From 60b5574643fcfbde3c4952310678a213d1f45d15 Mon Sep 17 00:00:00 2001 From: rlarlgnszx Date: Fri, 22 Nov 2024 15:37:54 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[feat]=20response=20dto=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20(#437)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/PlayGroundUserSoptLevelResponse.java | 8 +++ .../playground/dto/PlaygroundProfileInfo.java | 1 + .../app/presentation/user/UserResponse.java | 50 ++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/sopt/app/application/playground/dto/PlayGroundUserSoptLevelResponse.java diff --git a/src/main/java/org/sopt/app/application/playground/dto/PlayGroundUserSoptLevelResponse.java b/src/main/java/org/sopt/app/application/playground/dto/PlayGroundUserSoptLevelResponse.java new file mode 100644 index 00000000..961b3f1f --- /dev/null +++ b/src/main/java/org/sopt/app/application/playground/dto/PlayGroundUserSoptLevelResponse.java @@ -0,0 +1,8 @@ +package org.sopt.app.application.playground.dto; + +public record PlayGroundUserSoptLevelResponse( + Long id, + String profileImage, + int soptProjectCount +) { +} diff --git a/src/main/java/org/sopt/app/application/playground/dto/PlaygroundProfileInfo.java b/src/main/java/org/sopt/app/application/playground/dto/PlaygroundProfileInfo.java index bcb28b04..62d12cec 100755 --- a/src/main/java/org/sopt/app/application/playground/dto/PlaygroundProfileInfo.java +++ b/src/main/java/org/sopt/app/application/playground/dto/PlaygroundProfileInfo.java @@ -88,6 +88,7 @@ public static class PlaygroundProfile { private Long memberId; private String name; private String profileImage; + private String introduction; private List activities; public ActivityCardinalInfo getLatestActivity() { diff --git a/src/main/java/org/sopt/app/presentation/user/UserResponse.java b/src/main/java/org/sopt/app/presentation/user/UserResponse.java index 6692661e..8f763394 100755 --- a/src/main/java/org/sopt/app/presentation/user/UserResponse.java +++ b/src/main/java/org/sopt/app/presentation/user/UserResponse.java @@ -2,8 +2,14 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; -import lombok.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; import org.sopt.app.application.app_service.dto.AppServiceInfo; +import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile; +import org.sopt.app.domain.enums.PlaygroundPart; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class UserResponse { @@ -103,4 +109,46 @@ public static AppService of(final AppServiceInfo appServiceInfo) { .build(); } } + + @Getter + @Builder + public static class SoptLog { + @Schema(description = "유저 이름", example = "차은우") + private String userName; + @Schema(description = "프로필 이미지 url", example = "www.png") + private String profileImage; + @Schema(description = "파트") + private PlaygroundPart part; + @Schema(description = "콕찌르기 횟수") + private String pokeCount; + @Schema(description = "", example = "14등") + private String soptampRank; + @Schema(description = "솝력 ", example = "LV.7") + private String soptLevel; + @Schema(description = "유저 소개", example = "false") + private String profileMessage; + + public static SoptLog of(final String userName, final String profileImage, final PlaygroundPart part, final String pokeCount, final String soptampRank, final String soptLevel, final String profileMessage) { + return SoptLog.builder() + .userName(userName) + .profileImage(profileImage) + .part(part) + .pokeCount(pokeCount) + .soptampRank(soptampRank) + .soptLevel(soptLevel) + .profileMessage(profileMessage) + .build(); + } + public static SoptLog of(int soptLevel, Long pokeCount, Long soptampRank, PlaygroundProfile playgroundProfile) { + return SoptLog.builder() + .soptLevel("LV." + soptLevel) + .pokeCount(pokeCount.toString()) + .soptampRank(soptampRank.toString()) + .userName(playgroundProfile.getName()) + .profileImage(playgroundProfile.getProfileImage()) + .part(playgroundProfile.getLatestActivity().getPlaygroundPart()) + .profileMessage(playgroundProfile.getIntroduction()) + .build(); + } + } } From 0214a1577204411bdf2d00e9981edb8149bdd7c4 Mon Sep 17 00:00:00 2001 From: rlarlgnszx Date: Fri, 22 Nov 2024 15:38:25 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[feat]=20=ED=94=8C=EA=B7=B8=20API=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#437)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/application/playground/PlaygroundClient.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/sopt/app/application/playground/PlaygroundClient.java b/src/main/java/org/sopt/app/application/playground/PlaygroundClient.java index 4cfd98f5..1130ff7b 100755 --- a/src/main/java/org/sopt/app/application/playground/PlaygroundClient.java +++ b/src/main/java/org/sopt/app/application/playground/PlaygroundClient.java @@ -9,6 +9,7 @@ import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.RefreshedToken; import org.sopt.app.application.playground.dto.PlayGroundEmploymentResponse; import org.sopt.app.application.playground.dto.PlayGroundPostDetailResponse; +import org.sopt.app.application.playground.dto.PlayGroundUserSoptLevelResponse; import org.sopt.app.application.playground.dto.PlaygroundPostInfo.PlaygroundPostResponse; import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.ActiveUserIds; import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.OwnPlaygroundProfile; @@ -66,4 +67,10 @@ PlayGroundEmploymentResponse getPlaygroundEmploymentPost(@HeaderMap Map headers, @Param Long postId); + + @RequestLine("GET /internal/api/v1/members/{memberId}/project") + PlayGroundUserSoptLevelResponse getPlayGroundUserSoptLevel(@HeaderMap Map headers, @Param Long memberId); + + @RequestLine("GET /api/v1/members/profile/me") + PlaygroundProfile getPlayGroundProfile(@HeaderMap Map headers); } From a463d50b8cfa9f9ebec2d1615ab6c7b43af1a171 Mon Sep 17 00:00:00 2001 From: rlarlgnszx Date: Fri, 22 Nov 2024 15:39:29 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[feat]=20SoptLog=20API=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20(#437)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/application/poke/PokeService.java | 4 ++++ .../rank/SoptampUserRankCalculator.java | 13 ++++++++++ .../java/org/sopt/app/facade/AuthFacade.java | 19 ++++++++++++--- .../java/org/sopt/app/facade/PokeFacade.java | 4 ++++ .../java/org/sopt/app/facade/RankFacade.java | 7 ++++++ .../postgres/PokeHistoryRepository.java | 3 +++ .../app/presentation/user/UserController.java | 24 ++++++++++++++++++- 7 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sopt/app/application/poke/PokeService.java b/src/main/java/org/sopt/app/application/poke/PokeService.java index 6acdfd57..a0f6a70a 100755 --- a/src/main/java/org/sopt/app/application/poke/PokeService.java +++ b/src/main/java/org/sopt/app/application/poke/PokeService.java @@ -62,4 +62,8 @@ private PokeHistory createPokeByApplyingReply( .isAnonymous(isAnonymous) .build()); } + + public Long getUserPokeCount(Long userId) { + return historyRepository.countByPokerIdOrPokedId(userId, userId); + } } diff --git a/src/main/java/org/sopt/app/application/rank/SoptampUserRankCalculator.java b/src/main/java/org/sopt/app/application/rank/SoptampUserRankCalculator.java index 65548c0f..f7ef7d0d 100755 --- a/src/main/java/org/sopt/app/application/rank/SoptampUserRankCalculator.java +++ b/src/main/java/org/sopt/app/application/rank/SoptampUserRankCalculator.java @@ -1,5 +1,6 @@ package org.sopt.app.application.rank; +import java.util.AbstractMap; import java.util.Comparator; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -20,4 +21,16 @@ public List
calculateRank() { .map(user -> Main.of(rankPoint.getAndIncrement(), user)) .toList(); } + + public Long getUserRank(Long userId) { + AtomicInteger rankPoint = new AtomicInteger(1); + + return Long.valueOf(soptampUserInfos.stream() + .sorted(Comparator.comparing(SoptampUserInfo::getTotalPoints).reversed()) + .map(user -> new AbstractMap.SimpleEntry<>(rankPoint.getAndIncrement(), user)) + .filter(entry -> entry.getValue().getId().equals(userId)) + .map(AbstractMap.SimpleEntry::getKey) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("User not found"))); + } } diff --git a/src/main/java/org/sopt/app/facade/AuthFacade.java b/src/main/java/org/sopt/app/facade/AuthFacade.java index 610f9840..d825cfce 100755 --- a/src/main/java/org/sopt/app/facade/AuthFacade.java +++ b/src/main/java/org/sopt/app/facade/AuthFacade.java @@ -2,12 +2,17 @@ import lombok.RequiredArgsConstructor; import org.sopt.app.application.auth.JwtTokenService; -import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.*; +import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.AppToken; import org.sopt.app.application.playground.PlaygroundAuthService; -import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.*; +import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.LoginInfo; +import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundMain; +import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile; +import org.sopt.app.application.poke.PokeService; import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.application.user.UserService; -import org.sopt.app.presentation.auth.AppAuthRequest.*; +import org.sopt.app.domain.entity.User; +import org.sopt.app.presentation.auth.AppAuthRequest.AccessTokenRequest; +import org.sopt.app.presentation.auth.AppAuthRequest.CodeRequest; import org.sopt.app.presentation.auth.AppAuthResponse; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,6 +25,7 @@ public class AuthFacade { private final UserService userService; private final PlaygroundAuthService playgroundAuthService; private final SoptampUserService soptampUserService; + private final PokeService pokeService; @Transactional public AppAuthResponse loginWithPlayground(CodeRequest codeRequest) { @@ -66,4 +72,11 @@ public AppAuthResponse getRefreshToken(String refreshToken) { .build(); } + public int getUserSoptLevel(User user) { + return playgroundAuthService.getUserSoptLevel(user); + } + + public PlaygroundProfile getUserDetails(User user) { + return playgroundAuthService.getPlayGroundProfile(user.getPlaygroundToken()); + } } diff --git a/src/main/java/org/sopt/app/facade/PokeFacade.java b/src/main/java/org/sopt/app/facade/PokeFacade.java index bb88b48d..1e20795e 100755 --- a/src/main/java/org/sopt/app/facade/PokeFacade.java +++ b/src/main/java/org/sopt/app/facade/PokeFacade.java @@ -259,4 +259,8 @@ public RecommendedFriendsRequest getRecommendedFriendsByTypeList( public boolean getIsNewUser(Long userId) { return friendService.getIsNewUser(userId); } + + public Long getUserPokeCount(Long userId) { + return pokeService.getUserPokeCount(userId); + } } \ No newline at end of file diff --git a/src/main/java/org/sopt/app/facade/RankFacade.java b/src/main/java/org/sopt/app/facade/RankFacade.java index 9eede142..327c123b 100755 --- a/src/main/java/org/sopt/app/facade/RankFacade.java +++ b/src/main/java/org/sopt/app/facade/RankFacade.java @@ -47,4 +47,11 @@ public PartRank findPartRank(Part part) { .filter(partRank -> partRank.getPart().equals(part.getPartName())) .findFirst().orElseThrow(); } + + @Transactional(readOnly = true) + public Long findUserRank(Long userId) { + List soptampUserInfos = soptampUserFinder.findAllOfCurrentGeneration(); + SoptampUserRankCalculator soptampUserRankCalculator = new SoptampUserRankCalculator(soptampUserInfos); + return soptampUserRankCalculator.getUserRank(userId); + } } diff --git a/src/main/java/org/sopt/app/interfaces/postgres/PokeHistoryRepository.java b/src/main/java/org/sopt/app/interfaces/postgres/PokeHistoryRepository.java index 0b07450f..75aac879 100755 --- a/src/main/java/org/sopt/app/interfaces/postgres/PokeHistoryRepository.java +++ b/src/main/java/org/sopt/app/interfaces/postgres/PokeHistoryRepository.java @@ -1,5 +1,6 @@ package org.sopt.app.interfaces.postgres; +import jakarta.validation.constraints.NotNull; import java.util.List; import org.sopt.app.domain.entity.poke.PokeHistory; import org.springframework.data.domain.Page; @@ -36,4 +37,6 @@ List findAllWithFriendOrderByCreatedAtDescIsReplyFalse(@Param("user List findAllPokeHistoryByUsers(@Param("userId") Long userId, @Param("friendId") Long friendId); Long countByPokedIdAndIsReplyIsFalse(Long pokedId); + + Long countByPokerIdOrPokedId(@NotNull Long pokerId, @NotNull Long pokedId); } \ No newline at end of file diff --git a/src/main/java/org/sopt/app/presentation/user/UserController.java b/src/main/java/org/sopt/app/presentation/user/UserController.java index caf18076..101b41a3 100755 --- a/src/main/java/org/sopt/app/presentation/user/UserController.java +++ b/src/main/java/org/sopt/app/presentation/user/UserController.java @@ -7,19 +7,25 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import lombok.val; +import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile; import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.domain.entity.User; +import org.sopt.app.facade.AuthFacade; +import org.sopt.app.facade.PokeFacade; +import org.sopt.app.facade.RankFacade; import org.sopt.app.facade.SoptampFacade; +import org.sopt.app.presentation.user.UserResponse.SoptLog; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +@Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/api/v2/user") @@ -28,6 +34,9 @@ public class UserController { private final SoptampUserService soptampUserService; private final SoptampFacade soptampFacade; + private final AuthFacade authFacade; + private final PokeFacade pokeFacade; + private final RankFacade rankFacade; @Operation(summary = "솝탬프 정보 조회") @ApiResponses({ @@ -62,4 +71,17 @@ public ResponseEntity editProfileMessage( return ResponseEntity.ok(response); } + @Operation(summary = "유저 솝트로그 조회") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success"), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @GetMapping(value = "/sopt-log") + public ResponseEntity getUserSoptLog(@AuthenticationPrincipal User user) { + int soptLevel = authFacade.getUserSoptLevel(user); + Long pokeCount = pokeFacade.getUserPokeCount(user.getId()); + Long soptampRank = rankFacade.findUserRank(user.getId()); + PlaygroundProfile playgroundProfile = authFacade.getUserDetails(user); + return ResponseEntity.ok(SoptLog.of(soptLevel, pokeCount, soptampRank, playgroundProfile)); + } } From 4dc67dcf827229f0777f9fd45831b574d250616a Mon Sep 17 00:00:00 2001 From: rlarlgnszx Date: Fri, 22 Nov 2024 22:05:54 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[feat]=20soptLevel=EA=B3=BC=20=ED=94=8C?= =?UTF-8?q?=EA=B7=B8=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20(#437)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../playground/PlaygroundAuthService.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java index 0b5e8c3f..3e97c45a 100755 --- a/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java @@ -35,6 +35,7 @@ import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.common.exception.UnauthorizedException; import org.sopt.app.common.response.ErrorCode; +import org.sopt.app.domain.entity.User; import org.sopt.app.domain.enums.UserStatus; import org.sopt.app.presentation.auth.AppAuthRequest.AccessTokenRequest; import org.sopt.app.presentation.auth.AppAuthRequest.CodeRequest; @@ -239,4 +240,15 @@ private List getPostsWithMemberInfo(String pla } return mutablePosts; } + + public int getUserSoptLevel(User user) { + final Map accessToken = createAuthorizationHeaderByUserPlaygroundToken(user.getPlaygroundToken()); + return playgroundClient.getPlayGroundUserSoptLevel(accessToken,user.getPlaygroundId()).soptProjectCount(); + } + + public PlaygroundProfile getPlayGroundProfile(String accessToken) { + Map requestHeader = createAuthorizationHeaderByUserPlaygroundToken(accessToken); + return playgroundClient.getPlayGroundProfile(requestHeader); + + } } From 4650d69bb6ea852e6bf707d68584a19423d2b399 Mon Sep 17 00:00:00 2001 From: rlarlgnszx Date: Sun, 24 Nov 2024 14:27:28 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[fix]=20test=EC=88=98=EC=A0=95=20(#437)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/org/sopt/app/facade/PokeFacadeTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/sopt/app/facade/PokeFacadeTest.java b/src/test/java/org/sopt/app/facade/PokeFacadeTest.java index 0ee02244..7337e223 100755 --- a/src/test/java/org/sopt/app/facade/PokeFacadeTest.java +++ b/src/test/java/org/sopt/app/facade/PokeFacadeTest.java @@ -38,13 +38,14 @@ class PokeFacadeTest { private final UserProfile userProfile3 = UserProfile.builder().userId(3L).name("name3").playgroundId(3L).build(); private final List userProfileList = List.of(userProfile2, userProfile3); private final ActivityCardinalInfo activityCardinalInfo = new ActivityCardinalInfo("34,서버"); + private final String instruction = "test"; private final List playgroundProfileList = List.of( - new PlaygroundProfile(2L, "name2", "image", List.of(activityCardinalInfo)), - new PlaygroundProfile(3L, "name3", "image", List.of(activityCardinalInfo)) + new PlaygroundProfile(2L, "name2", "image", instruction,List.of(activityCardinalInfo)), + new PlaygroundProfile(3L, "name3", "image", instruction,List.of(activityCardinalInfo)) ); private final List playgroundProfileListWithoutImage = List.of( - new PlaygroundProfile(2L, "name2", "", List.of(activityCardinalInfo)), - new PlaygroundProfile(3L, "name3", "", List.of(activityCardinalInfo)) + new PlaygroundProfile(2L, "name2", "", instruction,List.of(activityCardinalInfo)), + new PlaygroundProfile(3L, "name3", "", instruction,List.of(activityCardinalInfo)) ); private final PokeHistory pokeHistory2 = PokeHistory.builder().id(2L).pokedId(1L).pokerId(2L).isReply(false) .isAnonymous(false).build(); From dfcdef3629a3356f1cd963a77df6784758c24e58 Mon Sep 17 00:00:00 2001 From: rlarlgnszx Date: Sat, 30 Nov 2024 17:43:20 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[fix]=20API=20=EB=B3=80=EA=B2=BD=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=88=98=EC=A0=95=20(#437)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/application/user/UserService.java | 23 ++++++++++ .../java/org/sopt/app/facade/AuthFacade.java | 10 +++++ .../app/presentation/user/UserController.java | 17 ++++++- .../app/presentation/user/UserResponse.java | 44 +++++++++---------- 4 files changed, 69 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/sopt/app/application/user/UserService.java b/src/main/java/org/sopt/app/application/user/UserService.java index 9acb92af..4b6b3293 100755 --- a/src/main/java/org/sopt/app/application/user/UserService.java +++ b/src/main/java/org/sopt/app/application/user/UserService.java @@ -1,5 +1,6 @@ package org.sopt.app.application.user; +import java.time.LocalDate; import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -8,7 +9,10 @@ import org.sopt.app.common.exception.NotFoundException; import org.sopt.app.common.exception.UnauthorizedException; import org.sopt.app.common.response.ErrorCode; +import org.sopt.app.domain.entity.Icons; import org.sopt.app.domain.entity.User; +import org.sopt.app.domain.enums.IconType; +import org.sopt.app.interfaces.postgres.IconRepository; import org.sopt.app.interfaces.postgres.UserRepository; import org.sopt.app.presentation.auth.AppAuthRequest.AccessTokenRequest; import org.springframework.stereotype.Service; @@ -21,6 +25,7 @@ public class UserService { private final UserRepository userRepository; + private final IconRepository iconRepository; @Transactional public Long upsertUser(LoginInfo loginInfo) { @@ -82,4 +87,22 @@ public List getAllPlaygroundIds() { public boolean isUserExist(Long userId) { return userRepository.existsById(userId); } + + public Long getDuration(Long myGeneration, Long currentGeneration) { + long monthsBetweenGenerations = (currentGeneration - myGeneration) * 6; + LocalDate now = LocalDate.now(); + int currentMonth = now.getMonthValue(); + int startMonth = (currentGeneration % 2 == 0) ? 3 : 9; + int monthsSinceStart = currentMonth - startMonth; + if (monthsSinceStart < 0) { + monthsSinceStart += 12; + } + return monthsBetweenGenerations + monthsSinceStart; + } + + public List getIcons(IconType iconType) { + return iconRepository.findAllByIconType(iconType).stream() + .map(Icons::getIconUrl) + .toList(); + } } diff --git a/src/main/java/org/sopt/app/facade/AuthFacade.java b/src/main/java/org/sopt/app/facade/AuthFacade.java index d825cfce..b6c47195 100755 --- a/src/main/java/org/sopt/app/facade/AuthFacade.java +++ b/src/main/java/org/sopt/app/facade/AuthFacade.java @@ -1,5 +1,6 @@ package org.sopt.app.facade; +import java.util.List; import lombok.RequiredArgsConstructor; import org.sopt.app.application.auth.JwtTokenService; import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.AppToken; @@ -11,6 +12,7 @@ import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.application.user.UserService; import org.sopt.app.domain.entity.User; +import org.sopt.app.domain.enums.IconType; import org.sopt.app.presentation.auth.AppAuthRequest.AccessTokenRequest; import org.sopt.app.presentation.auth.AppAuthRequest.CodeRequest; import org.sopt.app.presentation.auth.AppAuthResponse; @@ -79,4 +81,12 @@ public int getUserSoptLevel(User user) { public PlaygroundProfile getUserDetails(User user) { return playgroundAuthService.getPlayGroundProfile(user.getPlaygroundToken()); } + + public Long getDuration(Long Mygeneration, Long generation) { + return userService.getDuration(Mygeneration, generation); + } + + public List getIcons(IconType iconType) { + return userService.getIcons(iconType); + } } diff --git a/src/main/java/org/sopt/app/presentation/user/UserController.java b/src/main/java/org/sopt/app/presentation/user/UserController.java index 101b41a3..46a4dbad 100755 --- a/src/main/java/org/sopt/app/presentation/user/UserController.java +++ b/src/main/java/org/sopt/app/presentation/user/UserController.java @@ -6,17 +6,20 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import jakarta.validation.Valid; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile; import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.domain.entity.User; +import org.sopt.app.domain.enums.IconType; import org.sopt.app.facade.AuthFacade; import org.sopt.app.facade.PokeFacade; import org.sopt.app.facade.RankFacade; import org.sopt.app.facade.SoptampFacade; import org.sopt.app.presentation.user.UserResponse.SoptLog; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; @@ -37,6 +40,8 @@ public class UserController { private final AuthFacade authFacade; private final PokeFacade pokeFacade; private final RankFacade rankFacade; + @Value("${sopt.current.generation}") + private Long generation; @Operation(summary = "솝탬프 정보 조회") @ApiResponses({ @@ -80,8 +85,16 @@ public ResponseEntity editProfileMessage( public ResponseEntity getUserSoptLog(@AuthenticationPrincipal User user) { int soptLevel = authFacade.getUserSoptLevel(user); Long pokeCount = pokeFacade.getUserPokeCount(user.getId()); - Long soptampRank = rankFacade.findUserRank(user.getId()); PlaygroundProfile playgroundProfile = authFacade.getUserDetails(user); - return ResponseEntity.ok(SoptLog.of(soptLevel, pokeCount, soptampRank, playgroundProfile)); + Long soptampRank = null; + Long soptDuring = null; + Boolean isActive = playgroundProfile.getLatestActivity().getGeneration() == generation; + if (isActive) { + soptampRank = rankFacade.findUserRank(user.getId()); + } else { + soptDuring = authFacade.getDuration(playgroundProfile.getLatestActivity().getGeneration(), generation); + } + List icons = authFacade.getIcons(isActive ? IconType.ACTIVE : IconType.INACTIVE); + return ResponseEntity.ok(SoptLog.of(soptLevel, pokeCount, soptampRank, soptDuring,isActive,icons, playgroundProfile)); } } diff --git a/src/main/java/org/sopt/app/presentation/user/UserResponse.java b/src/main/java/org/sopt/app/presentation/user/UserResponse.java index 8f763394..b7ddb21c 100755 --- a/src/main/java/org/sopt/app/presentation/user/UserResponse.java +++ b/src/main/java/org/sopt/app/presentation/user/UserResponse.java @@ -127,28 +127,26 @@ public static class SoptLog { private String soptLevel; @Schema(description = "유저 소개", example = "false") private String profileMessage; - - public static SoptLog of(final String userName, final String profileImage, final PlaygroundPart part, final String pokeCount, final String soptampRank, final String soptLevel, final String profileMessage) { - return SoptLog.builder() - .userName(userName) - .profileImage(profileImage) - .part(part) - .pokeCount(pokeCount) - .soptampRank(soptampRank) - .soptLevel(soptLevel) - .profileMessage(profileMessage) - .build(); - } - public static SoptLog of(int soptLevel, Long pokeCount, Long soptampRank, PlaygroundProfile playgroundProfile) { - return SoptLog.builder() - .soptLevel("LV." + soptLevel) - .pokeCount(pokeCount.toString()) - .soptampRank(soptampRank.toString()) - .userName(playgroundProfile.getName()) - .profileImage(playgroundProfile.getProfileImage()) - .part(playgroundProfile.getLatestActivity().getPlaygroundPart()) - .profileMessage(playgroundProfile.getIntroduction()) - .build(); - } + @Schema(description = "솝트와", example = "37개월") + private String during; + private List icons; + private Boolean isActive; + + public static SoptLog of(int soptLevel, Long pokeCount, Long soptampRank, Long during, Boolean isActive, + List icons, + PlaygroundProfile playgroundProfile) { + return SoptLog.builder() + .soptLevel("Lv." + soptLevel) + .pokeCount(pokeCount + "회") + .soptampRank(soptampRank != null ? soptampRank +"등" : null) + .userName(playgroundProfile.getName()) + .profileImage(playgroundProfile.getProfileImage()) + .part(playgroundProfile.getLatestActivity().getPlaygroundPart()) + .profileMessage(playgroundProfile.getIntroduction()) + .during(during != null ? during + "개월": null) + .isActive(isActive) + .icons(icons) + .build(); + } } } From 9b607fc814c796f9033970a3eb036fe2a913f6c4 Mon Sep 17 00:00:00 2001 From: rlarlgnszx Date: Sat, 30 Nov 2024 17:43:43 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[fix]=20ICON=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A0=84=EC=86=A1=20(#437)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/app/domain/entity/Icons.java | 27 +++++++++++++++++++ .../org/sopt/app/domain/enums/IconType.java | 5 ++++ .../interfaces/postgres/IconRepository.java | 10 +++++++ 3 files changed, 42 insertions(+) create mode 100644 src/main/java/org/sopt/app/domain/entity/Icons.java create mode 100644 src/main/java/org/sopt/app/domain/enums/IconType.java create mode 100644 src/main/java/org/sopt/app/interfaces/postgres/IconRepository.java diff --git a/src/main/java/org/sopt/app/domain/entity/Icons.java b/src/main/java/org/sopt/app/domain/entity/Icons.java new file mode 100644 index 00000000..9594ec0f --- /dev/null +++ b/src/main/java/org/sopt/app/domain/entity/Icons.java @@ -0,0 +1,27 @@ +package org.sopt.app.domain.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.sopt.app.domain.enums.IconType; + +@Entity +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class Icons { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String iconUrl; + + @Enumerated(EnumType.STRING) + private IconType iconType; +} diff --git a/src/main/java/org/sopt/app/domain/enums/IconType.java b/src/main/java/org/sopt/app/domain/enums/IconType.java new file mode 100644 index 00000000..c659ab94 --- /dev/null +++ b/src/main/java/org/sopt/app/domain/enums/IconType.java @@ -0,0 +1,5 @@ +package org.sopt.app.domain.enums; + +public enum IconType { + ACTIVE, INACTIVE +} diff --git a/src/main/java/org/sopt/app/interfaces/postgres/IconRepository.java b/src/main/java/org/sopt/app/interfaces/postgres/IconRepository.java new file mode 100644 index 00000000..951865a2 --- /dev/null +++ b/src/main/java/org/sopt/app/interfaces/postgres/IconRepository.java @@ -0,0 +1,10 @@ +package org.sopt.app.interfaces.postgres; + +import java.util.List; +import org.sopt.app.domain.entity.Icons; +import org.sopt.app.domain.enums.IconType; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface IconRepository extends JpaRepository { + List findAllByIconType(IconType iconType); +}