diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 0909e1ce..30ecfb25 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,10 +1,4 @@ ## ๐Ÿš€ Issue Summary - #### ๐Ÿš— Implement TODO - [ ] -- [ ] - - -#### ๐Ÿš“ Remarks - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6e784b05..60acad73 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,13 +1,10 @@ ## ๐Ÿ“ PR Summary - -#### ๐ŸŒต Working Branch - - #### ๐ŸŒด Works -- [ ] -- [ ] - +- [x] #### ๐ŸŒฑ Related Issue +closed # +#### ๐ŸŒต PR ์ฐธ๊ณ ์‚ฌํ•ญ +- diff --git a/src/main/java/org/sopt/app/application/service/AppServiceInfo.java b/src/main/java/org/sopt/app/application/app_service/AppServiceInfo.java similarity index 86% rename from src/main/java/org/sopt/app/application/service/AppServiceInfo.java rename to src/main/java/org/sopt/app/application/app_service/AppServiceInfo.java index f1136958..33e0ee4d 100644 --- a/src/main/java/org/sopt/app/application/service/AppServiceInfo.java +++ b/src/main/java/org/sopt/app/application/app_service/AppServiceInfo.java @@ -1,4 +1,4 @@ -package org.sopt.app.application.service; +package org.sopt.app.application.app_service; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/org/sopt/app/application/service/AppServiceService.java b/src/main/java/org/sopt/app/application/app_service/AppServiceService.java similarity index 95% rename from src/main/java/org/sopt/app/application/service/AppServiceService.java rename to src/main/java/org/sopt/app/application/app_service/AppServiceService.java index 0a38c261..3d242a9c 100644 --- a/src/main/java/org/sopt/app/application/service/AppServiceService.java +++ b/src/main/java/org/sopt/app/application/app_service/AppServiceService.java @@ -1,4 +1,4 @@ -package org.sopt.app.application.service; +package org.sopt.app.application.app_service; import java.util.Comparator; import java.util.List; diff --git a/src/main/java/org/sopt/app/application/auth/CustomUserDetailService.java b/src/main/java/org/sopt/app/application/auth/CustomUserDetailService.java index 18f1a698..ba40f021 100644 --- a/src/main/java/org/sopt/app/application/auth/CustomUserDetailService.java +++ b/src/main/java/org/sopt/app/application/auth/CustomUserDetailService.java @@ -15,7 +15,7 @@ public class CustomUserDetailService implements UserDetailsService { private final UserRepository userRepository; public UserDetails loadUserByUsername(String username) throws NotFoundException { - return (UserDetails) userRepository.findUserById(Long.parseLong(username)) + return userRepository.findUserById(Long.parseLong(username)) .orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND.getMessage())); } } diff --git a/src/main/java/org/sopt/app/application/auth/JwtTokenService.java b/src/main/java/org/sopt/app/application/auth/JwtTokenService.java index ee64ce3d..eb872650 100644 --- a/src/main/java/org/sopt/app/application/auth/JwtTokenService.java +++ b/src/main/java/org/sopt/app/application/auth/JwtTokenService.java @@ -3,7 +3,6 @@ import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.Header; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.MalformedJwtException; import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.io.Decoders; import io.jsonwebtoken.security.Keys; @@ -15,7 +14,8 @@ import lombok.RequiredArgsConstructor; import lombok.val; import org.joda.time.LocalDateTime; -import org.sopt.app.application.auth.PlaygroundAuthInfo.AppToken; +import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.AppToken; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo; import org.sopt.app.application.user.UserInfo; import org.sopt.app.common.exception.UnauthorizedException; import org.springframework.beans.factory.annotation.Value; @@ -40,8 +40,8 @@ private Key getSigningKey(String keyString) { return Keys.hmacShaKeyFor(Decoders.BASE64.decode(secretKey)); } - public PlaygroundAuthInfo.AppToken issueNewTokens(UserInfo.Id userId, - PlaygroundAuthInfo.PlaygroundMain playgroundMember) { + public AppToken issueNewTokens(UserInfo.Id userId, + PlaygroundProfileInfo.PlaygroundMain playgroundMember) { val accessToken = this.encodeJwtToken(userId, playgroundMember.getId()); val refreshToken = this.encodeJwtRefreshToken(userId); return AppToken.builder().accessToken(accessToken).refreshToken(refreshToken).build(); diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java index 117ca361..ae3f00b1 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java @@ -11,10 +11,15 @@ import java.util.stream.IntStream; import lombok.RequiredArgsConstructor; import lombok.val; -import org.sopt.app.application.auth.PlaygroundAuthInfo.OwnPlaygroundProfile; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfile; -import org.sopt.app.application.auth.PlaygroundAuthInfo.RecommendFriendFilter; -import org.sopt.app.application.auth.PlaygroundAuthInfo.RecommendFriendRequest; +import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.RefreshedToken; +import org.sopt.app.application.auth.dto.PlaygroundPostInfo.PlaygroundPost; +import org.sopt.app.application.auth.dto.PlaygroundPostInfo.PlaygroundPostResponse; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.MainView; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.OwnPlaygroundProfile; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundProfile; +import org.sopt.app.application.auth.dto.RecommendFriendRequest; +import org.sopt.app.application.auth.dto.RecommendedFriendInfo.RecommendFriendFilter; import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.common.exception.UnauthorizedException; import org.sopt.app.common.response.ErrorCode; @@ -40,8 +45,11 @@ public class PlaygroundAuthService { private String requestFrom; @Value("${makers.playground.access-token}") private String playgroundToken; + @Value("${makers.playground.web-page}") + private String playgroundWebPageUrl; - public PlaygroundAuthInfo.PlaygroundMain getPlaygroundInfo(String token) { + + public PlaygroundProfileInfo.PlaygroundMain getPlaygroundInfo(String token) { val member = this.getPlaygroundMember(token); val playgroundProfile = this.getPlaygroundMemberProfile(token, member.getId()); val generationList = this.getMemberGenerationList(playgroundProfile); @@ -59,7 +67,7 @@ public AppAuthRequest.AccessTokenRequest getPlaygroundAccessToken(AppAuthRequest } } - private PlaygroundAuthInfo.PlaygroundMain getPlaygroundMember(String accessToken) { + private PlaygroundProfileInfo.PlaygroundMain getPlaygroundMember(String accessToken) { Map headers = createAuthorizationHeader(accessToken); try { return playgroundClient.getPlaygroundMember(headers); @@ -70,7 +78,7 @@ private PlaygroundAuthInfo.PlaygroundMain getPlaygroundMember(String accessToken } } - public PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(AppAuthRequest.AccessTokenRequest tokenRequest) { + public RefreshedToken refreshPlaygroundToken(AppAuthRequest.AccessTokenRequest tokenRequest) { Map headers = createDefaultHeader(); headers.put("x-api-key", apiKey); headers.put("x-request-from", requestFrom); @@ -81,24 +89,24 @@ public PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(AppAuthRequest.A } } - public PlaygroundAuthInfo.MainView getPlaygroundUserForMainView(String accessToken, Long playgroundId) { + public PlaygroundProfileInfo.MainView getPlaygroundUserForMainView(String accessToken, Long playgroundId) { val playgroundProfile = this.getPlaygroundMemberProfile(accessToken, playgroundId); val profileImage = playgroundProfile.getProfileImage() == null ? "" : playgroundProfile.getProfileImage(); val generationList = this.getMemberGenerationList(playgroundProfile); - val mainViewUser = PlaygroundAuthInfo.MainViewUser.builder() + val mainViewUser = PlaygroundProfileInfo.MainViewUser.builder() .status(this.getStatus(generationList)) .name(playgroundProfile.getName()) .profileImage(profileImage) .generationList(generationList) .build(); - return PlaygroundAuthInfo.MainView.builder().user(mainViewUser).build(); + return new MainView(mainViewUser); } private UserStatus getStatus(List generationList) { return generationList.contains(currentGeneration) ? UserStatus.ACTIVE : UserStatus.INACTIVE; } - private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String accessToken, Long playgroundId) { + private PlaygroundProfileInfo.PlaygroundProfile getPlaygroundMemberProfile(String accessToken, Long playgroundId) { Map headers = createAuthorizationHeader(accessToken); try { return playgroundClient.getSinglePlaygroundMemberProfile(headers, playgroundId).get(0); @@ -109,17 +117,14 @@ private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String a } } - public PlaygroundAuthInfo.UserActiveInfo getPlaygroundUserActiveInfo(String accessToken, Long playgroundId) { + public PlaygroundProfileInfo.UserActiveInfo getPlaygroundUserActiveInfo(String accessToken, Long playgroundId) { val playgroundProfile = this.getPlaygroundMemberProfile(accessToken, playgroundId); val generationList = this.getMemberGenerationList(playgroundProfile); val userStatus = this.getStatus(generationList); - return PlaygroundAuthInfo.UserActiveInfo.builder() - .status(userStatus) - .currentGeneration(currentGeneration) - .build(); + return new PlaygroundProfileInfo.UserActiveInfo(currentGeneration, userStatus); } - private List getMemberGenerationList(PlaygroundAuthInfo.PlaygroundProfile playgroundProfile) { + private List getMemberGenerationList(PlaygroundProfileInfo.PlaygroundProfile playgroundProfile) { return playgroundProfile.getActivities().stream() .map(activity -> { @@ -144,7 +149,7 @@ private Map createAuthorizationHeader(String accessToken) { return headers; } - public PlaygroundAuthInfo.ActiveUserIds getPlayGroundUserIds(String accessToken) { + public PlaygroundProfileInfo.ActiveUserIds getPlayGroundUserIds(String accessToken) { Map requestHeader = createAuthorizationHeader(accessToken); try { return playgroundClient.getPlaygroundUserIds(requestHeader, currentGeneration); @@ -181,7 +186,7 @@ public List getPlaygroundIdsForSameGeneration(List generationList return playgroundClient.getPlaygroundUserIdsForSameRecommendType( createAuthorizationHeader(playgroundToken), RecommendFriendRequest.createRecommendFriendRequestByGeneration(generationList) - ).getUserIds(); + ).userIds(); } private List getGenerationListByLatestGenerationForRange(Integer latestGeneration) { @@ -191,24 +196,38 @@ private List getGenerationListByLatestGenerationForRange(Integer latest } public List getPlaygroundIdsForSameMbti(Integer latestGeneration, String mbti) { - RecommendFriendRequest request = RecommendFriendRequest.builder() - .generations(getGenerationListByLatestGenerationForRange(latestGeneration)) - .filters(List.of(RecommendFriendFilter.builder().key(String.valueOf(MBTI)).value(mbti).build())) - .build(); + List targetGenerations = getGenerationListByLatestGenerationForRange(latestGeneration); + List filters = + List.of(RecommendFriendFilter.builder().key(String.valueOf(MBTI)).value(mbti).build()); + return playgroundClient.getPlaygroundUserIdsForSameRecommendType( createAuthorizationHeader(playgroundToken), - request - ).getUserIds(); + new RecommendFriendRequest(targetGenerations, filters) + ).userIds(); } public List getPlaygroundIdsForSameUniversity(Integer latestGeneration, String university) { - RecommendFriendRequest request = RecommendFriendRequest.builder() - .generations(getGenerationListByLatestGenerationForRange(latestGeneration)) - .filters(List.of(RecommendFriendFilter.builder().key(String.valueOf(UNIVERSITY)).value(university).build())) - .build(); + List targetGenerations = getGenerationListByLatestGenerationForRange(latestGeneration); + List filters = + List.of(RecommendFriendFilter.builder().key(String.valueOf(UNIVERSITY)).value(university).build()); + return playgroundClient.getPlaygroundUserIdsForSameRecommendType( createAuthorizationHeader(playgroundToken), - request - ).getUserIds(); + new RecommendFriendRequest(targetGenerations, filters) + ).userIds(); + } + + public PlaygroundPost getPlaygroundHotPost(String playgroundToken) { + PlaygroundPostResponse postInfo = playgroundClient.getPlaygroundHotPost(createAuthorizationHeader(playgroundToken)); + + return PlaygroundPost.builder() + .title(postInfo.title()) + .content(postInfo.content()) + .url(convertPlaygroundWebPageUrl(postInfo.postId())) + .build(); + } + + private String convertPlaygroundWebPageUrl(Long postId) { + return playgroundWebPageUrl + "/?feed=" + postId; } } diff --git a/src/main/java/org/sopt/app/application/auth/dto/PlaygroundAuthTokenInfo.java b/src/main/java/org/sopt/app/application/auth/dto/PlaygroundAuthTokenInfo.java new file mode 100644 index 00000000..bae87d11 --- /dev/null +++ b/src/main/java/org/sopt/app/application/auth/dto/PlaygroundAuthTokenInfo.java @@ -0,0 +1,30 @@ +package org.sopt.app.application.auth.dto; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlaygroundAuthTokenInfo { + + @Getter + @Builder + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class AppToken { + + private String accessToken; + private String refreshToken; + } + + @Getter + @Builder + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class RefreshedToken { + + private String accessToken; + private String errorCode; + } +} diff --git a/src/main/java/org/sopt/app/application/auth/dto/PlaygroundPostInfo.java b/src/main/java/org/sopt/app/application/auth/dto/PlaygroundPostInfo.java new file mode 100644 index 00000000..fc2ab0b1 --- /dev/null +++ b/src/main/java/org/sopt/app/application/auth/dto/PlaygroundPostInfo.java @@ -0,0 +1,30 @@ +package org.sopt.app.application.auth.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class PlaygroundPostInfo { + + @Getter + @Builder + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class PlaygroundPost { + + private String title; + private String content; + private String url; + } + + public record PlaygroundPostResponse( + @JsonProperty(value = "id") + Long postId, + String title, + String content + ) { + } +} diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java b/src/main/java/org/sopt/app/application/auth/dto/PlaygroundProfileInfo.java similarity index 60% rename from src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java rename to src/main/java/org/sopt/app/application/auth/dto/PlaygroundProfileInfo.java index 10d9357d..63f5dc33 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java +++ b/src/main/java/org/sopt/app/application/auth/dto/PlaygroundProfileInfo.java @@ -1,4 +1,4 @@ -package org.sopt.app.application.auth; +package org.sopt.app.application.auth.dto; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Comparator; @@ -14,42 +14,18 @@ import org.sopt.app.domain.enums.UserStatus; @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PlaygroundAuthInfo { +public class PlaygroundProfileInfo { - @Getter - @Builder - public static class AppToken { - - private String accessToken; - private String refreshToken; - } - - @Getter - @Builder - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @AllArgsConstructor(access = AccessLevel.PRIVATE) - public static class RefreshedToken { - - private String accessToken; - private String errorCode; - } - - @Getter - @Builder - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @AllArgsConstructor(access = AccessLevel.PRIVATE) - public static class ActiveUserIds { - - @JsonProperty("memberIds") - private List userIds; + public record ActiveUserIds( + @JsonProperty("memberIds") + List userIds + ) { } - @Getter - @Builder - public static class UserActiveInfo { - - private Long currentGeneration; - private UserStatus status; + public record UserActiveInfo( + Long currentGeneration, + UserStatus status + ) { } @Getter @@ -69,12 +45,9 @@ public static class PlaygroundMain { private UserStatus status; } - @Getter - @Builder - @ToString - public static class MainView { - - private MainViewUser user; + public record MainView( + MainViewUser user + ) { } @Getter @@ -162,13 +135,6 @@ public static class PlaygroundProfileOfRecommendedFriend { private String profileImage; private String name; private List activities; - - public PlaygroundProfileOfRecommendedFriend getProfileOfSameGeneration(Integer generation) { - this.activities = activities.stream() - .filter(activity -> activity.getGeneration().equals(generation)) - .toList(); - return this; - } } @Getter @@ -180,39 +146,4 @@ public static class PlaygroundActivity { private Integer generation; } - @Builder - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @AllArgsConstructor(access = AccessLevel.PRIVATE) - public static class RecommendFriendRequest { - - private List generations; - private List filters; - - public static RecommendFriendRequest createRecommendFriendRequestByGeneration(List generations) { - return RecommendFriendRequest.builder() - .generations(generations) - .filters(List.of()) - .build(); - } - } - - @Getter - @Builder - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @AllArgsConstructor(access = AccessLevel.PRIVATE) - public static class RecommendFriendFilter { - - private String key; - private String value; - } - - @Getter - @Builder - @NoArgsConstructor(access = AccessLevel.PRIVATE) - @AllArgsConstructor(access = AccessLevel.PRIVATE) - public static class PlaygroundUserIds { - private List userIds; - } - } diff --git a/src/main/java/org/sopt/app/application/auth/dto/RecommendFriendRequest.java b/src/main/java/org/sopt/app/application/auth/dto/RecommendFriendRequest.java new file mode 100644 index 00000000..80ad6816 --- /dev/null +++ b/src/main/java/org/sopt/app/application/auth/dto/RecommendFriendRequest.java @@ -0,0 +1,14 @@ +package org.sopt.app.application.auth.dto; + +import java.util.List; +import org.sopt.app.application.auth.dto.RecommendedFriendInfo.RecommendFriendFilter; + +public record RecommendFriendRequest( + List generations, + List filters +) { + + public static RecommendFriendRequest createRecommendFriendRequestByGeneration(List generations) { + return new RecommendFriendRequest(generations, List.of()); + } +} diff --git a/src/main/java/org/sopt/app/application/auth/dto/RecommendedFriendInfo.java b/src/main/java/org/sopt/app/application/auth/dto/RecommendedFriendInfo.java new file mode 100644 index 00000000..cb4ec3ee --- /dev/null +++ b/src/main/java/org/sopt/app/application/auth/dto/RecommendedFriendInfo.java @@ -0,0 +1,22 @@ +package org.sopt.app.application.auth.dto; + +import java.util.List; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class RecommendedFriendInfo { + + @Builder + public record RecommendFriendFilter( + String key, + String value + ) { + } + + public record PlaygroundUserIds( + List userIds + ) { + } +} diff --git a/src/main/java/org/sopt/app/application/notification/PushTokenService.java b/src/main/java/org/sopt/app/application/notification/PushTokenService.java index bcd8e02f..8962c954 100644 --- a/src/main/java/org/sopt/app/application/notification/PushTokenService.java +++ b/src/main/java/org/sopt/app/application/notification/PushTokenService.java @@ -127,7 +127,7 @@ private HttpHeaders createHeadersFor(String action, String platform) { } private PushTokenRequest.PushTokenManageRequest createBodyFor(PushToken pushToken) { - return PushTokenRequest.PushTokenManageRequest.of( + return new PushTokenRequest.PushTokenManageRequest( List.of(String.valueOf(pushToken.getPlaygroundId())), pushToken.getToken() ); diff --git a/src/main/java/org/sopt/app/application/poke/FriendService.java b/src/main/java/org/sopt/app/application/poke/FriendService.java index 2f31a671..939a0378 100644 --- a/src/main/java/org/sopt/app/application/poke/FriendService.java +++ b/src/main/java/org/sopt/app/application/poke/FriendService.java @@ -16,7 +16,7 @@ import org.sopt.app.common.utils.AnonymousNameGenerator; import org.sopt.app.domain.entity.Friend; import org.sopt.app.domain.enums.Friendship; -import org.sopt.app.interfaces.postgres.FriendRepository; +import org.sopt.app.interfaces.postgres.friend.FriendRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -25,6 +25,7 @@ @RequiredArgsConstructor public class FriendService { + private final Random random = new Random(); private final FriendRepository friendRepository; public List findAllFriendIdsByUserIdRandomly(Long userId, int limitNum) { @@ -164,8 +165,6 @@ public Long getPokeFriendIdRandomly(Long userId) { throw new NotFoundException(ErrorCode.FRIENDSHIP_NOT_FOUND.getMessage()); } - Random random = new Random(); - return friends.get(random.nextInt(friends.size())).getFriendUserId(); } diff --git a/src/main/java/org/sopt/app/application/rank/SoptampPartRankCalculator.java b/src/main/java/org/sopt/app/application/rank/SoptampPartRankCalculator.java new file mode 100644 index 00000000..9eead552 --- /dev/null +++ b/src/main/java/org/sopt/app/application/rank/SoptampPartRankCalculator.java @@ -0,0 +1,38 @@ +package org.sopt.app.application.rank; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.sopt.app.application.soptamp.SoptampPointInfo.PartPoint; +import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; + + +@RequiredArgsConstructor +public class SoptampPartRankCalculator { + + private final List partPoints; + + public List findAllPartRanks() { + + return partPoints.stream().map(this::createPartRank).toList(); + } + + private PartRank createPartRank(PartPoint targetPartPoint) { + + return PartRank.builder() + .part(targetPartPoint.part().getPartName()) + .rank(getTargetPartRank(targetPartPoint)) + .points(targetPartPoint.points()) + .build(); + } + + private int getTargetPartRank(PartPoint targetPartPoint) { + int rankPoint = 1; + + for (PartPoint comparisonPartPoint : partPoints) { + if (targetPartPoint.points() < comparisonPartPoint.points()) { + rankPoint++; + } + } + return rankPoint; + } +} diff --git a/src/main/java/org/sopt/app/application/rank/SoptampUserRankCalculator.java b/src/main/java/org/sopt/app/application/rank/SoptampUserRankCalculator.java new file mode 100644 index 00000000..a7d6c37c --- /dev/null +++ b/src/main/java/org/sopt/app/application/rank/SoptampUserRankCalculator.java @@ -0,0 +1,64 @@ +package org.sopt.app.application.rank; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.sopt.app.application.slack.SlackService; +import org.sopt.app.application.soptamp.SoptampPointInfo.Main; +import org.sopt.app.application.soptamp.SoptampPointInfo.Point; +import org.sopt.app.application.soptamp.SoptampUserInfo; + +@RequiredArgsConstructor +public class SoptampUserRankCalculator { + + private final List soptampUsers; + private final List
ranking = new ArrayList<>(); + private int rankPoint = 1; + + public List
calculateRanking(List soptampPointList) { + soptampPointList.stream() + .sorted(Comparator.comparing(Point::getPoints).reversed()) + .forEach(point -> + findSoptampUserInfo(point.getSoptampUserId()) + .ifPresentOrElse( + user -> addUserToRanking(user, point.getPoints()), + () -> SlackService.sendSlackMessage( + "Warning", + "soptamp_point์— ํ•ด๋‹นํ•˜์ง€ ์•Š๋Š” soptamp_user๊ฐ€ ํ™•์ธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.\n" + + "soptampPointId: " + point.getId() + "\n" + + "soptampUserId: " + point.getSoptampUserId() + ) + )); + return ranking; + } + + private void addUserToRanking(SoptampUserInfo user, Long userPoint) { + ranking.add(Main.builder() + .rank(getCurrentRankPointAndIncrement()) + .nickname(user.getNickname()) + .profileMessage(user.getProfileMessage()) + .point(userPoint) + .build()); + } + + private Optional findSoptampUserInfo(Long soptampUserId) { + return soptampUsers.stream() + .filter(user -> user.getId().equals(soptampUserId)) + .findAny(); + } + + private int getCurrentRankPointAndIncrement() { + return rankPoint++; + } + + @Deprecated + public List
calculateRank() { + return soptampUsers.stream().sorted( + Comparator.comparing(SoptampUserInfo::getTotalPoints).reversed()) + .map(user -> Main.of(getCurrentRankPointAndIncrement(), user)) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/org/sopt/app/application/slack/SlackService.java b/src/main/java/org/sopt/app/application/slack/SlackService.java index 57dcb18b..fcbcb92e 100644 --- a/src/main/java/org/sopt/app/application/slack/SlackService.java +++ b/src/main/java/org/sopt/app/application/slack/SlackService.java @@ -4,20 +4,23 @@ import com.slack.api.model.Attachment; import com.slack.api.webhook.Payload; import java.util.List; -import lombok.RequiredArgsConstructor; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service -@RequiredArgsConstructor +@Slf4j +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class SlackService { @Value("${webhook.slack.url}") - private String SLACK_WEBHOOK_URL; + private static String SLACK_WEBHOOK_URL; - private final Slack slackClient = Slack.getInstance(); + private static final Slack slackClient = Slack.getInstance(); - public void sendSlackMessage(String title, String message) { + public static void sendSlackMessage(String title, String message) { try{ slackClient.send(SLACK_WEBHOOK_URL, Payload.builder() .text(title) @@ -29,7 +32,7 @@ public void sendSlackMessage(String title, String message) { )) .build()); } catch (Exception e) { - e.printStackTrace(); + log.warn(e.getMessage()); } } } diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampPointInfo.java b/src/main/java/org/sopt/app/application/soptamp/SoptampPointInfo.java index 70990cd6..666422d5 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampPointInfo.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampPointInfo.java @@ -1,27 +1,39 @@ package org.sopt.app.application.soptamp; import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; import org.sopt.app.domain.entity.Mission; +import org.sopt.app.domain.entity.SoptampPoint; +import org.sopt.app.domain.enums.Part; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class SoptampPointInfo { @Getter @Builder - @ToString + @AllArgsConstructor(access = AccessLevel.PRIVATE) public static class Main { private Integer rank; private String nickname; private Long point; private String profileMessage; + + public static Main of(Integer rank, SoptampUserInfo soptampUserInfo) { + return new Main( + rank, + soptampUserInfo.getNickname(), + soptampUserInfo.getTotalPoints(), + soptampUserInfo.getProfileMessage() + ); + } } @Getter - @Builder - @ToString public static class Detail { private String nickname; @@ -31,23 +43,33 @@ public static class Detail { @Getter @Builder - @ToString + @AllArgsConstructor(access = AccessLevel.PRIVATE) public static class Point { private Long id; private Long generation; private Long soptampUserId; private Long points; - public static Point of(Long id, Long generation, Long soptampUserId, Long points) { - return new Point(id, generation, soptampUserId, points); + public static Point of(SoptampPoint soptampPoint) { + return new Point( + soptampPoint.getId(), + soptampPoint.getGeneration(), + soptampPoint.getSoptampUserId(), + soptampPoint.getPoints() + ); } } @Getter @Builder + @AllArgsConstructor(access = AccessLevel.PRIVATE) public static class PartRank { private String part; private Integer rank; private Long points; } + + public record PartPoint(Part part, Long points) { + + } } diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java b/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java index 96e0d135..1cec7703 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java @@ -1,18 +1,16 @@ package org.sopt.app.application.soptamp; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; +import java.util.Objects; import lombok.RequiredArgsConstructor; import lombok.val; -import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; +import org.sopt.app.application.soptamp.SoptampPointInfo.PartPoint; import org.sopt.app.application.soptamp.SoptampPointInfo.Point; import org.sopt.app.domain.entity.SoptampPoint; import org.sopt.app.domain.entity.SoptampUser; import org.sopt.app.domain.enums.Part; import org.sopt.app.domain.enums.UserStatus; -import org.sopt.app.interfaces.postgres.SoptampPointRepository; +import org.sopt.app.interfaces.postgres.soptamp_point.SoptampPointRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,61 +24,29 @@ public class SoptampPointService { @Value("${sopt.current.generation}") private Long currentGeneration; - public List findCurrentPointList() { + public List findCurrentGenerationPoints() { return soptampPointRepository.findAllByGeneration(currentGeneration).stream() - .map(point -> - SoptampPointInfo.Point.of( - point.getId(), - point.getGeneration(), - point.getSoptampUserId(), - point.getPoints() - ) - ).toList(); + .map(Point::of) + .toList(); } public List findCurrentPointListBySoptampUserIds(List soptampUserIdList) { - return soptampPointRepository.findAllBySoptampUserIdInAndGeneration(soptampUserIdList, currentGeneration) .stream() - .map(point -> - SoptampPointInfo.Point.of( - point.getId(), - point.getGeneration(), - point.getSoptampUserId(), - point.getPoints() - ) - ).toList(); + .map(Point::of) + .toList(); } @Transactional public void addPoint(Long soptampUserId, Integer level) { val soptampPoint = soptampPointRepository.findBySoptampUserIdAndGeneration(soptampUserId, currentGeneration); - if (soptampPoint.isPresent()) { - val soptampPointEntity = soptampPoint.get(); - val newSoptampPoint = SoptampPoint.builder() - .id(soptampPointEntity.getId()) - .generation(soptampPointEntity.getGeneration()) - .soptampUserId(soptampPointEntity.getSoptampUserId()) - .points(soptampPointEntity.getPoints() + level) - .build(); - soptampPointRepository.save(newSoptampPoint); - } + soptampPoint.ifPresent(point -> point.addPointsByLevelValue(level)); } @Transactional public void subtractPoint(Long soptampUserId, Integer level) { val soptampPoint = soptampPointRepository.findBySoptampUserIdAndGeneration(soptampUserId, currentGeneration); - if (soptampPoint.isEmpty()) { - return; - } - val soptampPointEntity = soptampPoint.get(); - val newSoptampPoint = SoptampPoint.builder() - .id(soptampPointEntity.getId()) - .generation(soptampPointEntity.getGeneration()) - .soptampUserId(soptampPointEntity.getSoptampUserId()) - .points(soptampPointEntity.getPoints() - level) - .build(); - soptampPointRepository.save(newSoptampPoint); + soptampPoint.ifPresent(point -> point.subtractPointsByLevelValue(level)); } @Transactional @@ -89,63 +55,16 @@ public void upsertSoptampPoint(UserStatus status, Long soptampUserId) { return; } val soptampPoint = soptampPointRepository.findBySoptampUserIdAndGeneration(soptampUserId, currentGeneration); - if (soptampPoint.isPresent()) { - return; + + if (soptampPoint.isEmpty()) { + soptampPointRepository.save(SoptampPoint.createNewSoptampPoint(currentGeneration, soptampUserId)); } - val newSoptampPoint = SoptampPoint.builder() - .generation(currentGeneration) - .soptampUserId(soptampUserId) - .points(0L) - .build(); - soptampPointRepository.save(newSoptampPoint); } @Transactional public void initPoint(Long soptampUserId) { val soptampPoint = soptampPointRepository.findBySoptampUserIdAndGeneration(soptampUserId, currentGeneration); - if(soptampPoint.isEmpty()){ - return; - } - val soptampPointEntity = soptampPoint.get(); - val newSoptampPoint = SoptampPoint.builder() - .id(soptampPointEntity.getId()) - .generation(soptampPointEntity.getGeneration()) - .soptampUserId(soptampPointEntity.getSoptampUserId()) - .points(0L) - .build(); - - soptampPointRepository.save(newSoptampPoint); - } - - public Map findPartRanks(Map partPoints) { - return partPoints.entrySet().stream() - .collect(Collectors.toMap( - Entry::getKey, - entry -> calculatePartRank(entry.getKey(), partPoints) - )); - } - - private PartRank calculatePartRank(Part part, Map partPoints) { - Integer rank = 1; - - for (Entry comparator : partPoints.entrySet()) { - if (partPoints.get(part) < comparator.getValue()) { - rank++; - } - } - - return PartRank.builder() - .part(part.getPartName()) - .rank(rank) - .points(partPoints.get(part)) - .build(); - } - - - public Long calculateSumOfPoints(List soptampPointList) { - return soptampPointList.stream() - .map(Point::getPoints) - .reduce(0L, Long::sum); + soptampPoint.ifPresent(SoptampPoint::initPoint); } public void deleteAll() { @@ -163,19 +82,23 @@ public List createCurrentGenerationSoptampPointList( val newSoptampUserList = soptampUserList.stream() .map(soptampUser -> prevSoptampUserIdList.contains(soptampUser.getId()) ? null : soptampUser) - .filter(x -> x != null) + .filter(Objects::nonNull) .toList(); val soptampPointList = newSoptampUserList.stream().map(soptampUser -> - SoptampPoint - .builder() - .generation(currentGeneration) - .points(0L) - .soptampUserId(soptampUser.getId()) - .build() + SoptampPoint.createNewSoptampPoint(currentGeneration, soptampUser.getId()) ).toList(); soptampPointRepository.saveAll(soptampPointList); return soptampPointList; } + + public List findSumOfPointAllParts() { + List allParts = Part.getAllParts(); + return allParts.stream() + .map(part -> { + Long point = soptampPointRepository.findSumOfPointBySamePartAndGeneration(part, currentGeneration); + return new PartPoint(part, point); + }).toList(); + } } diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampUserInfo.java b/src/main/java/org/sopt/app/application/soptamp/SoptampUserInfo.java index eb42646d..8d79c0b1 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampUserInfo.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampUserInfo.java @@ -1,37 +1,29 @@ package org.sopt.app.application.soptamp; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; -import lombok.ToString; +import org.sopt.app.domain.entity.SoptampUser; +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) public class SoptampUserInfo { - @Getter - @Builder - @ToString - public static class SoptampUser { - - private Long id; - private Long userId; - private String profileMessage; - private Long totalPoints; - private String nickname; - - public static SoptampUser of(Long id, Long userId, String profileMessage, Long totalPoints, String nickname) { - return new SoptampUser(id, userId, profileMessage, totalPoints, nickname); - } - } - - @Getter - @Builder - @ToString - public static class SoptampUserPlaygroundInfo { - - private Long userId; - private Long playgroundId; - private String name; - private Long generation; - private String part; + private Long id; + private Long userId; + private String profileMessage; + private Long totalPoints; + private String nickname; + + public static SoptampUserInfo of(SoptampUser soptampUser) { + return SoptampUserInfo.builder() + .id(soptampUser.getId()) + .userId(soptampUser.getUserId()) + .profileMessage(soptampUser.getProfileMessage()) + .totalPoints(soptampUser.getTotalPoints()) + .nickname(soptampUser.getNickname()) + .build(); } - } diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampUserPlaygroundInfo.java b/src/main/java/org/sopt/app/application/soptamp/SoptampUserPlaygroundInfo.java new file mode 100644 index 00000000..7d85508d --- /dev/null +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampUserPlaygroundInfo.java @@ -0,0 +1,18 @@ +package org.sopt.app.application.soptamp; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Builder +public class SoptampUserPlaygroundInfo { + + private Long userId; + private Long playgroundId; + private String name; + private Long generation; + private String part; +} diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java b/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java index f6532864..ecce8e21 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java @@ -8,12 +8,8 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.val; -import org.sopt.app.application.soptamp.SoptampPointInfo.Main; -import org.sopt.app.application.soptamp.SoptampPointInfo.Point; import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.common.response.ErrorCode; import org.sopt.app.domain.entity.SoptampUser; @@ -30,10 +26,10 @@ public class SoptampUserService { private final SoptampUserRepository soptampUserRepository; @Transactional(readOnly = true) - public SoptampUserInfo.SoptampUser getSoptampUserInfo(Long userId) { + public SoptampUserInfo getSoptampUserInfo(Long userId) { val user = soptampUserRepository.findByUserId(userId) .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())); - return SoptampUserInfo.SoptampUser.builder() + return SoptampUserInfo.builder() .id(user.getId()) .userId(user.getUserId()) .profileMessage(user.getProfileMessage()) @@ -51,16 +47,16 @@ public void checkUserNickname(String nickname) { } @Transactional - public SoptampUserInfo.SoptampUser editNickname(SoptampUserInfo.SoptampUser soptampUser, String nickname) { + public SoptampUserInfo editNickname(SoptampUserInfo soptampUserInfo, String nickname) { val newSoptampUser = SoptampUser.builder() - .id(soptampUser.getId()) - .userId(soptampUser.getUserId()) - .profileMessage(soptampUser.getProfileMessage()) - .totalPoints(soptampUser.getTotalPoints()) + .id(soptampUserInfo.getId()) + .userId(soptampUserInfo.getUserId()) + .profileMessage(soptampUserInfo.getProfileMessage()) + .totalPoints(soptampUserInfo.getTotalPoints()) .nickname(nickname) .build(); soptampUserRepository.save(newSoptampUser); - return SoptampUserInfo.SoptampUser.builder() + return SoptampUserInfo.builder() .id(newSoptampUser.getId()) .userId(newSoptampUser.getUserId()) .profileMessage(newSoptampUser.getProfileMessage()) @@ -70,23 +66,15 @@ public SoptampUserInfo.SoptampUser editNickname(SoptampUserInfo.SoptampUser sopt } @Transactional - public SoptampUserInfo.SoptampUser editProfileMessage(SoptampUserInfo.SoptampUser soptampUser, - String profileMessage) { + public SoptampUserInfo editProfileMessage(SoptampUserInfo soptampUserInfo, String profileMessage) { val newSoptampUser = SoptampUser.builder() - .id(soptampUser.getId()) - .userId(soptampUser.getUserId()) + .id(soptampUserInfo.getId()) + .userId(soptampUserInfo.getUserId()) .profileMessage(profileMessage) - .totalPoints(soptampUser.getTotalPoints()) - .nickname(soptampUser.getNickname()) + .totalPoints(soptampUserInfo.getTotalPoints()) + .nickname(soptampUserInfo.getNickname()) .build(); - soptampUserRepository.save(newSoptampUser); - return SoptampUserInfo.SoptampUser.of( - newSoptampUser.getId(), - newSoptampUser.getUserId(), - newSoptampUser.getProfileMessage(), - newSoptampUser.getTotalPoints(), - newSoptampUser.getNickname() - ); + return SoptampUserInfo.of(soptampUserRepository.save(newSoptampUser)); } @Transactional @@ -105,46 +93,17 @@ public Long updateSoptampUser(String name, Long userId) { return registerUser.get().getId(); } - public List
findRanks() { - val userList = soptampUserRepository.findAll(); - return this.getRanking(userList); - } - - public List findCurrentRanks(List soptampPointList) { - val soptampUserIdList = soptampPointList.stream() - .map(Point::getSoptampUserId).toList(); - val userList = soptampUserRepository.findAllById(soptampUserIdList); - return this.getCurrentRanking(userList, soptampPointList); - } - - private List
getRanking(List userList) { - val rankPoint = new AtomicInteger(1); - return userList.stream().sorted( - Comparator.comparing(SoptampUser::getTotalPoints).reversed()) - .map(user -> Main.builder() - .rank(rankPoint.getAndIncrement()) - .nickname(user.getNickname()) - .point(user.getTotalPoints()) - .profileMessage(user.getProfileMessage()) - .build()) - .collect(Collectors.toList()); + public List findAllBySoptampUserIds(List userIdList) { + return soptampUserRepository.findAllById(userIdList) + .stream().map(SoptampUserInfo::of) + .toList(); } - private List
getCurrentRanking(List userList, List soptampPointList) { - val rankPoint = new AtomicInteger(1); - return soptampPointList.stream().sorted(Comparator.comparing(Point::getPoints).reversed()) - .map(point -> { - val user = userList.stream() - .filter(u -> u.getId().equals(point.getSoptampUserId())) - .findFirst() - .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())); - return Main.builder() - .rank(rankPoint.getAndIncrement()) - .nickname(user.getNickname()) - .point(point.getPoints()) - .profileMessage(user.getProfileMessage()) - .build(); - }).collect(Collectors.toList()); + @Deprecated + public List findAllSoptampUsers() { + return soptampUserRepository.findAll() + .stream().map(SoptampUserInfo::of) + .toList(); } public List findSoptampUserByPart(Part part) { @@ -154,13 +113,15 @@ public List findSoptampUserByPart(Part part) { .toList(); } - public SoptampUser findRankByNickname(String nickname) { - return soptampUserRepository.findUserByNickname(nickname) - .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())); + public SoptampUserInfo findSoptampUserByNickname(String nickname) { + return SoptampUserInfo.of( + soptampUserRepository.findUserByNickname(nickname) + .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())) + ); } @Transactional - public SoptampUserInfo.SoptampUser addPoint(Long userId, Integer level) { + public SoptampUserInfo addPoint(Long userId, Integer level) { val user = soptampUserRepository.findByUserId(userId) .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())); val newTotalPoint = user.getTotalPoints() + level; @@ -171,18 +132,11 @@ public SoptampUserInfo.SoptampUser addPoint(Long userId, Integer level) { .totalPoints(newTotalPoint) .nickname(user.getNickname()) .build(); - soptampUserRepository.save(newSoptampUser); - return SoptampUserInfo.SoptampUser.builder() - .id(newSoptampUser.getId()) - .userId(newSoptampUser.getUserId()) - .profileMessage(newSoptampUser.getProfileMessage()) - .totalPoints(newSoptampUser.getTotalPoints()) - .nickname(newSoptampUser.getNickname()) - .build(); + return SoptampUserInfo.of(soptampUserRepository.save(newSoptampUser)); } @Transactional - public SoptampUserInfo.SoptampUser subtractPoint(Long userId, Integer level) { + public SoptampUserInfo subtractPoint(Long userId, Integer level) { val user = soptampUserRepository.findByUserId(userId) .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())); val newTotalPoint = user.getTotalPoints() - level; @@ -193,26 +147,13 @@ public SoptampUserInfo.SoptampUser subtractPoint(Long userId, Integer level) { .totalPoints(newTotalPoint) .nickname(user.getNickname()) .build(); - soptampUserRepository.save(newSoptampUser); - return SoptampUserInfo.SoptampUser.builder() - .id(newSoptampUser.getId()) - .userId(newSoptampUser.getUserId()) - .profileMessage(newSoptampUser.getProfileMessage()) - .totalPoints(newSoptampUser.getTotalPoints()) - .nickname(newSoptampUser.getNickname()) - .build(); + return SoptampUserInfo.of(soptampUserRepository.save(newSoptampUser)); } - public SoptampUserInfo.SoptampUser findByNickname(String nickname) { + public SoptampUserInfo findByNickname(String nickname) { val soptampUser = soptampUserRepository.findUserByNickname(nickname) .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND.getMessage())); - return SoptampUserInfo.SoptampUser.builder() - .id(soptampUser.getId()) - .userId(soptampUser.getUserId()) - .profileMessage(soptampUser.getProfileMessage()) - .totalPoints(soptampUser.getTotalPoints()) - .nickname(soptampUser.getNickname()) - .build(); + return SoptampUserInfo.of(soptampUser); } @Transactional @@ -243,11 +184,11 @@ public List getSoptampUserInfoList(List userIdList) { @Transactional public List initAllCurrentGenerationSoptampUser( List soptampUserList, - List userInfoList + List userInfoList ) { val validatedSoptampUserList = validateNickname(soptampUserList); - validatedSoptampUserList.stream().forEach(soptampUser -> { + validatedSoptampUserList.forEach(soptampUser -> { val userInfo = userInfoList.stream() .filter(e -> soptampUser.getUserId().equals(e.getUserId())) .findFirst().get(); @@ -275,8 +216,8 @@ public List validateNickname(List soptampUserList) { private HashMap> generateUniqueNicknameMap(List nicknameList) { val nicknameMap = new HashMap>(); - val uniqueNicknameList = nicknameList.stream().distinct().collect(Collectors.toList()); - uniqueNicknameList.stream().forEach(nickname -> { + val uniqueNicknameList = nicknameList.stream().distinct().toList(); + uniqueNicknameList.forEach(nickname -> { val count = Collections.frequency(nicknameList, nickname); if (count == 1) { nicknameMap.put(nickname, new ArrayList<>(List.of())); @@ -295,7 +236,7 @@ private List updateUniqueNickname( ) { soptampUserList.stream().sorted(Comparator.comparing(SoptampUser::getUserId)).forEach(soptampUser -> { val validatedNicknameList = nicknameMap.get(soptampUser.getNickname()); - if (validatedNicknameList.size() > 0) { + if (!validatedNicknameList.isEmpty()) { val validatedNickname = validatedNicknameList.get(0); validatedNicknameList.remove(0); nicknameMap.put(soptampUser.getNickname(), validatedNicknameList); diff --git a/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java b/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java index 6f13d827..3442832d 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java +++ b/src/main/java/org/sopt/app/application/stamp/StampDeletedEvent.java @@ -2,11 +2,9 @@ import java.util.List; import lombok.Getter; -import lombok.Setter; import org.sopt.app.common.event.Event; @Getter -@Setter public class StampDeletedEvent extends Event { private List fileUrls; diff --git a/src/main/java/org/sopt/app/application/stamp/StampService.java b/src/main/java/org/sopt/app/application/stamp/StampService.java index e99f63cc..7018f8ff 100644 --- a/src/main/java/org/sopt/app/application/stamp/StampService.java +++ b/src/main/java/org/sopt/app/application/stamp/StampService.java @@ -1,6 +1,5 @@ package org.sopt.app.application.stamp; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -96,10 +95,8 @@ public StampInfo.Stamp editStampContentsDeprecated( stamp.changeContents(editStampRequest.getContents()); } - stamp.setUpdatedAt(LocalDateTime.now()); - val newStamp = stampRepository.save(stamp); return StampInfo.Stamp.builder() - .id(newStamp.getId()) + .id(stamp.getId()) .build(); } @@ -120,10 +117,8 @@ public StampInfo.Stamp editStampContents( throw new BadRequestException(ErrorCode.INVALID_STAMP_ACTIVITY_DATE.getMessage()); } stamp.changeActivityDate(editStampRequest.getActivityDate()); - stamp.setUpdatedAt(LocalDateTime.now()); - val newStamp = stampRepository.save(stamp); return StampInfo.Stamp.builder() - .id(newStamp.getId()) + .id(stamp.getId()) .build(); } @@ -132,7 +127,6 @@ public void editStampImagesDeprecated(StampInfo.Stamp stamp, List imgPat val oldStamp = stampRepository.findById(stamp.getId()) .orElseThrow(() -> new BadRequestException(ErrorCode.STAMP_NOT_FOUND.getMessage())); oldStamp.changeImages(imgPaths); - stampRepository.save(oldStamp); } @Transactional(readOnly = true) 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 01cdc660..fdeb3f24 100644 --- a/src/main/java/org/sopt/app/application/user/UserService.java +++ b/src/main/java/org/sopt/app/application/user/UserService.java @@ -3,7 +3,7 @@ import java.util.List; import lombok.RequiredArgsConstructor; import lombok.val; -import org.sopt.app.application.auth.PlaygroundAuthInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo; import org.sopt.app.application.user.UserInfo.UserProfile; import org.sopt.app.common.exception.NotFoundException; import org.sopt.app.common.exception.UnauthorizedException; @@ -11,6 +11,7 @@ import org.sopt.app.domain.entity.User; import org.sopt.app.interfaces.postgres.UserRepository; import org.sopt.app.presentation.auth.AppAuthRequest; +import org.sopt.app.presentation.auth.AppAuthRequest.AccessTokenRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,7 +24,7 @@ public class UserService { @Transactional public UserInfo.Id loginWithUserPlaygroundId( - PlaygroundAuthInfo.PlaygroundMain playgroundMemberResponse + PlaygroundProfileInfo.PlaygroundMain playgroundMemberResponse ) { val registeredUser = userRepository.findUserByPlaygroundId( playgroundMemberResponse.getId()); @@ -67,18 +68,14 @@ public void deleteUser(User user) { @Transactional(readOnly = true) public AppAuthRequest.AccessTokenRequest getPlaygroundToken(UserInfo.Id userId) { val user = userRepository.findUserById(userId.getId()) - .orElseThrow( - () -> new UnauthorizedException(ErrorCode.INVALID_REFRESH_TOKEN.getMessage())); - val token = new AppAuthRequest.AccessTokenRequest(); - token.setAccessToken(user.getPlaygroundToken()); - return token; + .orElseThrow(() -> new UnauthorizedException(ErrorCode.INVALID_REFRESH_TOKEN.getMessage())); + return new AccessTokenRequest(user.getPlaygroundToken()); } @Transactional public void updatePlaygroundToken(UserInfo.Id userId, String playgroundToken) { val user = userRepository.findUserById(userId.getId()) - .orElseThrow( - () -> new UnauthorizedException(ErrorCode.INVALID_REFRESH_TOKEN.getMessage())); + .orElseThrow(() -> new UnauthorizedException(ErrorCode.INVALID_REFRESH_TOKEN.getMessage())); userRepository.save( User.builder() .id(user.getId()) diff --git a/src/main/java/org/sopt/app/common/event/Event.java b/src/main/java/org/sopt/app/common/event/Event.java index 9749b56d..b76ad989 100644 --- a/src/main/java/org/sopt/app/common/event/Event.java +++ b/src/main/java/org/sopt/app/common/event/Event.java @@ -2,10 +2,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Getter -@Setter @NoArgsConstructor public class Event { diff --git a/src/main/java/org/sopt/app/common/exception/ForbiddenException.java b/src/main/java/org/sopt/app/common/exception/ForbiddenException.java deleted file mode 100644 index 0a9e5636..00000000 --- a/src/main/java/org/sopt/app/common/exception/ForbiddenException.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sopt.app.common.exception; - -import org.springframework.http.HttpStatus; - -public class ForbiddenException extends BaseException { - - public ForbiddenException() { - super(HttpStatus.FORBIDDEN); - } - - public ForbiddenException(String message) { - super(HttpStatus.FORBIDDEN, message); - } -} diff --git a/src/main/java/org/sopt/app/common/exception/InternalServerException.java b/src/main/java/org/sopt/app/common/exception/InternalServerException.java new file mode 100644 index 00000000..b516780f --- /dev/null +++ b/src/main/java/org/sopt/app/common/exception/InternalServerException.java @@ -0,0 +1,10 @@ +package org.sopt.app.common.exception; + +import org.springframework.http.HttpStatus; + +public class InternalServerException extends BaseException { + + public InternalServerException(String message) { + super(HttpStatus.INTERNAL_SERVER_ERROR, message); + } +} diff --git a/src/main/java/org/sopt/app/common/exception/NotFoundException.java b/src/main/java/org/sopt/app/common/exception/NotFoundException.java index e2651b48..e07fd2fb 100644 --- a/src/main/java/org/sopt/app/common/exception/NotFoundException.java +++ b/src/main/java/org/sopt/app/common/exception/NotFoundException.java @@ -4,10 +4,6 @@ public class NotFoundException extends BaseException { - public NotFoundException() { - super(HttpStatus.NOT_FOUND); - } - public NotFoundException(String message) { super(HttpStatus.NOT_FOUND, message); } diff --git a/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java b/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java index 0b82c9f5..13cccc13 100644 --- a/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java +++ b/src/main/java/org/sopt/app/common/response/CommonControllerAdvice.java @@ -19,8 +19,6 @@ @RequiredArgsConstructor public class CommonControllerAdvice { - private final SlackService slackService; - @ExceptionHandler(value = BaseException.class) public ResponseEntity onKnownException(HttpServletRequest req, BaseException baseException) { final Long userId = getUserId(); @@ -32,7 +30,7 @@ public ResponseEntity onKnownException(HttpServletRequest req, BaseException bas baseException, userId, requestMethod, requestUri, baseExceptionMessage, baseExceptionStatusCode ); - slackService.sendSlackMessage("Error", message); + SlackService.sendSlackMessage("Error", message); return new ResponseEntity<>(CommonResponse.onFailure(baseExceptionStatusCode, baseExceptionMessage), null, baseExceptionStatusCode); diff --git a/src/main/java/org/sopt/app/domain/entity/AppService.java b/src/main/java/org/sopt/app/domain/entity/AppService.java index d8134dfd..f8d9e19e 100644 --- a/src/main/java/org/sopt/app/domain/entity/AppService.java +++ b/src/main/java/org/sopt/app/domain/entity/AppService.java @@ -10,10 +10,8 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Getter -@Setter @Entity @Table(name = "app_service", schema = "app_dev") @Builder diff --git a/src/main/java/org/sopt/app/domain/entity/BaseEntity.java b/src/main/java/org/sopt/app/domain/entity/BaseEntity.java index f4495d1f..a83e756b 100644 --- a/src/main/java/org/sopt/app/domain/entity/BaseEntity.java +++ b/src/main/java/org/sopt/app/domain/entity/BaseEntity.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Getter; -import lombok.Setter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -14,7 +13,6 @@ import java.time.LocalDateTime; @Getter -@Setter @MappedSuperclass @EntityListeners(AuditingEntityListener.class) public abstract class BaseEntity { diff --git a/src/main/java/org/sopt/app/domain/entity/Friend.java b/src/main/java/org/sopt/app/domain/entity/Friend.java index b62afd36..a334eca2 100644 --- a/src/main/java/org/sopt/app/domain/entity/Friend.java +++ b/src/main/java/org/sopt/app/domain/entity/Friend.java @@ -11,11 +11,9 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.hibernate.annotations.ColumnDefault; @Getter -@Setter @Entity @Table(name = "friend", schema = "app_dev") @Builder diff --git a/src/main/java/org/sopt/app/domain/entity/MainDescription.java b/src/main/java/org/sopt/app/domain/entity/MainDescription.java index cd873e2d..3a682237 100644 --- a/src/main/java/org/sopt/app/domain/entity/MainDescription.java +++ b/src/main/java/org/sopt/app/domain/entity/MainDescription.java @@ -10,12 +10,10 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Entity @Table(name = "main_description", schema = "app_dev") @Getter -@Setter @Builder @NoArgsConstructor @AllArgsConstructor diff --git a/src/main/java/org/sopt/app/domain/entity/Mission.java b/src/main/java/org/sopt/app/domain/entity/Mission.java index c6ccfe00..72dc040b 100644 --- a/src/main/java/org/sopt/app/domain/entity/Mission.java +++ b/src/main/java/org/sopt/app/domain/entity/Mission.java @@ -13,7 +13,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; @@ -24,7 +23,6 @@ typeClass = ListArrayType.class ) @Getter -@Setter @Builder @NoArgsConstructor @AllArgsConstructor diff --git a/src/main/java/org/sopt/app/domain/entity/PokeHistory.java b/src/main/java/org/sopt/app/domain/entity/PokeHistory.java index 10144425..e4cba339 100644 --- a/src/main/java/org/sopt/app/domain/entity/PokeHistory.java +++ b/src/main/java/org/sopt/app/domain/entity/PokeHistory.java @@ -11,11 +11,9 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.hibernate.annotations.Type; @Getter -@Setter @Entity @Table(name = "poke_history", schema = "app_dev") @Builder diff --git a/src/main/java/org/sopt/app/domain/entity/PokeMessage.java b/src/main/java/org/sopt/app/domain/entity/PokeMessage.java index 3e71a881..482abe6c 100644 --- a/src/main/java/org/sopt/app/domain/entity/PokeMessage.java +++ b/src/main/java/org/sopt/app/domain/entity/PokeMessage.java @@ -4,7 +4,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import javax.persistence.*; import javax.validation.constraints.NotNull; @@ -13,7 +12,6 @@ import org.sopt.app.domain.enums.PokeMessageTypeConverter; @Getter -@Setter @Entity @Table(name = "poke_message", schema = "app_dev") @Builder diff --git a/src/main/java/org/sopt/app/domain/entity/SoptampPoint.java b/src/main/java/org/sopt/app/domain/entity/SoptampPoint.java index 1752cad7..87323a6a 100644 --- a/src/main/java/org/sopt/app/domain/entity/SoptampPoint.java +++ b/src/main/java/org/sopt/app/domain/entity/SoptampPoint.java @@ -31,4 +31,24 @@ public class SoptampPoint extends BaseEntity{ @Column(name = "points") private Long points; + + public void addPointsByLevelValue(Integer level) { + this.points += level; + } + + public void subtractPointsByLevelValue(Integer level) { + this.points -= level; + } + + public void initPoint() { + this.points = 0L; + } + + public static SoptampPoint createNewSoptampPoint(Long generation, Long soptampUserId) { + return SoptampPoint.builder() + .generation(generation) + .soptampUserId(soptampUserId) + .points(0L) + .build(); + } } diff --git a/src/main/java/org/sopt/app/domain/enums/Part.java b/src/main/java/org/sopt/app/domain/enums/Part.java index c8d3b50c..d35096b3 100644 --- a/src/main/java/org/sopt/app/domain/enums/Part.java +++ b/src/main/java/org/sopt/app/domain/enums/Part.java @@ -1,18 +1,28 @@ package org.sopt.app.domain.enums; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Getter; @AllArgsConstructor @Getter public enum Part { - PLAN("๊ธฐํš"), - DESIGN("๋””์ž์ธ"), - ANDROID("์•ˆ๋“œ"), - IOS("์•„์š”"), - WEB("์›น"), - SERVER("์„œ๋ฒ„"), + PLAN("๊ธฐํš", 1), + DESIGN("๋””์ž์ธ", 2), + WEB("์›น", 3), + IOS("์•„์š”", 4), + ANDROID("์•ˆ๋“œ", 5), + SERVER("์„œ๋ฒ„", 6), ; private final String partName; + private final int partOrder; + + public static List getAllParts() { + return Arrays.stream(Part.class.getEnumConstants()) + .sorted(Comparator.comparing(Part::getPartOrder)) + .toList(); + } } diff --git a/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java b/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java index afc05169..1e595d9f 100644 --- a/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java +++ b/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java @@ -7,7 +7,7 @@ import org.sopt.app.application.auth.PlaygroundAuthService; import org.sopt.app.application.mission.MissionService; import org.sopt.app.application.soptamp.SoptampPointService; -import org.sopt.app.application.soptamp.SoptampUserInfo.SoptampUserPlaygroundInfo; +import org.sopt.app.application.soptamp.SoptampUserPlaygroundInfo; import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.application.stamp.StampService; import org.sopt.app.application.user.UserInfo.UserProfile; @@ -40,8 +40,8 @@ public void initAllMissionAndStampAndPoints() { @Transactional public AdminSoptampResponse.Rows initCurrentGenerationInfo(User user) { // ํ”Œ๊ทธ์—์„œ ํ˜„์žฌ ๊ธฐ์ˆ˜ ๋ฉค๋ฒ„ ์•„์ด๋”” ์กฐํšŒ - val currentGenerationPlaygroundIdList = playgroundAuthService.getPlayGroundUserIds(user.getPlaygroundToken()) - .getUserIds(); + val currentGenerationPlaygroundIdList = + playgroundAuthService.getPlayGroundUserIds(user.getPlaygroundToken()).userIds(); // ํ”Œ๊ทธ์—์„œ ํ˜„์žฌ ๊ธฐ์ˆ˜ ๋ฉค๋ฒ„ ํ”„๋กœํ•„ ์กฐํšŒ val memberProfileList = playgroundAuthService.getPlaygroundMemberProfiles( @@ -71,8 +71,8 @@ public AdminSoptampResponse.Rows initCurrentGenerationInfo(User user) { ).filter(Objects::nonNull).toList(); // ํ”Œ๊ทธ ํŒŒํŠธ, ๊ธฐ์ˆ˜, ์ ์ˆ˜ ์ •๋ณด ์—…๋ฐ์ดํŠธ - val updatedSoptampUserList = soptampUserService.initAllCurrentGenerationSoptampUser(soptampUserList, - userInfoList); + val updatedSoptampUserList = + soptampUserService.initAllCurrentGenerationSoptampUser(soptampUserList, userInfoList); // ํ”Œ๊ทธ ์•„์ด๋””๋กœ SoptampPoint ํ˜„ํ™œ๊ธฐ์ˆ˜ row ์ถ”๊ฐ€ val currentGenerationSoptampPointList = soptampPointService.createCurrentGenerationSoptampPointList( diff --git a/src/main/java/org/sopt/app/facade/DescriptionFacade.java b/src/main/java/org/sopt/app/facade/DescriptionFacade.java index 86ea0cbb..231c02a9 100644 --- a/src/main/java/org/sopt/app/facade/DescriptionFacade.java +++ b/src/main/java/org/sopt/app/facade/DescriptionFacade.java @@ -19,6 +19,6 @@ public class DescriptionFacade { @Transactional(readOnly = true) public MainDescription getMainDescriptionForUser(User user) { val userActiveInfo = playgroundAuthService.getPlaygroundUserActiveInfo(user.getPlaygroundToken(), user.getPlaygroundId()); - return descriptionService.getMainDescription(userActiveInfo.getStatus()); + return descriptionService.getMainDescription(userActiveInfo.status()); } } diff --git a/src/main/java/org/sopt/app/facade/PokeFacade.java b/src/main/java/org/sopt/app/facade/PokeFacade.java index 13f7fa50..7f366e62 100644 --- a/src/main/java/org/sopt/app/facade/PokeFacade.java +++ b/src/main/java/org/sopt/app/facade/PokeFacade.java @@ -17,10 +17,9 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.val; -import org.sopt.app.application.auth.PlaygroundAuthInfo.ActivityCardinalInfo; -import org.sopt.app.application.auth.PlaygroundAuthInfo.OwnPlaygroundProfile; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundActivity; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfile; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.ActivityCardinalInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.OwnPlaygroundProfile; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundProfile; import org.sopt.app.application.auth.PlaygroundAuthService; import org.sopt.app.application.poke.FriendService; import org.sopt.app.application.poke.PokeHistoryService; @@ -78,7 +77,7 @@ public List getRecommendUserForNew(String playgroundToken, Lo Long userId ) { val playgroundUserIds = playgroundAuthService.getPlayGroundUserIds(playgroundToken); - val notFriendUserPlaygroundIds = userService.getUserProfilesByPlaygroundIds(playgroundUserIds.getUserIds()) + val notFriendUserPlaygroundIds = userService.getUserProfilesByPlaygroundIds(playgroundUserIds.userIds()) .stream() .filter(userProfile -> !userId.equals(userProfile.getUserId()) && !friendService.isFriendEachOther( userId, userProfile.getUserId())) diff --git a/src/main/java/org/sopt/app/facade/RankFacade.java b/src/main/java/org/sopt/app/facade/RankFacade.java new file mode 100644 index 00000000..5ebacf47 --- /dev/null +++ b/src/main/java/org/sopt/app/facade/RankFacade.java @@ -0,0 +1,62 @@ +package org.sopt.app.facade; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.sopt.app.application.rank.SoptampPartRankCalculator; +import org.sopt.app.application.rank.SoptampUserRankCalculator; +import org.sopt.app.application.soptamp.SoptampPointInfo.Main; +import org.sopt.app.application.soptamp.SoptampPointInfo.PartPoint; +import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; +import org.sopt.app.application.soptamp.SoptampPointInfo.Point; +import org.sopt.app.application.soptamp.SoptampPointService; +import org.sopt.app.application.soptamp.SoptampUserInfo; +import org.sopt.app.application.soptamp.SoptampUserService; +import org.sopt.app.domain.enums.Part; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class RankFacade { + + private final SoptampUserService soptampUserService; + private final SoptampPointService soptampPointService; + + @Transactional(readOnly = true) + @Deprecated + public List
findAllSoptampUserRanks() { + List soptampUsers = soptampUserService.findAllSoptampUsers(); + SoptampUserRankCalculator soptampUserRankCalculator = new SoptampUserRankCalculator(soptampUsers); + return soptampUserRankCalculator.calculateRank(); + } + + @Transactional(readOnly = true) + public List
findCurrentRanks() { + List soptampPointList = soptampPointService.findCurrentGenerationPoints(); + List soptampUserIdList = soptampPointList.stream().map(Point::getSoptampUserId).toList(); + + return getMainsByCalculateRanking(soptampUserIdList, soptampPointList); + } + + private List
getMainsByCalculateRanking(List soptampUserIdList, List soptampPointList) { + List userList = soptampUserService.findAllBySoptampUserIds(soptampUserIdList); + + SoptampUserRankCalculator soptampUserRankCalculator = new SoptampUserRankCalculator(userList); + return soptampUserRankCalculator.calculateRanking(soptampPointList); + } + + @Transactional(readOnly = true) + public List
findCurrentRanksByPart(Part part) { + List soptampUserIdList = soptampUserService.findSoptampUserByPart(part); + List soptampPointList = soptampPointService.findCurrentPointListBySoptampUserIds(soptampUserIdList); + + return getMainsByCalculateRanking(soptampUserIdList, soptampPointList); + } + + @Transactional(readOnly = true) + public List findAllPartRanks() { + List partPoints = soptampPointService.findSumOfPointAllParts(); + SoptampPartRankCalculator soptampPartRankCalculator = new SoptampPartRankCalculator(partPoints); + return soptampPartRankCalculator.findAllPartRanks(); + } +} diff --git a/src/main/java/org/sopt/app/facade/SoptampFacade.java b/src/main/java/org/sopt/app/facade/SoptampFacade.java index aee099d3..3f621b8f 100644 --- a/src/main/java/org/sopt/app/facade/SoptampFacade.java +++ b/src/main/java/org/sopt/app/facade/SoptampFacade.java @@ -10,6 +10,9 @@ import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.application.stamp.StampInfo; import org.sopt.app.application.stamp.StampService; +import org.sopt.app.domain.entity.Mission; +import org.sopt.app.presentation.rank.RankResponse; +import org.sopt.app.presentation.rank.RankResponseMapper; import org.sopt.app.presentation.stamp.StampRequest; import org.sopt.app.presentation.stamp.StampRequest.RegisterStampRequest; import org.springframework.stereotype.Service; @@ -25,6 +28,7 @@ public class SoptampFacade { private final MissionService missionService; private final SoptampUserService soptampUserService; private final SoptampPointService soptampPointService; + private final RankResponseMapper rankResponseMapper; @Transactional public StampInfo.Stamp uploadStampDeprecated(Long userId, Long missionId, RegisterStampRequest registerStampRequest, List multipartFileList){ @@ -64,13 +68,13 @@ public void deleteStampAll(Long userId){ } @Transactional - public SoptampUserInfo.SoptampUser editSoptampUserNickname(Long userId, String nickname){ + public SoptampUserInfo editSoptampUserNickname(Long userId, String nickname){ val soptampUser = soptampUserService.getSoptampUserInfo(userId); return soptampUserService.editNickname(soptampUser, nickname); } @Transactional - public SoptampUserInfo.SoptampUser editSoptampUserProfileMessage(Long userId, String newProfileMessage){ + public SoptampUserInfo editSoptampUserProfileMessage(Long userId, String newProfileMessage){ val soptampUser = soptampUserService.getSoptampUserInfo(userId); return soptampUserService.editProfileMessage(soptampUser, newProfileMessage); } @@ -90,4 +94,11 @@ public StampInfo.Stamp editStamp(StampRequest.EditStampRequest editStampRequest, } return stamp; } + + public RankResponse.Detail findSoptampUserAndCompletedMissionByNickname(String nickname) { + SoptampUserInfo soptampUserInfo = soptampUserService.findSoptampUserByNickname(nickname); + List missionList = missionService.getCompleteMission(soptampUserInfo.getUserId()); + + return rankResponseMapper.of(soptampUserInfo, missionList); + } } diff --git a/src/main/java/org/sopt/app/facade/UserFacade.java b/src/main/java/org/sopt/app/facade/UserFacade.java index 61a259a0..7ef4c9e1 100644 --- a/src/main/java/org/sopt/app/facade/UserFacade.java +++ b/src/main/java/org/sopt/app/facade/UserFacade.java @@ -6,7 +6,7 @@ import org.sopt.app.application.auth.PlaygroundAuthService; import org.sopt.app.application.notification.NotificationService; import org.sopt.app.application.operation.OperationInfo; -import org.sopt.app.application.service.AppServiceService; +import org.sopt.app.application.app_service.AppServiceService; import org.sopt.app.domain.entity.User; import org.sopt.app.presentation.user.UserResponse.AppService; import org.sopt.app.presentation.user.UserResponse.MainView; diff --git a/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java b/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java index 9c2940c6..07c9ff2b 100644 --- a/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java +++ b/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java @@ -3,11 +3,14 @@ import feign.HeaderMap; import feign.Param; import feign.RequestLine; -import org.sopt.app.application.auth.PlaygroundAuthInfo; -import org.sopt.app.application.auth.PlaygroundAuthInfo.ActiveUserIds; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfile; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundUserIds; -import org.sopt.app.application.auth.PlaygroundAuthInfo.RecommendFriendRequest; +import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.RefreshedToken; +import org.sopt.app.application.auth.dto.PlaygroundPostInfo; +import org.sopt.app.application.auth.dto.PlaygroundPostInfo.PlaygroundPostResponse; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.ActiveUserIds; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundProfile; +import org.sopt.app.application.auth.dto.RecommendFriendRequest; +import org.sopt.app.application.auth.dto.RecommendedFriendInfo.PlaygroundUserIds; import org.sopt.app.presentation.auth.AppAuthRequest; import java.util.List; @@ -21,7 +24,7 @@ AppAuthRequest.AccessTokenRequest getAccessToken(@HeaderMap final Map headers, + RefreshedToken refreshPlaygroundToken(@HeaderMap Map headers, AppAuthRequest.AccessTokenRequest tokenRequest); @RequestLine("GET /internal/api/v1/members/latest?generation={generation}") @@ -36,12 +39,15 @@ List getPlaygroundMemberProfiles(@HeaderMap Map headers); + PlaygroundProfileInfo.PlaygroundMain getPlaygroundMember(@HeaderMap Map headers); @RequestLine("GET /api/v1/members/profile/me") - PlaygroundAuthInfo.OwnPlaygroundProfile getOwnPlaygroundProfile(@HeaderMap Map headers); + PlaygroundProfileInfo.OwnPlaygroundProfile getOwnPlaygroundProfile(@HeaderMap Map headers); @RequestLine("POST /internal/api/v1/members/profile/recommend") PlaygroundUserIds getPlaygroundUserIdsForSameRecommendType( @HeaderMap Map headers, @RequestBody RecommendFriendRequest request); + + @RequestLine("GET /api/v1/community/posts/hot") + PlaygroundPostResponse getPlaygroundHotPost(@HeaderMap Map headers); } diff --git a/src/main/java/org/sopt/app/interfaces/postgres/FriendCustomRepository.java b/src/main/java/org/sopt/app/interfaces/postgres/friend/FriendCustomRepository.java similarity index 81% rename from src/main/java/org/sopt/app/interfaces/postgres/FriendCustomRepository.java rename to src/main/java/org/sopt/app/interfaces/postgres/friend/FriendCustomRepository.java index 739870d1..a7b05fdc 100644 --- a/src/main/java/org/sopt/app/interfaces/postgres/FriendCustomRepository.java +++ b/src/main/java/org/sopt/app/interfaces/postgres/friend/FriendCustomRepository.java @@ -1,4 +1,4 @@ -package org.sopt.app.interfaces.postgres; +package org.sopt.app.interfaces.postgres.friend; import java.util.List; diff --git a/src/main/java/org/sopt/app/interfaces/postgres/FriendRepository.java b/src/main/java/org/sopt/app/interfaces/postgres/friend/FriendRepository.java similarity index 95% rename from src/main/java/org/sopt/app/interfaces/postgres/FriendRepository.java rename to src/main/java/org/sopt/app/interfaces/postgres/friend/FriendRepository.java index 2526cb24..88433c04 100644 --- a/src/main/java/org/sopt/app/interfaces/postgres/FriendRepository.java +++ b/src/main/java/org/sopt/app/interfaces/postgres/friend/FriendRepository.java @@ -1,4 +1,4 @@ -package org.sopt.app.interfaces.postgres; +package org.sopt.app.interfaces.postgres.friend; import org.sopt.app.domain.entity.Friend; import org.springframework.data.domain.Page; diff --git a/src/main/java/org/sopt/app/interfaces/postgres/FriendRepositoryImpl.java b/src/main/java/org/sopt/app/interfaces/postgres/friend/FriendRepositoryImpl.java similarity index 96% rename from src/main/java/org/sopt/app/interfaces/postgres/FriendRepositoryImpl.java rename to src/main/java/org/sopt/app/interfaces/postgres/friend/FriendRepositoryImpl.java index 1e67da53..2a2f108b 100644 --- a/src/main/java/org/sopt/app/interfaces/postgres/FriendRepositoryImpl.java +++ b/src/main/java/org/sopt/app/interfaces/postgres/friend/FriendRepositoryImpl.java @@ -1,11 +1,10 @@ -package org.sopt.app.interfaces.postgres; +package org.sopt.app.interfaces.postgres.friend; import com.querydsl.core.types.SubQueryExpression; import com.querydsl.core.types.dsl.Expressions; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; import lombok.RequiredArgsConstructor; -import lombok.val; import org.sopt.app.domain.entity.QFriend; @RequiredArgsConstructor diff --git a/src/main/java/org/sopt/app/interfaces/postgres/SoptampPointRepository.java b/src/main/java/org/sopt/app/interfaces/postgres/soptamp_point/SoptampPointJpaRepository.java similarity index 76% rename from src/main/java/org/sopt/app/interfaces/postgres/SoptampPointRepository.java rename to src/main/java/org/sopt/app/interfaces/postgres/soptamp_point/SoptampPointJpaRepository.java index 48477fa4..d216533d 100644 --- a/src/main/java/org/sopt/app/interfaces/postgres/SoptampPointRepository.java +++ b/src/main/java/org/sopt/app/interfaces/postgres/soptamp_point/SoptampPointJpaRepository.java @@ -1,11 +1,11 @@ -package org.sopt.app.interfaces.postgres; +package org.sopt.app.interfaces.postgres.soptamp_point; import java.util.List; import java.util.Optional; import org.sopt.app.domain.entity.SoptampPoint; import org.springframework.data.jpa.repository.JpaRepository; -public interface SoptampPointRepository extends JpaRepository { +public interface SoptampPointJpaRepository extends JpaRepository { List findAllByGeneration(Long currentGeneration); diff --git a/src/main/java/org/sopt/app/interfaces/postgres/soptamp_point/SoptampPointRepository.java b/src/main/java/org/sopt/app/interfaces/postgres/soptamp_point/SoptampPointRepository.java new file mode 100644 index 00000000..6884e509 --- /dev/null +++ b/src/main/java/org/sopt/app/interfaces/postgres/soptamp_point/SoptampPointRepository.java @@ -0,0 +1,23 @@ +package org.sopt.app.interfaces.postgres.soptamp_point; + +import java.util.List; +import java.util.Optional; +import org.sopt.app.domain.entity.SoptampPoint; +import org.sopt.app.domain.enums.Part; + +public interface SoptampPointRepository { + + SoptampPoint save(SoptampPoint soptampPoint); + + void saveAll(List soptampPoint); + + void deleteAll(); + + List findAllByGeneration(Long currentGeneration); + + Optional findBySoptampUserIdAndGeneration(Long soptampUserId, Long currentGeneration); + + List findAllBySoptampUserIdInAndGeneration(List soptampUserIdList, Long currentGeneration); + + Long findSumOfPointBySamePartAndGeneration(Part part, Long generation); +} diff --git a/src/main/java/org/sopt/app/interfaces/postgres/soptamp_point/SoptampPointRepositoryImpl.java b/src/main/java/org/sopt/app/interfaces/postgres/soptamp_point/SoptampPointRepositoryImpl.java new file mode 100644 index 00000000..70caf2ab --- /dev/null +++ b/src/main/java/org/sopt/app/interfaces/postgres/soptamp_point/SoptampPointRepositoryImpl.java @@ -0,0 +1,69 @@ +package org.sopt.app.interfaces.postgres.soptamp_point; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.List; +import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.sopt.app.domain.entity.QSoptampPoint; +import org.sopt.app.domain.entity.QSoptampUser; +import org.sopt.app.domain.entity.SoptampPoint; +import org.sopt.app.domain.enums.Part; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class SoptampPointRepositoryImpl implements SoptampPointRepository { + + private final SoptampPointJpaRepository soptampPointJpaRepository; + private final JPAQueryFactory queryFactory; + + @Override + public SoptampPoint save(SoptampPoint soptampPoint) { + return soptampPointJpaRepository.save(soptampPoint); + } + + @Override + public void saveAll(List soptampPoints) { + soptampPointJpaRepository.saveAll(soptampPoints); + } + + @Override + public void deleteAll() { + soptampPointJpaRepository.deleteAll(); + } + + @Override + public List findAllByGeneration(Long currentGeneration) { + return soptampPointJpaRepository.findAllByGeneration(currentGeneration); + } + + @Override + public Optional findBySoptampUserIdAndGeneration(Long soptampUserId, Long currentGeneration) { + return soptampPointJpaRepository.findBySoptampUserIdAndGeneration(soptampUserId, currentGeneration); + } + + @Override + public List findAllBySoptampUserIdInAndGeneration(List soptampUserIdList, + Long currentGeneration) { + return soptampPointJpaRepository.findAllBySoptampUserIdInAndGeneration(soptampUserIdList, currentGeneration); + } + + @Override + public Long findSumOfPointBySamePartAndGeneration(Part part, Long generation) { + QSoptampPoint soptampPoint = new QSoptampPoint("soptampPoint"); + QSoptampUser soptampUser = new QSoptampUser("soptampUser"); + + return Optional.ofNullable( + queryFactory + .select(soptampPoint.points.sum()) + .from(soptampUser) + .join(soptampPoint) + .on(soptampPoint.soptampUserId.eq(soptampUser.id) + .and(soptampUser.part.eq(String.valueOf(part)) + .and(soptampUser.generation.eq(generation)))) + . fetchOne()) + .orElse(0L); + } + + +} diff --git a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java index 3335f441..b8033a82 100644 --- a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java +++ b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java @@ -35,13 +35,13 @@ public class AdminSoptampController { @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) @DeleteMapping(value = "/point") - public ResponseEntity initAllMissionAndStampAndPoints( + public ResponseEntity initAllMissionAndStampAndPoints( @AuthenticationPrincipal User user, @RequestParam(name = "password") String password ) { validateAdmin(password); adminSoptampFacade.initAllMissionAndStampAndPoints(); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } @Operation(summary = "ํ™œ๋™ ๊ธฐ์ˆ˜ ์ •๋ณด ์ „์ฒด ์ดˆ๊ธฐํ™”") @@ -57,7 +57,7 @@ public ResponseEntity initCurrentGenerationInfo( ) { validateAdmin(password); val rows = adminSoptampFacade.initCurrentGenerationInfo(user); - return ResponseEntity.status(HttpStatus.OK).body(rows); + return ResponseEntity.ok(rows); } private void validateAdmin(String password) { diff --git a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampResponse.java b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampResponse.java index 6dc25a58..a09b50fb 100644 --- a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampResponse.java +++ b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampResponse.java @@ -1,16 +1,15 @@ package org.sopt.app.presentation.admin; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class AdminSoptampResponse { @Getter - @Setter - @ToString @Builder public static class Rows { diff --git a/src/main/java/org/sopt/app/presentation/auth/AppAuthController.java b/src/main/java/org/sopt/app/presentation/auth/AppAuthController.java index 2899caf6..28d39b3a 100644 --- a/src/main/java/org/sopt/app/presentation/auth/AppAuthController.java +++ b/src/main/java/org/sopt/app/presentation/auth/AppAuthController.java @@ -35,7 +35,7 @@ public ResponseEntity playgroundLogin( @Valid @RequestBody AppAuthRequest.CodeRequest codeRequest ) { val response = authFacade.loginWithPlayground(codeRequest); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "ํ† ํฐ ๋ฆฌํ”„๋ ˆ์‹œ") @@ -49,6 +49,6 @@ public ResponseEntity refreshToken( @Valid @RequestBody AppAuthRequest.RefreshRequest refreshRequest ) { val response = authFacade.getRefreshToken(refreshRequest); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } } \ No newline at end of file diff --git a/src/main/java/org/sopt/app/presentation/auth/AppAuthRequest.java b/src/main/java/org/sopt/app/presentation/auth/AppAuthRequest.java index 698f8bf9..8d98eba2 100644 --- a/src/main/java/org/sopt/app/presentation/auth/AppAuthRequest.java +++ b/src/main/java/org/sopt/app/presentation/auth/AppAuthRequest.java @@ -2,15 +2,17 @@ import io.swagger.v3.oas.annotations.media.Schema; import javax.validation.constraints.NotNull; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class AppAuthRequest { @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class CodeRequest { @Schema(description = "ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ OAuth Token", example = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyMiIsImV4cCI6MTY4MDAxNDQzNn0.asdfasdfasdfasdfasdfasdf") @@ -19,16 +21,16 @@ public static class CodeRequest { } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class AccessTokenRequest { private String accessToken; } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class RefreshRequest { @Schema(description = "์•ฑ Refresh Token", example = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyMiIsImV4cCI6MTY4MDAxNDQzNn0.asdfasdfasdfasdfasdfasdf") diff --git a/src/main/java/org/sopt/app/presentation/auth/AppAuthResponse.java b/src/main/java/org/sopt/app/presentation/auth/AppAuthResponse.java index 5c5bf277..30962353 100644 --- a/src/main/java/org/sopt/app/presentation/auth/AppAuthResponse.java +++ b/src/main/java/org/sopt/app/presentation/auth/AppAuthResponse.java @@ -1,16 +1,18 @@ package org.sopt.app.presentation.auth; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; import org.sopt.app.domain.enums.UserStatus; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class AppAuthResponse { @Getter - @Setter - @ToString + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PUBLIC) public static class LoginResponse { private Long userId; @@ -18,8 +20,8 @@ public static class LoginResponse { } @Getter - @Setter - @ToString + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PUBLIC) public static class Token { @Schema(description = "์•ฑ ์„œ๋ฒ„ AccessToken", example = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyMiIsImV4cCI6MTY4MDAxNDQzNn0.asdfasdfasdfasdfasdfasdf") diff --git a/src/main/java/org/sopt/app/presentation/auth/PlaygroundAuthRequest.java b/src/main/java/org/sopt/app/presentation/auth/PlaygroundAuthRequest.java deleted file mode 100644 index aed3b72a..00000000 --- a/src/main/java/org/sopt/app/presentation/auth/PlaygroundAuthRequest.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sopt.app.presentation.auth; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -public class PlaygroundAuthRequest { - /** - * Playground SSO Auth DTO - */ - @Getter - @Setter - @ToString - public static class PlaygroundAccessTokenRequest { - private String code; - - } - -} diff --git a/src/main/java/org/sopt/app/presentation/auth/PlaygroundAuthResponse.java b/src/main/java/org/sopt/app/presentation/auth/PlaygroundAuthResponse.java deleted file mode 100644 index 997421d4..00000000 --- a/src/main/java/org/sopt/app/presentation/auth/PlaygroundAuthResponse.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sopt.app.presentation.auth; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -public class PlaygroundAuthResponse { - /** - * Playground SSO Auth DTO - */ - @Getter - @Setter - @ToString - public static class PlaygroundAccessTokenResponse { - private String accessToken; - - } -} diff --git a/src/main/java/org/sopt/app/presentation/config/ConfigController.java b/src/main/java/org/sopt/app/presentation/config/ConfigController.java index c4df1dfd..9df17015 100644 --- a/src/main/java/org/sopt/app/presentation/config/ConfigController.java +++ b/src/main/java/org/sopt/app/presentation/config/ConfigController.java @@ -28,6 +28,6 @@ public class ConfigController { }) @GetMapping(value = "/availability") public ResponseEntity getUserInfo() { - return ResponseEntity.status(HttpStatus.OK).body(Availability.builder().isAvailable(isAvailable).build()); + return ResponseEntity.ok(Availability.builder().isAvailable(isAvailable).build()); } } diff --git a/src/main/java/org/sopt/app/presentation/description/DescriptionController.java b/src/main/java/org/sopt/app/presentation/description/DescriptionController.java index d79ea3bf..9544e2b7 100644 --- a/src/main/java/org/sopt/app/presentation/description/DescriptionController.java +++ b/src/main/java/org/sopt/app/presentation/description/DescriptionController.java @@ -35,7 +35,7 @@ public ResponseEntity getMainDescription( @AuthenticationPrincipal User user ) { val response = descriptionFacade.getMainDescriptionForUser(user); - return ResponseEntity.status(HttpStatus.OK).body( + return ResponseEntity.ok( DescriptionResponse.MainDescription.builder() .topDescription(response.getTopDescription()) .bottomDescription(response.getBottomDescription()) diff --git a/src/main/java/org/sopt/app/presentation/description/DescriptionResponse.java b/src/main/java/org/sopt/app/presentation/description/DescriptionResponse.java index 6582ce75..83fda807 100644 --- a/src/main/java/org/sopt/app/presentation/description/DescriptionResponse.java +++ b/src/main/java/org/sopt/app/presentation/description/DescriptionResponse.java @@ -1,16 +1,18 @@ package org.sopt.app.presentation.description; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class DescriptionResponse { @Getter - @Setter - @ToString + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PUBLIC) @Builder public static class MainDescription { @Schema(description="๋ฉ”์ธ ์ƒ๋‹จ ๋ฌธ๊ตฌ", example = "33๊ธฐ Do sopt์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!") diff --git a/src/main/java/org/sopt/app/presentation/mission/MissionController.java b/src/main/java/org/sopt/app/presentation/mission/MissionController.java index 0bb87737..26e5c73e 100644 --- a/src/main/java/org/sopt/app/presentation/mission/MissionController.java +++ b/src/main/java/org/sopt/app/presentation/mission/MissionController.java @@ -40,7 +40,7 @@ public class MissionController { public ResponseEntity> findAllMission(@AuthenticationPrincipal User user) { val result = missionService.findAllMission(user.getId()); val response = missionResponseMapper.ofCompleteness(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @@ -54,7 +54,7 @@ public ResponseEntity registerMission( @Valid @RequestBody MissionRequest.RegisterMissionRequest registerMissionRequest) { val mission = missionService.uploadMission(registerMissionRequest); val response = missionResponseMapper.of(mission.getId()); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์™„๋ฃŒ ๋ฏธ์…˜๋งŒ ์กฐํšŒํ•˜๊ธฐ") @@ -66,7 +66,7 @@ public ResponseEntity registerMission( public ResponseEntity> findCompleteMission(@AuthenticationPrincipal User user) { val result = missionService.getCompleteMission(user.getId()); val response = missionResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "๋ฏธ์™„๋ฃŒ ๋ฏธ์…˜๋งŒ ์กฐํšŒํ•˜๊ธฐ") @@ -78,6 +78,6 @@ public ResponseEntity> findCompleteMission(@Au public ResponseEntity> findInCompleteMission(@AuthenticationPrincipal User user) { val result = missionService.getIncompleteMission(user.getId()); val response = missionResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } } diff --git a/src/main/java/org/sopt/app/presentation/mission/MissionRequest.java b/src/main/java/org/sopt/app/presentation/mission/MissionRequest.java index a4620909..58d953a7 100644 --- a/src/main/java/org/sopt/app/presentation/mission/MissionRequest.java +++ b/src/main/java/org/sopt/app/presentation/mission/MissionRequest.java @@ -2,15 +2,17 @@ import io.swagger.v3.oas.annotations.media.Schema; import javax.validation.constraints.NotNull; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class MissionRequest { @Getter - @Setter - @ToString + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PUBLIC) public static class RegisterMissionRequest { @Schema(description = "๋ฏธ์…˜ ์ด๋ฏธ์ง€", example = "https://s3.ap-northeast-2.amazonaws.com/example/283aab53-22e3-46da-85ec-146c99f82ed4") diff --git a/src/main/java/org/sopt/app/presentation/mission/MissionResponse.java b/src/main/java/org/sopt/app/presentation/mission/MissionResponse.java index f9d926da..38176a7c 100644 --- a/src/main/java/org/sopt/app/presentation/mission/MissionResponse.java +++ b/src/main/java/org/sopt/app/presentation/mission/MissionResponse.java @@ -3,15 +3,17 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class MissionResponse { @Getter - @Setter - @ToString + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PUBLIC) public static class MissionMain { @Schema(description = "๋ฏธ์…˜ ์•„์ด๋””", example = "1") @@ -25,8 +27,8 @@ public static class MissionMain { } @Getter - @Setter - @ToString + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PUBLIC) public static class Completeness { @Schema(description = "๋ฏธ์…˜ ์•„์ด๋””", example = "1") @@ -42,8 +44,8 @@ public static class Completeness { } @Getter - @Setter - @ToString + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PUBLIC) public static class MissionId { @Schema(description = "๋ฏธ์…˜ ์•„์ด๋””", example = "1") diff --git a/src/main/java/org/sopt/app/presentation/notification/NotificationController.java b/src/main/java/org/sopt/app/presentation/notification/NotificationController.java index fb7c98cd..850d9e92 100644 --- a/src/main/java/org/sopt/app/presentation/notification/NotificationController.java +++ b/src/main/java/org/sopt/app/presentation/notification/NotificationController.java @@ -45,9 +45,9 @@ public ResponseEntity> findNotific @PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable ) { val result = notificationService.findNotificationList(user, pageable); - return ResponseEntity.status(HttpStatus.OK).body( + return ResponseEntity.ok( result.stream() - .map((notification) -> NotificationResponse.NotificationSimple.of( + .map(notification -> NotificationResponse.NotificationSimple.of( notification.getNotificationId() , notification.getUserId() , notification.getTitle() @@ -68,7 +68,7 @@ public ResponseEntity findNotificationD @PathVariable("notificationId") String notificationId ) { val result = notificationService.findNotification(user, notificationId); - return ResponseEntity.status(HttpStatus.OK).body( + return ResponseEntity.ok( NotificationResponse.NotificationDetail.of( result.getNotificationId(), result.getUserId(), @@ -82,7 +82,6 @@ public ResponseEntity findNotificationD ); } - @Operation(summary = "[External] ์•Œ๋ฆผ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์•Œ๋ฆผ ๋“ฑ๋ก") @ApiResponses({ @ApiResponse(responseCode = "200", description = "success"), @@ -94,7 +93,7 @@ public ResponseEntity registerNotification( ) { // TODO : AppUser ๊ฐ€ ์•„๋‹Œ ์™ธ๋ถ€ Client ๋กœ๋ถ€ํ„ฐ ์ธ์ฆ ์ ˆ์ฐจ ์—†์–ด๋„ ๋˜๋Š”์ง€ ๋…ผ์˜ (ex. x-api-key, spring security ๊ธฐ๋Šฅ ๋“ฑ) notificationService.registerNotification(registerNotificationRequest); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } @Operation(summary = "์•Œ๋ฆผ ์ฝ์Œ ์—ฌ๋ถ€ ๋ณ€๊ฒฝ") @@ -110,11 +109,9 @@ public ResponseEntity updateNotificationIsRead( @PathVariable(name = "notificationId", required = false) String notificationId ) { notificationService.updateNotificationIsRead(user, notificationId); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } - - @Operation(summary = "์•Œ๋ฆผ ๋ชฉ๋ก ์กฐํšŒ - DEPRECATED") @ApiResponses({ @ApiResponse(responseCode = "200", description = "success"), @@ -127,9 +124,9 @@ public ResponseEntity> f @PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable ) { val result = notificationService.findNotificationList(user, pageable); - return ResponseEntity.status(HttpStatus.OK).body( + return ResponseEntity.ok( result.stream() - .map((notification) -> NotificationResponse.NotificationSimpleDeprecated.of( + .map(notification -> NotificationResponse.NotificationSimpleDeprecated.of( notification.getId() , notification.getUserId() , notification.getTitle() @@ -151,7 +148,7 @@ public ResponseEntity findNot @PathVariable("notificationId") Long notificationId ) { val result = notificationService.findNotificationDeprecated(user, notificationId); - return ResponseEntity.status(HttpStatus.OK).body( + return ResponseEntity.ok( NotificationResponse.NotificationDetailDeprecated.of( result.getId(), result.getUserId(), @@ -179,6 +176,6 @@ public ResponseEntity updateNotificationIsReadDeprecated( @PathVariable(name = "notificationId", required = false) Long notificationId ) { notificationService.updateNotificationIsReadDeprecated(user, notificationId); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } } diff --git a/src/main/java/org/sopt/app/presentation/notification/NotificationRequest.java b/src/main/java/org/sopt/app/presentation/notification/NotificationRequest.java index da72c45d..83842f21 100644 --- a/src/main/java/org/sopt/app/presentation/notification/NotificationRequest.java +++ b/src/main/java/org/sopt/app/presentation/notification/NotificationRequest.java @@ -11,12 +11,12 @@ import java.util.List; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class NotificationRequest { @Getter - @Setter - @NoArgsConstructor - @ToString + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @AllArgsConstructor(access = AccessLevel.PUBLIC) public static class RegisterNotificationRequest { @Schema(description = "์•Œ๋ฆผ ๋Œ€์ƒ ์œ ์ € ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ID ๋ฆฌ์ŠคํŠธ", example = "['1', '2']") diff --git a/src/main/java/org/sopt/app/presentation/notification/PushTokenRequest.java b/src/main/java/org/sopt/app/presentation/notification/PushTokenRequest.java index 685e08b7..d18e23a2 100644 --- a/src/main/java/org/sopt/app/presentation/notification/PushTokenRequest.java +++ b/src/main/java/org/sopt/app/presentation/notification/PushTokenRequest.java @@ -6,12 +6,12 @@ import javax.validation.constraints.NotNull; import java.util.List; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class PushTokenRequest { @Getter - // Builder ๋กœ ํ•˜๋ฉด Jackson ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ž๋™ RequestBody Mapping์„ ๋ชปํ•ด์ค๋‹ˆ๋‹ค. - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class EditRequest { @Schema(description = "์ ‘์† ๊ธฐ๊ธฐ ํ”Œ๋žซํผ", example = "Android") @@ -24,8 +24,8 @@ public static class EditRequest { } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class DeleteRequest { @Schema(description = "์ ‘์† ๊ธฐ๊ธฐ ํ”Œ๋žซํผ", example = "Android") @@ -40,8 +40,7 @@ public static class DeleteRequest { @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) - @AllArgsConstructor(access = AccessLevel.PRIVATE) - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) public static class PushTokenManageRequest { @Schema(description = "์œ ์ € ์•„์ด๋””", example = "['1']") @@ -51,9 +50,5 @@ public static class PushTokenManageRequest { @Schema(description = "ํ‘ธ์‹œ ํ† ํฐ", example = "asdfasdf") @NotNull(message = "push token may not be null") private String deviceToken; - - public static PushTokenManageRequest of(List userIds, String deviceToken) { - return new PushTokenManageRequest(userIds, deviceToken); - } } } diff --git a/src/main/java/org/sopt/app/presentation/poke/PokeController.java b/src/main/java/org/sopt/app/presentation/poke/PokeController.java index 5e897e7a..7404a5e5 100644 --- a/src/main/java/org/sopt/app/presentation/poke/PokeController.java +++ b/src/main/java/org/sopt/app/presentation/poke/PokeController.java @@ -102,7 +102,7 @@ public ResponseEntity orderPoke( user.getId(), pokedUserId, messageRequest.getMessage(), messageRequest.getIsAnonymous() ); val response = pokeFacade.getPokeHistoryProfile(user, pokedUserId, pokeHistoryId); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์นœ๊ตฌ๋ฅผ ์ฐ”๋Ÿฌ๋ณด์„ธ์š” ์กฐํšŒ") diff --git a/src/main/java/org/sopt/app/presentation/rank/RankController.java b/src/main/java/org/sopt/app/presentation/rank/RankController.java index 3e9783ca..f1f87cdf 100644 --- a/src/main/java/org/sopt/app/presentation/rank/RankController.java +++ b/src/main/java/org/sopt/app/presentation/rank/RankController.java @@ -6,17 +6,12 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.val; -import org.sopt.app.application.mission.MissionService; +import org.sopt.app.facade.RankFacade; import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; -import org.sopt.app.application.soptamp.SoptampPointService; -import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.domain.enums.Part; -import org.springframework.http.HttpStatus; +import org.sopt.app.facade.SoptampFacade; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -30,10 +25,9 @@ @SecurityRequirement(name = "Authorization") public class RankController { - private final SoptampPointService soptampPointService; - private final SoptampUserService soptampUserService; + private final RankFacade rankFacade; + private final SoptampFacade soptampFacade; private final RankResponseMapper rankResponseMapper; - private final MissionService missionService; @Operation(summary = "๋žญํ‚น ๋ชฉ๋ก ์กฐํšŒ") @ApiResponses(value = { @@ -41,10 +35,9 @@ public class RankController { @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) @GetMapping("") - public ResponseEntity> findRanks() { - val result = soptampUserService.findRanks(); - val response = rankResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + public ResponseEntity> findAllRanks() { + val result = rankFacade.findAllSoptampUserRanks(); + return ResponseEntity.ok(rankResponseMapper.of(result)); } @Operation(summary = "ํ˜„์žฌ ๊ธฐ์ˆ˜ ๋žญํ‚น ๋ชฉ๋ก ์กฐํšŒ") @@ -54,10 +47,8 @@ public ResponseEntity> findRanks() { }) @GetMapping("/current") public ResponseEntity> findCurrentRanks() { - val soptampPointList = soptampPointService.findCurrentPointList(); - val result = soptampUserService.findCurrentRanks(soptampPointList); - val response = rankResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + val result = rankFacade.findCurrentRanks(); + return ResponseEntity.ok(rankResponseMapper.of(result)); } @Operation(summary = "ํŒŒํŠธ ๋ณ„ ํ˜„์žฌ ๊ธฐ์ˆ˜ ๋žญํ‚น ๋ชฉ๋ก ์กฐํšŒ") @@ -70,25 +61,21 @@ public ResponseEntity> findCurrentRanks() { public ResponseEntity> findCurrentRanksByPart( @PathVariable("part") Part part ) { - val soptampUserIdList = soptampUserService.findSoptampUserByPart(part); - val soptampPointList = soptampPointService.findCurrentPointListBySoptampUserIds(soptampUserIdList); - val result = soptampUserService.findCurrentRanks(soptampPointList); - val response = rankResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + val result = rankFacade.findCurrentRanksByPart(part); + return ResponseEntity.ok(rankResponseMapper.of(result)); } - @Operation(summary = "๋žญํ‚น ์ƒ์„ธ ์กฐํšŒ") + @Operation(summary = "์œ ์ € ๋ฏธ์…˜ ์ •๋ณด ์ƒ์„ธ ์กฐํšŒ") @ApiResponses({ @ApiResponse(responseCode = "200", description = "success"), @ApiResponse(responseCode = "400", description = "no user with the nickname", content = @Content), @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) @GetMapping("/detail") - public ResponseEntity findRankByNickname(@RequestParam(value = "nickname") String nickname) { - val result = soptampUserService.findRankByNickname(nickname); - val missionList = missionService.getCompleteMission(result.getUserId()); - val response = rankResponseMapper.of(result, missionList); - return ResponseEntity.status(HttpStatus.OK).body(response); + public ResponseEntity findSoptampUserAndCompletedMissionByNickname( + @RequestParam(value = "nickname") String nickname) { + + return ResponseEntity.ok(soptampFacade.findSoptampUserAndCompletedMissionByNickname(nickname)); } @Operation(summary = "ํŒŒํŠธ๋ผ๋ฆฌ์˜ ๋žญํ‚น ๋ชฉ๋ก ์กฐํšŒ") @@ -98,22 +85,7 @@ public ResponseEntity findRankByNickname(@RequestParam(valu }) @GetMapping("/part") public ResponseEntity> findPartRanks() { - List partList = List.of(Part.PLAN, Part.DESIGN, Part.WEB, Part.IOS, Part.ANDROID, Part.SERVER); - - Map partPoints = partList.stream() - .collect(Collectors.toMap( - Function.identity(), - part -> soptampPointService.calculateSumOfPoints( - soptampPointService.findCurrentPointListBySoptampUserIds( - soptampUserService.findSoptampUserByPart(part) - ) - ) - )); - return ResponseEntity.status(HttpStatus.OK).body( - partList.stream() - .map(soptampPointService.findPartRanks(partPoints)::get) - .toList() - ); + return ResponseEntity.ok((rankFacade.findAllPartRanks())); } } diff --git a/src/main/java/org/sopt/app/presentation/rank/RankResponse.java b/src/main/java/org/sopt/app/presentation/rank/RankResponse.java index e9c2f32f..5ced4ada 100644 --- a/src/main/java/org/sopt/app/presentation/rank/RankResponse.java +++ b/src/main/java/org/sopt/app/presentation/rank/RankResponse.java @@ -2,15 +2,17 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class RankResponse { @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class RankMain { @Schema(description = "์œ ์ € ๋žญํ‚น ์ˆœ์œ„", example = "1") @@ -24,8 +26,8 @@ public static class RankMain { } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class Detail { @Schema(description = "์œ ์ € ๋‹‰๋„ค์ž„", example = "๊น€์•ฑ์งฑ") @@ -37,8 +39,8 @@ public static class Detail { } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class RankMission { @Schema(description = "๋ฏธ์…˜ ์•„์ด๋””", example = "1") diff --git a/src/main/java/org/sopt/app/presentation/rank/RankResponseMapper.java b/src/main/java/org/sopt/app/presentation/rank/RankResponseMapper.java index c41ef621..45139c36 100644 --- a/src/main/java/org/sopt/app/presentation/rank/RankResponseMapper.java +++ b/src/main/java/org/sopt/app/presentation/rank/RankResponseMapper.java @@ -5,8 +5,8 @@ import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; import org.sopt.app.application.soptamp.SoptampPointInfo.Main; +import org.sopt.app.application.soptamp.SoptampUserInfo; import org.sopt.app.domain.entity.Mission; -import org.sopt.app.domain.entity.SoptampUser; @Mapper( componentModel = "spring", @@ -17,5 +17,5 @@ public interface RankResponseMapper { List of(List
rank); - RankResponse.Detail of(SoptampUser user, List userMissions); + RankResponse.Detail of(SoptampUserInfo user, List userMissions); } diff --git a/src/main/java/org/sopt/app/presentation/s3/S3Controller.java b/src/main/java/org/sopt/app/presentation/s3/S3Controller.java index 328170ad..9454a4e2 100644 --- a/src/main/java/org/sopt/app/presentation/s3/S3Controller.java +++ b/src/main/java/org/sopt/app/presentation/s3/S3Controller.java @@ -23,7 +23,6 @@ public class S3Controller { private final S3Service s3Service; private final S3ResponseMapper s3ResponseMapper; - private RestTemplate restTemplate = new RestTemplate(); @Operation(summary = "์Šคํƒฌํ”„ pre-signed url ์กฐํšŒ") @ApiResponses({ @@ -35,7 +34,7 @@ public class S3Controller { public ResponseEntity getStampPreSignedUrl() { val result = s3Service.getPreSignedUrl("stamp"); val response = s3ResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "๋ฏธ์…˜ pre-signed url ์กฐํšŒ") @@ -48,6 +47,6 @@ public ResponseEntity getStampPreSignedUrl() { public ResponseEntity getMissionPreSignedUrl() { val result = s3Service.getPreSignedUrl("mission"); val response = s3ResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } } diff --git a/src/main/java/org/sopt/app/presentation/s3/S3Response.java b/src/main/java/org/sopt/app/presentation/s3/S3Response.java index f1bdb175..1730f3e7 100644 --- a/src/main/java/org/sopt/app/presentation/s3/S3Response.java +++ b/src/main/java/org/sopt/app/presentation/s3/S3Response.java @@ -1,15 +1,17 @@ package org.sopt.app.presentation.s3; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class S3Response { @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class PreSignedUrl { @Schema(description = "Pre-Signed URL ์ฃผ์†Œ", example = "https://s3.ap-northeast-2.amazonaws.com/example/6d7cfc58-05a6-4a83-9112-725f3f95d4fd?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230412T155024Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3599&X-Amz-Credential=AKIAVQPX6FSLOVJS53KL%2F20230412%2Fap-northeast-2%2Fs3%2Faws4_request&X-Amz-Signature=123456123456") diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampController.java b/src/main/java/org/sopt/app/presentation/stamp/StampController.java index 61182a0f..30cc6e33 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampController.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampController.java @@ -51,7 +51,7 @@ public ResponseEntity findStampByMissionAndUserId( ) { val result = soptampFacade.getStampInfo(findStampRequest.getMissionId(), findStampRequest.getNickname()); val response = stampResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์Šคํƒฌํ”„ ์กฐํšŒํ•˜๊ธฐ - DEPRECATED") @@ -67,7 +67,7 @@ public ResponseEntity findStampByMissionAndUserIdDeprec ) { val result = stampService.findStamp(missionId, user.getId()); val response = stampResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์Šคํƒฌํ”„ ๋“ฑ๋กํ•˜๊ธฐ - DEPRECATED") @@ -81,7 +81,7 @@ public ResponseEntity registerStampDeprecated( ) { val result = soptampFacade.uploadStampDeprecated(user.getId(), missionId, registerStampRequest, multipartFiles); val response = stampResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์Šคํƒฌํ”„ ์ˆ˜์ •ํ•˜๊ธฐ - DEPRECATED") @@ -94,7 +94,7 @@ public ResponseEntity editStampDeprecated( ) { val stamp = soptampFacade.editStamp(editStampRequest, user.getId(), missionId, multipartFiles); val response = stampResponseMapper.of(stamp.getId()); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @@ -112,7 +112,7 @@ public ResponseEntity registerStamp( ) { val result = soptampFacade.uploadStamp(user.getId(), registerStampRequest); val response = stampResponseMapper.of(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์Šคํƒฌํ”„ ์ˆ˜์ •ํ•˜๊ธฐ") @@ -128,7 +128,7 @@ public ResponseEntity editStamp( ) { val stamp = stampService.editStampContents(editStampRequest, user.getId()); val response = stampResponseMapper.of(stamp.getId()); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์Šคํƒฌํ”„ ์‚ญ์ œํ•˜๊ธฐ(๊ฐœ๋ณ„)") @@ -138,12 +138,12 @@ public ResponseEntity editStamp( @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) @DeleteMapping("/{stampId}") - public ResponseEntity deleteStampById( + public ResponseEntity deleteStampById( @AuthenticationPrincipal User user, @PathVariable Long stampId ) { soptampFacade.deleteStamp(user.getId(), stampId); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } @Operation(summary = "์Šคํƒฌํ”„ ์‚ญ์ œํ•˜๊ธฐ(์ „์ฒด)") @@ -152,8 +152,8 @@ public ResponseEntity deleteStampById( @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) @DeleteMapping("/all") - public ResponseEntity deleteStampByUserId(@AuthenticationPrincipal User user) { + public ResponseEntity deleteStampByUserId(@AuthenticationPrincipal User user) { soptampFacade.deleteStampAll(user.getId()); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } } diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java b/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java index 7c45fd61..7ba41e05 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampRequest.java @@ -2,15 +2,17 @@ import io.swagger.v3.oas.annotations.media.Schema; import javax.validation.constraints.NotNull; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class StampRequest { @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class FindStampRequest { @Schema(description = "๋ฏธ์…˜ ์•„์ด๋””", example = "1") @@ -22,8 +24,8 @@ public static class FindStampRequest { } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class RegisterStampRequest { @Schema(description = "๋ฏธ์…˜ ์•„์ด๋””", example = "1") @@ -41,8 +43,8 @@ public static class RegisterStampRequest { } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class EditStampRequest { @Schema(description = "๋ฏธ์…˜ ์•„์ด๋””", example = "1") diff --git a/src/main/java/org/sopt/app/presentation/stamp/StampResponse.java b/src/main/java/org/sopt/app/presentation/stamp/StampResponse.java index c2042aef..842238c9 100644 --- a/src/main/java/org/sopt/app/presentation/stamp/StampResponse.java +++ b/src/main/java/org/sopt/app/presentation/stamp/StampResponse.java @@ -3,15 +3,17 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDateTime; import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class StampResponse { @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class StampMain { @Schema(description = "์Šคํƒฌํ”„ ์•„์ด๋””", example = "1") @@ -31,8 +33,8 @@ public static class StampMain { } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class StampId { @Schema(description = "์Šคํƒฌํ”„ ์•„์ด๋””", example = "1") 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 4e58eac5..0284561c 100644 --- a/src/main/java/org/sopt/app/presentation/user/UserController.java +++ b/src/main/java/org/sopt/app/presentation/user/UserController.java @@ -11,7 +11,6 @@ import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.domain.entity.User; import org.sopt.app.facade.SoptampFacade; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; @@ -39,7 +38,7 @@ public class UserController { @GetMapping(value = "") public ResponseEntity getUserInfo(@AuthenticationPrincipal User user) { val response = userResponseMapper.ofAppUser(user); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์†ํƒฌํ”„ ์ •๋ณด ์กฐํšŒ") @@ -55,7 +54,7 @@ public ResponseEntity getSoptampInfo(@AuthenticationPrinci .profileMessage(soptampUser.getProfileMessage()) .points(soptampUser.getTotalPoints()) .build(); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "๋‹‰๋„ค์ž„ ์ค‘๋ณต ๊ฒ€์‚ฌ") @@ -67,7 +66,7 @@ public ResponseEntity getSoptampInfo(@AuthenticationPrinci @GetMapping(value = "/nickname/{nickname}") public ResponseEntity validateUserNickname(@PathVariable String nickname) { soptampUserService.checkUserNickname(nickname); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } @Operation(summary = "๋‹‰๋„ค์ž„ ๋ณ€๊ฒฝ") @@ -84,7 +83,7 @@ public ResponseEntity editNickname( val response = UserResponse.Nickname.builder() .nickname(result.getNickname()) .build(); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "ํ•œ๋งˆ๋”” ๋ณ€๊ฒฝ") @@ -101,7 +100,7 @@ public ResponseEntity editProfileMessage( val response = UserResponse.ProfileMessage.builder() .profileMessage(result.getProfileMessage()) .build(); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } } diff --git a/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java b/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java index 4d39e803..ab2e93cc 100644 --- a/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java +++ b/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java @@ -9,6 +9,7 @@ import lombok.RequiredArgsConstructor; import lombok.val; import org.sopt.app.application.auth.PlaygroundAuthService; +import org.sopt.app.application.auth.dto.PlaygroundPostInfo.PlaygroundPost; import org.sopt.app.domain.entity.User; import org.sopt.app.facade.UserFacade; import org.sopt.app.presentation.user.UserResponse.AppService; @@ -41,7 +42,7 @@ public ResponseEntity getMainViewInfo( @AuthenticationPrincipal User user ) { val response = userFacade.getMainViewInfo(user); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์œ ์ € ๊ธฐ์ˆ˜ ์ •๋ณด ์กฐํšŒ") @@ -57,7 +58,7 @@ public ResponseEntity getGenerationInfo( val generationUser = playgroundAuthService.getPlaygroundUserActiveInfo( user.getPlaygroundToken(), user.getPlaygroundId()); val response = userResponseMapper.ofGeneration(generationUser); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "์•ฑ ์„œ๋น„์Šค ์กฐํšŒ") @@ -69,6 +70,19 @@ public ResponseEntity getGenerationInfo( @GetMapping(value = "/app-service") public ResponseEntity> getAppServiceInfo() { val response = userFacade.getAppServiceInfo(); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); + } + + @Operation(summary = "ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ์ธ๊ธฐ ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success"), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @GetMapping(value = "/playground/hot-post") + public ResponseEntity getPlaygroundHotPost( + @AuthenticationPrincipal User user + ) { + val response = playgroundAuthService.getPlaygroundHotPost(user.getPlaygroundToken()); + return ResponseEntity.ok(response); } } diff --git a/src/main/java/org/sopt/app/presentation/user/UserPushTokenController.java b/src/main/java/org/sopt/app/presentation/user/UserPushTokenController.java index fd22cf3a..3a7d5ad7 100644 --- a/src/main/java/org/sopt/app/presentation/user/UserPushTokenController.java +++ b/src/main/java/org/sopt/app/presentation/user/UserPushTokenController.java @@ -43,7 +43,7 @@ public ResponseEntity updatePushToken( pushTokenRequest.getPlatform() ); val response = pushTokenResponseMapper.ofStatus(result); - return ResponseEntity.status(HttpStatus.OK).body(response); + return ResponseEntity.ok(response); } @Operation(summary = "ํ‘ธ์‹œ ํ† ํฐ ํ•ด์ œ") @@ -62,7 +62,7 @@ public ResponseEntity deletePushToken( ); pushTokenService.deleteDeviceToken(targetPushToken); } - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } } diff --git a/src/main/java/org/sopt/app/presentation/user/UserRequest.java b/src/main/java/org/sopt/app/presentation/user/UserRequest.java index e04bdcc8..709652b3 100644 --- a/src/main/java/org/sopt/app/presentation/user/UserRequest.java +++ b/src/main/java/org/sopt/app/presentation/user/UserRequest.java @@ -2,17 +2,19 @@ import io.swagger.v3.oas.annotations.media.Schema; import javax.validation.constraints.NotNull; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; import java.util.List; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class UserRequest { @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class EditNicknameRequest { @Schema(description = "๋‹‰๋„ค์ž„", example = "๊น€์•ฑ์งฑ") @@ -21,8 +23,8 @@ public static class EditNicknameRequest { } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class EditProfileMessageRequest { @Schema(description = "ํ•œ๋งˆ๋””", example = "1๋“ฑ์ด ๋˜๊ณ  ๋ง๊ฑฐ์•ผ!") @@ -32,8 +34,8 @@ public static class EditProfileMessageRequest { @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class EditIsOptInRequest { @Schema(description = "ํ‘ธ์‹œ ์•Œ๋ฆผ ์ˆ˜์‹  ๋™์˜", example = "false") @@ -42,8 +44,8 @@ public static class EditIsOptInRequest { } @Getter - @Setter - @ToString + @AllArgsConstructor(access = AccessLevel.PUBLIC) + @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class MemberProfilesRequest { @Schema(description = "ํ”„๋กœํ•„ ์กฐํšŒ ๋Œ€์ƒ ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ID ๋ฆฌ์ŠคํŠธ", example = "[115, 106]") diff --git a/src/main/java/org/sopt/app/presentation/user/UserResponseMapper.java b/src/main/java/org/sopt/app/presentation/user/UserResponseMapper.java index bb98cdc9..07a70977 100644 --- a/src/main/java/org/sopt/app/presentation/user/UserResponseMapper.java +++ b/src/main/java/org/sopt/app/presentation/user/UserResponseMapper.java @@ -4,9 +4,9 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; -import org.sopt.app.application.auth.PlaygroundAuthInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo; import org.sopt.app.application.operation.OperationInfo; -import org.sopt.app.application.service.AppServiceInfo; +import org.sopt.app.application.app_service.AppServiceInfo; import org.sopt.app.application.user.UserInfo; import org.sopt.app.domain.entity.User; import org.sopt.app.presentation.user.UserResponse.AppService; @@ -20,14 +20,14 @@ public interface UserResponseMapper { UserResponse.AppUser ofAppUser(User user); - UserResponse.MainView ofMainView(PlaygroundAuthInfo.MainView user, OperationInfo.MainView operation, + UserResponse.MainView ofMainView(PlaygroundProfileInfo.MainView user, OperationInfo.MainView operation, Boolean isAllConfirm); UserResponse.Nickname of(UserInfo.Nickname nickname); UserResponse.ProfileMessage of(UserInfo.ProfileMessage profileMessage); - UserResponse.Generation ofGeneration(PlaygroundAuthInfo.UserActiveInfo userActiveInfo); + UserResponse.Generation ofGeneration(PlaygroundProfileInfo.UserActiveInfo userActiveInfo); List ofAppServiceList(List appServiceList); } diff --git a/src/main/java/org/sopt/app/presentation/user/UserWithdrawController.java b/src/main/java/org/sopt/app/presentation/user/UserWithdrawController.java index 39ff9a48..fad9f199 100644 --- a/src/main/java/org/sopt/app/presentation/user/UserWithdrawController.java +++ b/src/main/java/org/sopt/app/presentation/user/UserWithdrawController.java @@ -47,7 +47,7 @@ public ResponseEntity logout( ); pushTokenService.deleteDeviceToken(targetPushToken); } - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } @Operation(summary = "ํƒˆํ‡ดํ•˜๊ธฐ") @@ -65,6 +65,6 @@ public ResponseEntity withdraw(@AuthenticationPrincipal Us pushTokenService.deleteAllDeviceTokenOf(user); // ์œ ์ € ์ •๋ณด ์‚ญ์ œ userService.deleteUser(user); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.ok().build(); } } \ No newline at end of file diff --git a/src/test/java/org/sopt/app/application/FriendServiceTest.java b/src/test/java/org/sopt/app/application/FriendServiceTest.java index 9551b282..fda868fb 100644 --- a/src/test/java/org/sopt/app/application/FriendServiceTest.java +++ b/src/test/java/org/sopt/app/application/FriendServiceTest.java @@ -12,7 +12,7 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.sopt.app.application.poke.FriendService; -import org.sopt.app.interfaces.postgres.FriendRepository; +import org.sopt.app.interfaces.postgres.friend.FriendRepository; @ExtendWith(MockitoExtension.class) class FriendServiceTest { diff --git a/src/test/java/org/sopt/app/application/MissionServiceTest.java b/src/test/java/org/sopt/app/application/MissionServiceTest.java index fd338733..2ba34f5a 100644 --- a/src/test/java/org/sopt/app/application/MissionServiceTest.java +++ b/src/test/java/org/sopt/app/application/MissionServiceTest.java @@ -72,10 +72,7 @@ void SUCCESS_findAllMission() { @DisplayName("SUCCESS_๋ฏธ์…˜ ์—…๋กœ๋“œ") void SUCCESS_uploadMission() { // given - RegisterMissionRequest registerMissionRequest = new RegisterMissionRequest(); - registerMissionRequest.setTitle("title"); - registerMissionRequest.setLevel(1); - registerMissionRequest.setImage("image"); + RegisterMissionRequest registerMissionRequest = new RegisterMissionRequest("image", "title", 1); // when Mission expected = Mission.builder() diff --git a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java index 365d9c12..9651a813 100644 --- a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java +++ b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java @@ -4,14 +4,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; import static org.sopt.app.common.fixtures.PokeFixture.GENERATION; import static org.sopt.app.common.fixtures.PokeFixture.MBTI; import static org.sopt.app.common.fixtures.PokeFixture.UNIVERSITY; -import static org.sopt.app.common.fixtures.PokeFixture.createSameMbtiPlaygroundProfileOfRecommendedFriend; -import static org.sopt.app.common.fixtures.PokeFixture.createSameUniversityPlaygroundProfileOfRecommendedFriend; import io.jsonwebtoken.ExpiredJwtException; import java.util.List; @@ -22,21 +19,17 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.sopt.app.application.auth.PlaygroundAuthInfo; -import org.sopt.app.application.auth.PlaygroundAuthInfo.ActiveUserIds; -import org.sopt.app.application.auth.PlaygroundAuthInfo.MainView; -import org.sopt.app.application.auth.PlaygroundAuthInfo.MainViewUser; -import org.sopt.app.application.auth.PlaygroundAuthInfo.OwnPlaygroundProfile; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundMain; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfile; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfileOfRecommendedFriend; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfileOfRecommendedFriendList; -import org.sopt.app.application.auth.PlaygroundAuthInfo.ActivityCardinalInfo; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundUserIds; -import org.sopt.app.application.auth.PlaygroundAuthInfo.RecommendFriendRequest; -import org.sopt.app.application.auth.PlaygroundAuthInfo.RefreshedToken; -import org.sopt.app.application.auth.PlaygroundAuthInfo.UserActiveInfo; +import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.RefreshedToken; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.ActiveUserIds; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.MainView; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.MainViewUser; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundMain; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundProfile; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.ActivityCardinalInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.UserActiveInfo; import org.sopt.app.application.auth.PlaygroundAuthService; +import org.sopt.app.application.auth.dto.RecommendedFriendInfo.PlaygroundUserIds; import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.common.exception.UnauthorizedException; import org.sopt.app.domain.enums.UserStatus; @@ -62,9 +55,8 @@ class PlaygroundAuthServiceTest { @DisplayName("SUCCESS_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ์ •๋ณด ์กฐํšŒ") void SUCCESS_getPlaygroundInfo() { // given - String token = "token"; ActivityCardinalInfo activityCardinalInfo = new ActivityCardinalInfo("29,์„œ๋ฒ„"); - PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder() + PlaygroundProfileInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder() .activities(List.of(activityCardinalInfo)) .profileImage("profileImage") .name("name") @@ -102,10 +94,8 @@ void FAIL_getPlaygroundInfoExpiredJwtUnauthorizedException() { @Test @DisplayName("SUCCESS_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ์–ด์„ธ์Šค ํ† ํฐ ๋ฐœ๊ธ‰") void SUCCESS_getPlaygroundAccessToken() { - CodeRequest codeRequest = new CodeRequest(); - codeRequest.setCode("code"); - AccessTokenRequest accessTokenRequest = new AccessTokenRequest(); - accessTokenRequest.setAccessToken("accessToken"); + CodeRequest codeRequest = new CodeRequest("code"); + AccessTokenRequest accessTokenRequest = new AccessTokenRequest("accessToken"); when(playgroundClient.getAccessToken(any(), any())).thenReturn(accessTokenRequest); @@ -116,7 +106,7 @@ void SUCCESS_getPlaygroundAccessToken() { @Test @DisplayName("FAIL_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ์–ด์„ธ์Šค ํ† ํฐ ๋ฐœ๊ธ‰ BadRequestException") void FAIL_getPlaygroundAccessTokenBadRequestException() { - CodeRequest codeRequest = new CodeRequest(); + CodeRequest codeRequest = new CodeRequest("code"); when(playgroundClient.getAccessToken(any(), any())).thenThrow(BadRequest.class); @@ -128,8 +118,7 @@ void FAIL_getPlaygroundAccessTokenBadRequestException() { @Test @DisplayName("SUCCESS_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ํ† ํฐ ๋ฆฌํ”„๋ ˆ์‹œ") void SUCCESS_refreshPlaygroundToken() { - AccessTokenRequest accessTokenRequest = new AccessTokenRequest(); - accessTokenRequest.setAccessToken("accessToken"); + AccessTokenRequest accessTokenRequest = new AccessTokenRequest("accessToken"); RefreshedToken refreshedToken = RefreshedToken.builder().accessToken("refreshedToken").build(); when(playgroundClient.refreshPlaygroundToken(any(), any())).thenReturn(refreshedToken); @@ -141,7 +130,7 @@ void SUCCESS_refreshPlaygroundToken() { @Test @DisplayName("FAIL_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ํ† ํฐ ๋ฆฌํ”„๋ ˆ์‹œ UnauthorizedException") void FAIL_refreshPlaygroundTokenUnauthorizedException() { - AccessTokenRequest accessTokenRequest = new AccessTokenRequest(); + AccessTokenRequest accessTokenRequest = new AccessTokenRequest("accessToken"); when(playgroundClient.refreshPlaygroundToken(any(), any())).thenThrow(BadRequest.class); @@ -152,7 +141,7 @@ void FAIL_refreshPlaygroundTokenUnauthorizedException() { @Test @DisplayName("FAIL_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ํ† ํฐ ๋ฆฌํ”„๋ ˆ์‹œ UnauthorizedException") void FAIL_refreshPlaygroundTokenExpiredJwtUnauthorizedException() { - AccessTokenRequest accessTokenRequest = new AccessTokenRequest(); + AccessTokenRequest accessTokenRequest = new AccessTokenRequest("accessToken"); when(playgroundClient.refreshPlaygroundToken(any(), any())).thenThrow(ExpiredJwtException.class); @@ -165,37 +154,39 @@ void FAIL_refreshPlaygroundTokenExpiredJwtUnauthorizedException() { @DisplayName("SUCCESS_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ์ด๋ฏธ์ง€ ์žˆ๋Š” ์œ ์ € ๋ฉ”์ธ ๋ทฐ ์กฐํšŒ") void SUCCESS_getPlaygroundUserForMainViewWithProfileImage() { ActivityCardinalInfo activityCardinalInfo = new ActivityCardinalInfo("29,์„œ๋ฒ„"); - PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder() + PlaygroundProfileInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder() .activities(List.of(activityCardinalInfo)) .profileImage("profileImage") .name("name") .build(); MainViewUser mainViewUser = MainViewUser.builder().name("name").profileImage("profileImage").build(); - MainView mainView = MainView.builder().user(mainViewUser).build(); + MainView mainView = new MainView(mainViewUser); when(playgroundClient.getSinglePlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); MainView result = playgroundAuthService.getPlaygroundUserForMainView(token, 1L); - assertEquals(mainView.getUser().getName(), result.getUser().getName()); + assertEquals(mainView.user().getName(), result.user().getName()); } @Test @DisplayName("SUCCESS_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ์ด๋ฏธ์ง€ ์—†๋Š” ์œ ์ € ๋ฉ”์ธ ๋ทฐ ์กฐํšŒ") void SUCCESS_getPlaygroundUserForMainViewWithoutProfileImage() { ActivityCardinalInfo activityCardinalInfo = new ActivityCardinalInfo("1,์„œ๋ฒ„"); - PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder() + PlaygroundProfileInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder() .activities(List.of(activityCardinalInfo)) .profileImage(null) .name("name") .build(); - MainViewUser mainViewUser = MainViewUser.builder().name("name").profileImage("").build(); - MainView mainView = MainView.builder().user(mainViewUser).build(); + MainView mainView = new MainView(MainViewUser.builder() + .name("name") + .profileImage("") + .generationList(List.of(1L)) + .build()); when(playgroundClient.getSinglePlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); MainView result = playgroundAuthService.getPlaygroundUserForMainView(token, 1L); - assertEquals(mainView.getUser().getName(), result.getUser().getName()); - assertEquals(mainView.getUser().getProfileImage(), result.getUser().getProfileImage()); + assertEquals(mainView.user().getName(), result.user().getName()); } // getPlaygroundUserActiveInfo @@ -204,7 +195,7 @@ void SUCCESS_getPlaygroundUserForMainViewWithoutProfileImage() { void SUCCESS_getPlaygroundUserActiveInfoActive() { // given ActivityCardinalInfo activityCardinalInfo = new ActivityCardinalInfo("1,์„œ๋ฒ„"); - PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = + PlaygroundProfileInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder().activities(List.of(activityCardinalInfo)).build(); ReflectionTestUtils.setField(playgroundAuthService, "currentGeneration", 1L); @@ -213,30 +204,30 @@ void SUCCESS_getPlaygroundUserActiveInfoActive() { UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); // then - assertEquals(UserStatus.ACTIVE, result.getStatus()); + assertEquals(UserStatus.ACTIVE, result.status()); } @Test @DisplayName("SUCCESS_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ๋น„ํ™œ๋™ ์œ ์ € ํ™œ๋™ ์ •๋ณด ์กฐํšŒ") void SUCCESS_getPlaygroundUserActiveInfoInactive() { - PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder().activities(List.of()).build(); + PlaygroundProfileInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder().activities(List.of()).build(); when(playgroundClient.getSinglePlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); - assertEquals(UserStatus.INACTIVE, result.getStatus()); + assertEquals(UserStatus.INACTIVE, result.status()); } @Test @DisplayName("SUCCESS_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ์— ํ‹ฐ ์œ ์ € ํ™œ๋™ ์ •๋ณด ์กฐํšŒ") void SUCCESS_getPlaygroundUserActiveInfoEmptyList() { - PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = + PlaygroundProfileInfo.PlaygroundProfile playgroundProfile = PlaygroundProfile.builder().activities(List.of()).build(); when(playgroundClient.getSinglePlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); - assertEquals(UserStatus.INACTIVE, result.getStatus()); + assertEquals(UserStatus.INACTIVE, result.status()); } @Test @@ -261,13 +252,13 @@ void FAIL_getPlaygroundUserActiveInfoExpiredJwtUnauthorizedException() { @Test @DisplayName("SUCCESS_ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ์œ ์ € ์•„์ด๋”” ์กฐํšŒ") void SUCCESS_getPlayGroundUserIds() { - PlaygroundAuthInfo.ActiveUserIds userIds = ActiveUserIds.builder().userIds(List.of(1L)).build(); + PlaygroundProfileInfo.ActiveUserIds userIds = new ActiveUserIds(List.of(1L)); when(playgroundClient.getPlaygroundUserIds(any(), any())).thenReturn(userIds); ActiveUserIds result = playgroundAuthService.getPlayGroundUserIds(token); - assertEquals(1, result.getUserIds().size()); - assertEquals(1L, result.getUserIds().get(0)); + assertEquals(1, result.userIds().size()); + assertEquals(1L, result.userIds().get(0)); } @Test @@ -325,7 +316,6 @@ void FAIL_getPlaygroundMemberProfilesExpiredJwtUnauthorizedException() { @DisplayName("SUCCESS_์ž์‹ ์˜ ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ํ”„๋กœํ•„ ์กฐํšŒ") void SUCCESS_getOwnPlaygroundProfile() { // given & when - given(playgroundClient.getOwnPlaygroundProfile(any())).willReturn(new OwnPlaygroundProfile()); // then assertDoesNotThrow(() -> playgroundAuthService.getOwnPlaygroundProfile(token)); @@ -337,7 +327,7 @@ void SUCCESS_getPlaygroundIdsForSameGeneration() { // given & when given(playgroundClient.getPlaygroundUserIdsForSameRecommendType(any(), any())) - .willReturn(PlaygroundUserIds.builder().build()); + .willReturn(new PlaygroundUserIds(List.of())); // then assertDoesNotThrow(() -> playgroundAuthService.getPlaygroundIdsForSameGeneration(List.of(GENERATION))); @@ -348,7 +338,7 @@ void SUCCESS_getPlaygroundIdsForSameGeneration() { void SUCCESS_getPlaygroundProfilesForSameMbtiAndGeneration() { // given & when given(playgroundClient.getPlaygroundUserIdsForSameRecommendType(any(), any())) - .willReturn(PlaygroundUserIds.builder().build()); + .willReturn(new PlaygroundUserIds(List.of())); // then assertDoesNotThrow(() -> playgroundAuthService.getPlaygroundIdsForSameMbti(GENERATION, MBTI)); @@ -359,7 +349,7 @@ void SUCCESS_getPlaygroundProfilesForSameMbtiAndGeneration() { void SUCCESS_getPlaygroundProfilesForSameUniversityAndGeneration() { // given & when given(playgroundClient.getPlaygroundUserIdsForSameRecommendType(any(), any())) - .willReturn(PlaygroundUserIds.builder().build()); + .willReturn(new PlaygroundUserIds(List.of())); // then assertDoesNotThrow(() -> playgroundAuthService.getPlaygroundIdsForSameUniversity(GENERATION, UNIVERSITY)); diff --git a/src/test/java/org/sopt/app/application/PokeHistoryServiceTest.java b/src/test/java/org/sopt/app/application/PokeHistoryServiceTest.java index a26d44ee..d5aa7efd 100644 --- a/src/test/java/org/sopt/app/application/PokeHistoryServiceTest.java +++ b/src/test/java/org/sopt/app/application/PokeHistoryServiceTest.java @@ -100,7 +100,7 @@ void SUCCESS_getAllLatestPokeHistoryFromTo() { void SUCCESS_getAllLatestPokeHistoryIn() { PokeHistory pokeHistory = PokeHistory.builder().id(1L).pokerId(2L).pokedId(1L).message("message").isReply(false) .build(); - Page pokeHistoryPage = new PageImpl<>(List.of(pokeHistory)); + Page pokeHistoryPage = new PageImpl<>(List.of(pokeHistory)); Pageable pageable = Pageable.ofSize(1); when(pokeHistoryRepository.findAllByIdIsInOrderByCreatedAtDesc(any(), any())).thenReturn(pokeHistoryPage); diff --git a/src/test/java/org/sopt/app/application/SlackServiceTest.java b/src/test/java/org/sopt/app/application/SlackServiceTest.java new file mode 100644 index 00000000..7984b764 --- /dev/null +++ b/src/test/java/org/sopt/app/application/SlackServiceTest.java @@ -0,0 +1,16 @@ +package org.sopt.app.application; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.sopt.app.application.slack.SlackService; + +class SlackServiceTest { + + @Test + @DisplayName("SUCCESS_์Šฌ๋ž™ ๋ฉ”์‹œ์ง€ ๋ณด๋‚ด๊ธฐ") + void SUCCESS_sendSlackMessage() { + assertDoesNotThrow(() -> SlackService.sendSlackMessage("title","message")); + } +} diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java index b9611dd5..f5dfbec5 100644 --- a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -7,7 +7,6 @@ import static org.mockito.Mockito.when; import java.util.List; -import java.util.Map; import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -17,13 +16,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; import org.sopt.app.application.soptamp.SoptampPointInfo.Point; import org.sopt.app.application.soptamp.SoptampPointService; import org.sopt.app.domain.entity.SoptampPoint; -import org.sopt.app.domain.enums.Part; import org.sopt.app.domain.enums.UserStatus; -import org.sopt.app.interfaces.postgres.SoptampPointRepository; +import org.sopt.app.interfaces.postgres.soptamp_point.SoptampPointRepository; import org.springframework.test.util.ReflectionTestUtils; @ExtendWith(MockitoExtension.class) @@ -42,7 +39,7 @@ void setUp() { @Test @DisplayName("SUCCESS_ํ˜„์žฌ ํฌ์ธํŠธ ๋ฆฌ์ŠคํŠธ ์ฐพ๊ธฐ") - void SUCCESS_findCurrentPointList() { + void SUCCESS_findCurrentGenerationPoints() { //given final Long anyGeneration = anyLong(); @@ -64,7 +61,7 @@ void SUCCESS_findCurrentPointList() { //when when(soptampPointRepository.findAllByGeneration(anyGeneration)).thenReturn(soptampPointList); - List result = soptampPointService.findCurrentPointList(); + List result = soptampPointService.findCurrentGenerationPoints(); List expected = List.of( Point.builder() .id(1L) @@ -88,7 +85,7 @@ void SUCCESS_findCurrentPointList() { @Test @DisplayName("SUCCESS_์œ ์ € ์•„์ด๋”” ๋ฆฌ์ŠคํŠธ๋กœ ํ˜„์žฌ ํฌ์ธํŠธ ๋ฆฌ์ŠคํŠธ ์ฐพ๊ธฐ") - void SUCCESS_findCurrentPointListBySoptampUserIds() { + void SUCCESS_findCurrentGenerationPointsBySoptampUserIds() { //given List soptampUserIdList = any(); Long anyGeneration = anyLong(); @@ -218,76 +215,4 @@ void SUCCESS_upsertSoptampPointNotPresent() { //then Assertions.assertDoesNotThrow(() -> soptampPointService.upsertSoptampPoint(UserStatus.ACTIVE, 1L)); } - - @Test - @DisplayName("SUCCESS_ํŒŒํŠธ ๋žญํ‚น ์ฐพ๊ธฐ") - void SUCCESS_findPartRanks() { - //given - Map partPoints = Map.of( - Part.PLAN, 50L, - Part.DESIGN, 0L, - Part.IOS, 20L, - Part.ANDROID, 10L, - Part.WEB, 30L, - Part.SERVER, 40L - ); - - //when - Map result = soptampPointService.findPartRanks(partPoints); - Map expected = Map.of( - Part.PLAN, PartRank.builder() - .part(Part.PLAN.getPartName()) - .rank(1) - .points(50L) - .build(), - Part.DESIGN, PartRank.builder() - .part(Part.DESIGN.getPartName()) - .rank(6) - .points(0L) - .build(), - Part.IOS, PartRank.builder() - .part(Part.IOS.getPartName()) - .rank(4) - .points(20L) - .build(), - Part.ANDROID, PartRank.builder() - .part(Part.ANDROID.getPartName()) - .rank(5) - .points(10L) - .build(), - Part.WEB, PartRank.builder() - .part(Part.WEB.getPartName()) - .rank(3) - .points(30L) - .build(), - Part.SERVER, PartRank.builder() - .part(Part.SERVER.getPartName()) - .rank(2) - .points(40L) - .build() - ); - - //then - assertThat(result).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - @DisplayName("SUCCESS_ํŒŒํŠธ ๋žญํ‚น ๊ณ„์‚ฐ") - void SUCCESS_calculateSumOfPoints() { - //given - List soptampPointList = List.of( - Point.builder() - .points(100L) - .build(), - Point.builder() - .points(200L) - .build() - ); - - //when - Long result = soptampPointService.calculateSumOfPoints(soptampPointList); - - //then - assertThat(result).isEqualTo(300L); - } } \ No newline at end of file diff --git a/src/test/java/org/sopt/app/application/SoptampUserServiceTest.java b/src/test/java/org/sopt/app/application/SoptampUserServiceTest.java index bdb830fe..ab65547f 100644 --- a/src/test/java/org/sopt/app/application/SoptampUserServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampUserServiceTest.java @@ -4,11 +4,10 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; +import static org.sopt.app.common.fixtures.SoptampUserFixture.SOPTAMP_USER_1; -import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -17,8 +16,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.sopt.app.application.soptamp.SoptampPointInfo.Main; -import org.sopt.app.application.soptamp.SoptampPointInfo.Point; import org.sopt.app.application.soptamp.SoptampUserInfo; import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.common.exception.BadRequestException; @@ -53,7 +50,7 @@ void SUCCESS_getSoptampUserInfo() { .build()); //when - SoptampUserInfo.SoptampUser expected = SoptampUserInfo.SoptampUser.builder() + SoptampUserInfo expected = SoptampUserInfo.builder() .id(id) .userId(anyUserId) .profileMessage(profileMessage) @@ -62,7 +59,7 @@ void SUCCESS_getSoptampUserInfo() { .build(); Mockito.when(soptampUserRepository.findByUserId(anyUserId)).thenReturn(soptampUser); - SoptampUserInfo.SoptampUser result = soptampUserService.getSoptampUserInfo(anyUserId); + SoptampUserInfo result = soptampUserService.getSoptampUserInfo(anyUserId); //then assertThat(result).usingRecursiveComparison().isEqualTo(expected); @@ -118,7 +115,7 @@ void FAIL_checkUserNickname() { void SUCCESS_editNickname() { //given final String newNickname = "newNickname"; - SoptampUserInfo.SoptampUser soptampUser = SoptampUserInfo.SoptampUser.builder() + SoptampUserInfo soptampUser = SoptampUserInfo.builder() .nickname("oldNickname") .build(); @@ -131,14 +128,28 @@ void SUCCESS_editNickname() { void SUCCESS_editProfileMessage() { //given final String newProfileMessage = "newProfileMessage"; - SoptampUserInfo.SoptampUser soptampUser = SoptampUserInfo.SoptampUser.builder() - .nickname("oldProfileMessage") + final SoptampUser editedSoptampUser = SoptampUser.builder() + .id(SOPTAMP_USER_1.getId()) + .userId(SOPTAMP_USER_1.getUserId()) + .nickname(SOPTAMP_USER_1.getNickname()) + .totalPoints(SOPTAMP_USER_1.getTotalPoints()) + .profileMessage(newProfileMessage) .build(); + final SoptampUserInfo editedSoptampUserInfo = SoptampUserInfo.builder() + .id(SOPTAMP_USER_1.getId()) + .userId(SOPTAMP_USER_1.getUserId()) + .nickname(SOPTAMP_USER_1.getNickname()) + .totalPoints(SOPTAMP_USER_1.getTotalPoints()) + .profileMessage(newProfileMessage) + .build(); + given(soptampUserRepository.save(any(SoptampUser.class))).willReturn(editedSoptampUser); + + // when + String result = soptampUserService.editProfileMessage(editedSoptampUserInfo, newProfileMessage) + .getProfileMessage(); //then - Assertions.assertEquals( - soptampUserService.editProfileMessage(soptampUser, newProfileMessage).getProfileMessage(), - newProfileMessage); + Assertions.assertEquals(newProfileMessage, result); } @Test @@ -182,88 +193,9 @@ void FAIL_updateSoptampUser() { Assertions.assertEquals(soptampUserService.updateSoptampUser(newNickname, anyUserId), id); } - @Test - @DisplayName("SUCCESS_์†ํƒฌํ”„ ์œ ์ € ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฐ›์•„ ๋žญํฌ ์กฐํšŒ") - void SUCCESS_findRanks() { - //given - final SoptampUser soptampUser1 = SoptampUser.builder().nickname("1stUser").totalPoints(100L).build(); - final SoptampUser soptampUser2 = SoptampUser.builder().nickname("2stUser").totalPoints(200L).build(); - final SoptampUser soptampUser3 = SoptampUser.builder().nickname("3stUser").totalPoints(300L).build(); - final List soptampUserList = List.of(soptampUser1, soptampUser2, soptampUser3); - - //when - List
expected = List.of( - Main.builder().rank(1).point(300L).nickname("3stUser").build(), - Main.builder().rank(2).point(200L).nickname("2stUser").build(), - Main.builder().rank(3).point(100L).nickname("1stUser").build() - ); - - Mockito.when(soptampUserRepository.findAll()).thenReturn(soptampUserList); - List
result = soptampUserService.findRanks(); - - //then - assertThat(result).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - @DisplayName("SUCCESS_์†ํƒฌํ”„ ํฌ์ธํŠธ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฐ›์•„ ๋žญํฌ๋ฅผ ์กฐํšŒ") - void SUCCESS_findCurrentRanks() { - //given - List soptampPointList = Stream.of( - Point.of(1L, 1L, 1L, 100L), - Point.of(2L, 1L, 2L, 200L), - Point.of(3L, 1L, 3L, 300L) - ).collect(Collectors.toList()); - - List soptampUserIdList = soptampPointList.stream() - .map(Point::getSoptampUserId).toList(); - - //when - List
expected = List.of( - Main.builder().rank(1).point(300L).build(), - Main.builder().rank(2).point(200L).build(), - Main.builder().rank(3).point(100L).build() - ); - - Mockito.when(soptampUserRepository.findAllById(soptampUserIdList)).thenReturn( - List.of( - SoptampUser.builder().id(1L).build(), - SoptampUser.builder().id(2L).build(), - SoptampUser.builder().id(3L).build() - )); - List
result = soptampUserService.findCurrentRanks(soptampPointList); - - //then - assertThat(result).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - @DisplayName("FAIL_์†ํƒฌํ”„ ํฌ์ธํŠธ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฐ›์•˜์„ ๋•Œ ์œ ์ €๋ฅผ ์ฐพ์ง€ ๋ชปํ•˜๋ฉด BadRequestException ๋ฐœ์ƒ") - void FAIL_findCurrentRanks() { - //given - List soptampPointList = Stream.of( - Point.of(1L, 1L, 1L, 100L), - Point.of(2L, 1L, 2L, 200L), - Point.of(3L, 1L, 3L, 300L) - ).collect(Collectors.toList()); - - List soptampUserIdList = soptampPointList.stream() - .map(Point::getSoptampUserId).toList(); - - //when - - Mockito.when(soptampUserRepository.findAllById(soptampUserIdList)).thenReturn(List.of()); - - //then - Assertions.assertThrows(BadRequestException.class, () -> { - soptampUserService.findCurrentRanks(soptampPointList); - }); - } - - @Test @DisplayName("SUCCESS_๋‹‰๋„ค์ž„์œผ๋กœ ๋žญํ‚น ์กฐํšŒ") - void SUCCESS_findRankByNickname() { + void SUCCESS_findSoptampUserByNickname() { // given final String anyNickname = anyString(); final SoptampUser soptampUser = SoptampUser.builder().nickname(anyNickname).build(); @@ -278,7 +210,7 @@ void SUCCESS_findRankByNickname() { @Test @DisplayName("FAIL_๋‹‰๋„ค์ž„์œผ๋กœ ๋žญํ‚น ์กฐํšŒ") - void FAIL_findRankByNickname() { + void FAIL_findSoptampUserByNickname() { // given final String anyNickname = anyString(); @@ -287,7 +219,7 @@ void FAIL_findRankByNickname() { //then Assertions.assertThrows(BadRequestException.class, () -> { - soptampUserService.findRankByNickname(anyNickname); + soptampUserService.findSoptampUserByNickname(anyNickname); }); } @@ -309,7 +241,7 @@ void SUCCESS_addPoint() { .build(); //when - SoptampUserInfo.SoptampUser result = SoptampUserInfo.SoptampUser.builder() + SoptampUserInfo result = SoptampUserInfo.builder() .id(newSoptampUser.getId()) .userId(newSoptampUser.getUserId()) .profileMessage(newSoptampUser.getProfileMessage()) @@ -356,7 +288,7 @@ void SUCCESS_subtractPoint() { .build(); //when - SoptampUserInfo.SoptampUser result = SoptampUserInfo.SoptampUser.builder() + SoptampUserInfo result = SoptampUserInfo.builder() .id(newSoptampUser.getId()) .userId(newSoptampUser.getUserId()) .profileMessage(newSoptampUser.getProfileMessage()) @@ -405,7 +337,7 @@ void SUCCESS_findByNickname() { .build(); //when Mockito.when(soptampUserRepository.findUserByNickname(anyNickname)).thenReturn(Optional.of(soptampUser)); - SoptampUserInfo.SoptampUser expected = SoptampUserInfo.SoptampUser.builder() + SoptampUserInfo expected = SoptampUserInfo.builder() .id(id) .userId(userId) .profileMessage(profileMessage) diff --git a/src/test/java/org/sopt/app/application/StampServiceTest.java b/src/test/java/org/sopt/app/application/StampServiceTest.java index 1f91a5f8..e07f11bc 100644 --- a/src/test/java/org/sopt/app/application/StampServiceTest.java +++ b/src/test/java/org/sopt/app/application/StampServiceTest.java @@ -3,6 +3,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; +import static org.sopt.app.common.fixtures.SoptampFixture.MISSION_ID; +import static org.sopt.app.common.fixtures.SoptampFixture.STAMP_CONTENTS; +import static org.sopt.app.common.fixtures.SoptampFixture.STAMP_IMG_PATHS; +import static org.sopt.app.common.fixtures.SoptampFixture.USER_ID; +import static org.sopt.app.common.fixtures.SoptampFixture.getEditStampRequest; import java.time.LocalDateTime; import java.util.List; @@ -18,6 +23,7 @@ import org.sopt.app.application.stamp.StampInfo; import org.sopt.app.application.stamp.StampService; import org.sopt.app.common.exception.BadRequestException; +import org.sopt.app.common.fixtures.SoptampFixture; import org.sopt.app.domain.entity.Stamp; import org.sopt.app.interfaces.postgres.StampRepository; import org.sopt.app.presentation.stamp.StampRequest; @@ -37,9 +43,7 @@ class StampServiceTest { @DisplayName("SUCCESS_UserId์™€ MissionId๋กœ ์Šคํƒฌํ”„๋ฅผ ์ฐพ์œผ๋ฉด StampInfo.Stamp DTO ๋ฐ˜ํ™˜") void SUCCESS_findStamp() { //given - final Long stampUserId = anyLong(); - final Long stampMissionId = anyLong(); - final Stamp stamp = getSavedStamp(stampMissionId, stampUserId); + final Stamp stamp = getSavedStamp(); //when StampInfo.Stamp expected = StampInfo.Stamp.builder() @@ -49,7 +53,7 @@ void SUCCESS_findStamp() { .activityDate(stamp.getActivityDate()) .missionId(stamp.getMissionId()) .build(); - StampInfo.Stamp result = stampService.findStamp(stampUserId, stampMissionId); + StampInfo.Stamp result = stampService.findStamp(MISSION_ID, USER_ID); //then assertThat(result).usingRecursiveComparison().isEqualTo(expected); @@ -76,20 +80,15 @@ void FAIL_findStampBadRequest() { @DisplayName("SUCCESS_์Šคํƒฌํ”„๊ฐ€ request์—์„œ ๋ณด๋‚ธ ๋‚ด์šฉ์˜ ์ด๋ฏธ์ง€์™€ ๋‚ด์šฉ์œผ๋กœ ๋“ฑ๋ก๋˜์—ˆ๋Š”์ง€ ํ™•์ธ") void SUCCESS_uploadStampDeprecated() { // given - final Long requestUserId = 1L; - final Long requestMissionId = 1L; - final String requestContents = "requestContents"; - final List imgPaths = List.of("requestImage1", "requestImage2"); - RegisterStampRequest stampRequest = new RegisterStampRequest(); - stampRequest.setContents(requestContents); + RegisterStampRequest stampRequest = SoptampFixture.getRegisterStampRequest(); Stamp stamp = Stamp.builder() .id(1L) - .contents(stampRequest.getContents()) - .images(imgPaths) - .missionId(requestMissionId) - .userId(requestUserId) + .contents(STAMP_CONTENTS) + .images(STAMP_IMG_PATHS) + .missionId(MISSION_ID) + .userId(USER_ID) .build(); //when @@ -105,7 +104,7 @@ void SUCCESS_uploadStampDeprecated() { .updatedAt(newStamp.getUpdatedAt()) .build(); StampInfo.Stamp result = stampService.uploadStampDeprecated( - stampRequest, imgPaths, requestUserId, requestMissionId); + stampRequest, STAMP_IMG_PATHS, USER_ID, MISSION_ID); //then assertThat(result).usingRecursiveComparison().isEqualTo(expected); @@ -115,21 +114,13 @@ void SUCCESS_uploadStampDeprecated() { @DisplayName("SUCCESS_์Šคํƒฌํ”„๊ฐ€ request์—์„œ ๋ณด๋‚ธ ๋‚ด์šฉ์˜ ์ด๋ฏธ์ง€์™€ ๋‚ด์šฉ์œผ๋กœ ๋“ฑ๋ก๋˜์—ˆ๋Š”์ง€ ํ™•์ธ") void SUCCESS_uploadStamp() { // given - final Long requestUserId = 1L; - final Long requestMissionId = 1L; - final String requestContents = "requestContents"; - final String requestImage = "requestImage"; - - RegisterStampRequest stampRequest = new RegisterStampRequest(); - stampRequest.setContents(requestContents); - stampRequest.setImage(requestImage); - stampRequest.setMissionId(requestMissionId); + RegisterStampRequest stampRequest = SoptampFixture.getRegisterStampRequest(); Stamp stamp = Stamp.builder() .contents(stampRequest.getContents()) .images(List.of(stampRequest.getImage())) .missionId(stampRequest.getMissionId()) - .userId(requestUserId) + .userId(USER_ID) .build(); //when @@ -144,7 +135,7 @@ void SUCCESS_uploadStamp() { .updatedAt(newStamp.getUpdatedAt()) .build(); - StampInfo.Stamp result = stampService.uploadStamp(stampRequest, requestUserId); + StampInfo.Stamp result = stampService.uploadStamp(stampRequest, USER_ID); //then assertThat(result).usingRecursiveComparison().isEqualTo(expected); @@ -154,21 +145,12 @@ void SUCCESS_uploadStamp() { @DisplayName("SUCCESS_request์—์„œ ๋ณด๋‚ธ ๋‚ด์šฉ์˜ ์ด๋ฏธ์ง€์™€ ๋‚ด์šฉ์˜ ์Šคํƒฌํ”„ DTO๋ฅผ ์ž˜ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ํ™•์ธ_DEPRECATED") void SUCCESS_editStampContentsDeprecated() { // given - final Long requestUserId = anyLong(); - final Long requestMissionId = anyLong(); - final String requestContents = "requestContents"; - final String requestImage = "requestImage"; - - StampRequest.EditStampRequest editStampRequest = new StampRequest.EditStampRequest(); - editStampRequest.setContents(requestContents); - editStampRequest.setImage(requestImage); - editStampRequest.setMissionId(requestMissionId); + StampRequest.EditStampRequest editStampRequest = SoptampFixture.getEditStampRequest(); //when - Stamp oldStamp = getSavedStamp(requestMissionId, requestUserId); + Stamp oldStamp = getSavedStamp(); StampInfo.Stamp expected = editStamp(oldStamp, editStampRequest, true); - StampInfo.Stamp result = stampService.editStampContentsDeprecated(editStampRequest, requestUserId, - requestMissionId); + StampInfo.Stamp result = stampService.editStampContentsDeprecated(editStampRequest, USER_ID, MISSION_ID); //then Assertions.assertEquals(expected.getId(), result.getId()); @@ -178,43 +160,29 @@ void SUCCESS_editStampContentsDeprecated() { @DisplayName("SUCCESS_request์˜ contents๊ฐ€ ๋นˆ ๋ฌธ์ž์—ด์ด๋ฉด contents๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์Œ_DEPRECATED") void SUCCESS_editStampContentsDeprecatedNoChangeContents() { // given - final Long requestUserId = anyLong(); - final Long requestMissionId = anyLong(); - - final String requestBlankContents = ""; - final String requestImage = "requestImage"; - StampRequest.EditStampRequest editStampRequest = new StampRequest.EditStampRequest(); - editStampRequest.setContents(requestBlankContents); - editStampRequest.setImage(requestImage); - editStampRequest.setMissionId(requestMissionId); + StampRequest.EditStampRequest editStampRequest = SoptampFixture.getEditStampRequest(); //when - Stamp oldStamp = getSavedStamp(requestMissionId, requestUserId); + Stamp oldStamp = getSavedStamp(); editStamp(oldStamp, editStampRequest, true); - StampInfo.Stamp result = stampService.editStampContentsDeprecated(editStampRequest, requestUserId, - requestMissionId); + StampInfo.Stamp result = stampService.editStampContentsDeprecated(editStampRequest, USER_ID, MISSION_ID); //then Assertions.assertEquals(oldStamp.getId(), result.getId()); } - private Stamp getSavedStamp(Long missionId, Long requestUserId) { - final Long stampId = 1L; - final String contents = "savedContents"; - final List images = List.of("savedImage"); - final String activityDate = "2024.04.08"; - + private Stamp getSavedStamp() { final Optional savedStamp = Optional.of(Stamp.builder() - .id(stampId) - .contents(contents) - .images(images) - .missionId(missionId) - .userId(requestUserId) - .activityDate(activityDate) + .id(1L) + .contents("savedContents") + .images(List.of("savedImage")) + .missionId(MISSION_ID) + .userId(USER_ID) + .activityDate("2000.01.01") .build()); - Mockito.when(stampRepository.findByUserIdAndMissionId(requestUserId, missionId)).thenReturn(savedStamp); + Mockito.when(stampRepository.findByUserIdAndMissionId(USER_ID, MISSION_ID)).thenReturn(savedStamp); return savedStamp.get(); } @@ -240,8 +208,6 @@ private StampInfo.Stamp editStamp(Stamp oldStamp, StampRequest.EditStampRequest .userId(oldStamp.getUserId()) .build(); - Mockito.when(stampRepository.save(any(Stamp.class))).thenReturn(newStamp); - return StampInfo.Stamp.builder() .id(newStamp.getId()) .missionId(newStamp.getMissionId()) @@ -256,41 +222,28 @@ private StampInfo.Stamp editStamp(Stamp oldStamp, StampRequest.EditStampRequest @DisplayName("FAIL_์Šคํƒฌํ”„๋ฅผ ์ฐพ์ง€ ๋ชปํ•˜๋ฉด BadRequestException ๋ฐœ์ƒ_DEPRECATED") void FAIL_editStampContentsDeprecated() { //given - final Long requestUserId = anyLong(); - final Long requestMissionId = anyLong(); - final StampRequest.EditStampRequest editStampRequest = new StampRequest.EditStampRequest(); + final StampRequest.EditStampRequest editStampRequest = SoptampFixture.getEditStampRequest(); //when - Mockito.when(stampRepository.findByUserIdAndMissionId(requestUserId, requestMissionId)) + Mockito.when(stampRepository.findByUserIdAndMissionId(anyLong(), anyLong())) .thenReturn(Optional.empty()); //then - Assertions.assertThrows(BadRequestException.class, () -> { - stampService.editStampContentsDeprecated(editStampRequest, requestUserId, requestMissionId); - }); + Assertions.assertThrows(BadRequestException.class, + () -> stampService.editStampContentsDeprecated(editStampRequest, USER_ID, MISSION_ID)); } @Test @DisplayName("SUCCESS_request์—์„œ ๋ณด๋‚ธ ๋‚ด์šฉ์˜ ์ด๋ฏธ์ง€์™€ ๋‚ด์šฉ์˜ ์Šคํƒฌํ”„ DTO๋ฅผ ์ž˜ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ํ™•์ธ") void SUCCESS_editStampContents() { -// given - final Long requestUserId = anyLong(); - final Long requestMissionId = anyLong(); - final String requestContents = "requestContents"; - final String requestImage = "requestImage"; - final String requestActivityDate = "2024.04.08"; - - StampRequest.EditStampRequest editStampRequest = new StampRequest.EditStampRequest(); - editStampRequest.setContents(requestContents); - editStampRequest.setImage(requestImage); - editStampRequest.setMissionId(requestMissionId); - editStampRequest.setActivityDate(requestActivityDate); + // given + StampRequest.EditStampRequest editStampRequest = SoptampFixture.getEditStampRequest(); //when - Stamp oldStamp = getSavedStamp(requestMissionId, requestUserId); + Stamp oldStamp = getSavedStamp(); editStamp(oldStamp, editStampRequest, false); - StampInfo.Stamp result = stampService.editStampContents(editStampRequest, requestUserId); + StampInfo.Stamp result = stampService.editStampContents(editStampRequest, USER_ID); //then Assertions.assertEquals(oldStamp.getId(), result.getId()); @@ -300,23 +253,12 @@ void SUCCESS_editStampContents() { @DisplayName("SUCCESS_SUCCESS_request์˜ contents๊ฐ€ ๋นˆ ๋ฌธ์ž์—ด์ด๋ฉด contents๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์Œ") void SUCCESS_editStampContentsNoContents() { // given - final Long requestUserId = anyLong(); - final Long requestMissionId = anyLong(); - - final String requestBlankContents = ""; - final String requestImage = "requestImage"; - final String requestActivityDate = "2024.04.08"; - - StampRequest.EditStampRequest editStampRequest = new StampRequest.EditStampRequest(); - editStampRequest.setContents(requestBlankContents); - editStampRequest.setImage(requestImage); - editStampRequest.setMissionId(requestMissionId); - editStampRequest.setActivityDate(requestActivityDate); + StampRequest.EditStampRequest editStampRequest = SoptampFixture.getEditStampRequest(); //when - Stamp oldStamp = getSavedStamp(requestMissionId, requestUserId); + Stamp oldStamp = getSavedStamp(); StampInfo.Stamp expected = editStamp(oldStamp, editStampRequest, false); - StampInfo.Stamp result = stampService.editStampContents(editStampRequest, requestUserId); + StampInfo.Stamp result = stampService.editStampContents(editStampRequest, USER_ID); //then Assertions.assertEquals(expected.getId(), result.getId()); @@ -326,22 +268,12 @@ void SUCCESS_editStampContentsNoContents() { @DisplayName("SUCCESS_SUCCESS_request์˜ image๊ฐ€ ๋นˆ ๋ฌธ์ž์—ด์ด๋ฉด image๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์Œ") void SUCCESS_editStampContentsNoImage() { // given - final Long requestUserId = anyLong(); - final Long requestMissionId = anyLong(); - final String requestContents = "requestContents"; - final String requestBlankImage = ""; - final String requestActivityDate = "2024.04.08"; - - StampRequest.EditStampRequest editStampRequest = new StampRequest.EditStampRequest(); - editStampRequest.setContents(requestContents); - editStampRequest.setImage(requestBlankImage); - editStampRequest.setMissionId(requestMissionId); - editStampRequest.setActivityDate(requestActivityDate); + StampRequest.EditStampRequest editStampRequest = getEditStampRequest(); //when - Stamp oldStamp = getSavedStamp(requestMissionId, requestUserId); + Stamp oldStamp = getSavedStamp(); editStamp(oldStamp, editStampRequest, false); - StampInfo.Stamp result = stampService.editStampContents(editStampRequest, requestUserId); + StampInfo.Stamp result = stampService.editStampContents(editStampRequest, USER_ID); //then Assertions.assertEquals(oldStamp.getId(), result.getId()); @@ -353,8 +285,7 @@ void FAIL_editStampContents() { //given final Long requestUserId = anyLong(); final Long requestMissionId = anyLong(); - final StampRequest.EditStampRequest editStampRequest = new StampRequest.EditStampRequest(); - editStampRequest.setMissionId(requestMissionId); + final StampRequest.EditStampRequest editStampRequest = SoptampFixture.getEditStampRequest(); //when Mockito.when(stampRepository.findByUserIdAndMissionId(requestUserId, requestMissionId)) @@ -389,7 +320,6 @@ void SUCCESS_editStampImagesDeprecated() { //when Mockito.when(stampRepository.findById(anyLong())).thenReturn(Optional.of(oldStamp)); oldStamp.changeImages(imgPaths); - Mockito.when(stampRepository.save(any(Stamp.class))).thenReturn(oldStamp); //then Assertions.assertDoesNotThrow(() -> { diff --git a/src/test/java/org/sopt/app/application/UserServiceTest.java b/src/test/java/org/sopt/app/application/UserServiceTest.java index 9dc3d752..291a11b0 100644 --- a/src/test/java/org/sopt/app/application/UserServiceTest.java +++ b/src/test/java/org/sopt/app/application/UserServiceTest.java @@ -14,7 +14,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundMain; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundMain; import org.sopt.app.application.user.UserInfo; import org.sopt.app.application.user.UserService; import org.sopt.app.common.exception.NotFoundException; diff --git a/src/test/java/org/sopt/app/common/fixtures/PokeFixture.java b/src/test/java/org/sopt/app/common/fixtures/PokeFixture.java index 7a0e9a71..26cfb1c4 100644 --- a/src/test/java/org/sopt/app/common/fixtures/PokeFixture.java +++ b/src/test/java/org/sopt/app/common/fixtures/PokeFixture.java @@ -2,11 +2,11 @@ import java.util.ArrayList; import java.util.List; -import org.sopt.app.application.auth.PlaygroundAuthInfo.ActivityCardinalInfo; -import org.sopt.app.application.auth.PlaygroundAuthInfo.OwnPlaygroundProfile; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundActivity; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfile; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfileOfRecommendedFriend; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.ActivityCardinalInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.OwnPlaygroundProfile; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundActivity; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundProfile; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundProfileOfRecommendedFriend; import org.sopt.app.application.user.UserInfo.UserProfile; public class PokeFixture { diff --git a/src/test/java/org/sopt/app/common/fixtures/SoptampFixture.java b/src/test/java/org/sopt/app/common/fixtures/SoptampFixture.java new file mode 100644 index 00000000..db45caab --- /dev/null +++ b/src/test/java/org/sopt/app/common/fixtures/SoptampFixture.java @@ -0,0 +1,51 @@ +package org.sopt.app.common.fixtures; + +import java.util.List; +import org.sopt.app.application.soptamp.SoptampUserInfo; +import org.sopt.app.application.stamp.StampInfo; +import org.sopt.app.presentation.stamp.StampRequest.EditStampRequest; +import org.sopt.app.presentation.stamp.StampRequest.RegisterStampRequest; +import org.springframework.web.multipart.MultipartFile; + +public class SoptampFixture { + + /* User */ + public static final Long USER_ID = 10L; + public static final Long SOPTAMP_USER_ID = 100L; + public static final String NICKNAME = "nickname"; + + /* Mission */ + public static final Long MISSION_ID = 1L; + public static final Integer MISSION_LEVEL = 1; + + /* Stamp */ + public static final Long STAMP_ID = 11L; + public static final String STAMP_CONTENTS = "stamp contents"; + public static final String STAMP_IMAGE = "stamp image"; + public static final List STAMP_IMG_PATHS = List.of("image"); + public static final String STAMP_ACTIVITY_DATE = "2024.04.08"; + public static final List MULTIPART_FILE_LIST = List.of(); + + public static SoptampUserInfo getUserInfo() { + return SoptampUserInfo.builder().id(SOPTAMP_USER_ID).userId(USER_ID).nickname(NICKNAME).build(); + } + + public static StampInfo.Stamp getStampInfo() { + return StampInfo.Stamp.builder() + .id(STAMP_ID) + .contents(STAMP_CONTENTS) + .userId(SOPTAMP_USER_ID) + .missionId(MISSION_ID) + .images(STAMP_IMG_PATHS) + .activityDate(STAMP_ACTIVITY_DATE) + .build(); + } + + public static RegisterStampRequest getRegisterStampRequest() { + return new RegisterStampRequest(MISSION_ID, STAMP_IMAGE, STAMP_CONTENTS, STAMP_ACTIVITY_DATE); + } + + public static EditStampRequest getEditStampRequest() { + return new EditStampRequest(MISSION_ID, STAMP_IMAGE, STAMP_CONTENTS, STAMP_ACTIVITY_DATE); + } +} diff --git a/src/test/java/org/sopt/app/common/fixtures/SoptampPointFixture.java b/src/test/java/org/sopt/app/common/fixtures/SoptampPointFixture.java new file mode 100644 index 00000000..3f41ce51 --- /dev/null +++ b/src/test/java/org/sopt/app/common/fixtures/SoptampPointFixture.java @@ -0,0 +1,71 @@ +package org.sopt.app.common.fixtures; + +import static org.sopt.app.common.fixtures.SoptampUserFixture.SOPTAMP_USER_1; +import static org.sopt.app.common.fixtures.SoptampUserFixture.SOPTAMP_USER_2; +import static org.sopt.app.common.fixtures.SoptampUserFixture.SOPTAMP_USER_3; + +import java.util.List; +import org.sopt.app.application.soptamp.SoptampPointInfo.PartPoint; +import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; +import org.sopt.app.application.soptamp.SoptampPointInfo.Point; +import org.sopt.app.domain.enums.Part; + +public class SoptampPointFixture { + + public static final Point POINT_1 = Point.builder() + .id(1L) + .generation(1L) + .soptampUserId(SOPTAMP_USER_1.getId()) + .points(100L).build(); + public static final Point POINT_2 = Point.builder() + .id(2L) + .generation(1L) + .soptampUserId(SOPTAMP_USER_2.getId()) + .points(200L).build(); + public static final Point POINT_3 = Point.builder() + .id(3L) + .generation(1L) + .soptampUserId(SOPTAMP_USER_3.getId()) + .points(300L).build(); + public static final List SOPTAMP_POINT_LIST = List.of(POINT_1, POINT_2, POINT_3); + + public static final PartRank PART_RANK_PLAN = PartRank.builder() + .part(Part.PLAN.getPartName()) + .rank(1) + .points(50L) + .build(); + public static final PartRank PART_RANK_SERVER = PartRank.builder() + .part(Part.SERVER.getPartName()) + .rank(2) + .points(40L) + .build(); + public static final PartRank PART_RANK_WEB = PartRank.builder() + .part(Part.WEB.getPartName()) + .rank(3) + .points(30L) + .build(); + public static final PartRank PART_RANK_IOS = PartRank.builder() + .part(Part.IOS.getPartName()) + .rank(4) + .points(20L) + .build(); + public static final PartRank PART_RANK_ANDROID = PartRank.builder() + .part(Part.ANDROID.getPartName()) + .rank(5) + .points(10L) + .build(); + public static final PartRank PART_RANK_DESIGN = PartRank.builder() + .part(Part.DESIGN.getPartName()) + .rank(6) + .points(0L) + .build(); + + public static final List PART_POINTS = List.of( + new PartPoint(Part.PLAN, 50L), + new PartPoint(Part.DESIGN, 0L), + new PartPoint(Part.WEB, 30L), + new PartPoint(Part.IOS, 20L), + new PartPoint(Part.ANDROID, 10L), + new PartPoint(Part.SERVER, 40L)); +} + diff --git a/src/test/java/org/sopt/app/common/fixtures/SoptampUserFixture.java b/src/test/java/org/sopt/app/common/fixtures/SoptampUserFixture.java new file mode 100644 index 00000000..5109231b --- /dev/null +++ b/src/test/java/org/sopt/app/common/fixtures/SoptampUserFixture.java @@ -0,0 +1,26 @@ +package org.sopt.app.common.fixtures; + +import java.util.List; +import org.sopt.app.application.soptamp.SoptampUserInfo; +import org.sopt.app.domain.entity.SoptampUser; + +public class SoptampUserFixture { + + public static final SoptampUser SOPTAMP_USER_1 = + SoptampUser.builder().id(1L).userId(10L).nickname("1stUser").totalPoints(100L).build(); + public static final SoptampUser SOPTAMP_USER_2 = + SoptampUser.builder().id(2L).userId(20L).nickname("2stUser").totalPoints(200L).build(); + public static final SoptampUser SOPTAMP_USER_3 = + SoptampUser.builder().id(3L).userId(30L).nickname("3stUser").totalPoints(300L).build(); + public static final List SOPTAMP_USER_ID_LIST = + List.of(SOPTAMP_USER_1.getId(), SOPTAMP_USER_2.getId(), SOPTAMP_USER_3.getId()); + + public static final SoptampUserInfo SOPTAMP_USER_INFO_1 = + SoptampUserInfo.builder().id(1L).userId(10L).nickname("1stUser").totalPoints(100L).build(); + public static final SoptampUserInfo SOPTAMP_USER_INFO_2 = + SoptampUserInfo.builder().id(2L).userId(20L).nickname("2stUser").totalPoints(200L).build(); + public static final SoptampUserInfo SOPTAMP_USER_INFO_3 = + SoptampUserInfo.builder().id(3L).userId(30L).nickname("3stUser").totalPoints(300L).build(); + public static final List SOPTAMP_USER_INFO_LIST = + List.of(SOPTAMP_USER_INFO_1, SOPTAMP_USER_INFO_2, SOPTAMP_USER_INFO_3); +} diff --git a/src/test/java/org/sopt/app/facade/AuthFacadeTest.java b/src/test/java/org/sopt/app/facade/AuthFacadeTest.java index 28cf50f5..a9d9b277 100644 --- a/src/test/java/org/sopt/app/facade/AuthFacadeTest.java +++ b/src/test/java/org/sopt/app/facade/AuthFacadeTest.java @@ -11,9 +11,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.sopt.app.application.auth.JwtTokenService; -import org.sopt.app.application.auth.PlaygroundAuthInfo.AppToken; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundMain; -import org.sopt.app.application.auth.PlaygroundAuthInfo.RefreshedToken; +import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.AppToken; +import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.RefreshedToken; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundMain; import org.sopt.app.application.auth.PlaygroundAuthService; import org.sopt.app.application.soptamp.SoptampPointService; import org.sopt.app.application.soptamp.SoptampUserService; @@ -48,18 +48,14 @@ public class AuthFacadeTest { @Test @DisplayName("SUCCESS_์ธ์ฆ ํšŒ์› ํ”Œ๊ทธ๋กœ ๋กœ๊ทธ์ธ") void SUCCESS_loginWithPlaygroundActive() { - CodeRequest codeRequest = new CodeRequest(); - codeRequest.setCode("code"); - AccessTokenRequest accessTokenRequest = new AccessTokenRequest(); - accessTokenRequest.setAccessToken("accessToken"); + CodeRequest codeRequest = new CodeRequest("code"); + AccessTokenRequest accessTokenRequest = new AccessTokenRequest("accessToken"); RefreshedToken refreshedToken = RefreshedToken.builder().accessToken("refreshedToken").build(); PlaygroundMain playgroundMain = PlaygroundMain.builder().name("name").status(UserStatus.ACTIVE).build(); Id userId = Id.builder().id(21L).build(); Long soptampUserId = 5L; AppToken appToken = AppToken.builder().accessToken("appAccessToken").refreshToken("appRefreshToken").build(); - Token token = new Token(); - token.setAccessToken("appAccessToken"); - token.setRefreshToken("appRefreshToken"); + Token token = new Token("appAccessToken", "appRefreshToken", null, null); when(playgroundAuthService.getPlaygroundAccessToken(codeRequest)).thenReturn(accessTokenRequest); when(playgroundAuthService.refreshPlaygroundToken(accessTokenRequest)).thenReturn(refreshedToken); @@ -81,18 +77,14 @@ void SUCCESS_loginWithPlaygroundActive() { @Test @DisplayName("SUCCESS_์ธ์ฆ ํšŒ์› ํ† ํฐ ๋ฆฌํ”„๋ ˆ์‹œ") void SUCCESS_getRefreshToken() { - RefreshRequest refreshRequest = new RefreshRequest(); - refreshRequest.setRefreshToken("refreshToken"); - AccessTokenRequest accessTokenRequest = new AccessTokenRequest(); - accessTokenRequest.setAccessToken("accessToken"); + RefreshRequest refreshRequest = new RefreshRequest("refreshToken"); + AccessTokenRequest accessTokenRequest = new AccessTokenRequest("accessToken"); RefreshedToken refreshedToken = RefreshedToken.builder().accessToken("refreshedToken").build(); PlaygroundMain playgroundMain = PlaygroundMain.builder().accessToken("accessToken").status(UserStatus.ACTIVE).build(); Id userId = Id.builder().id(21L).build(); AppToken newAppToken = AppToken.builder().accessToken("newAppAccessToken").refreshToken("newAppRefreshToken") .build(); - Token token = new Token(); - token.setAccessToken("newAppAccessToken"); - token.setRefreshToken("newAppRefreshToken"); + Token token = new Token("newAppAccessToken", "newAppRefreshToken", null, null); when(jwtTokenService.getUserIdFromJwtToken(refreshRequest.getRefreshToken())).thenReturn(userId); when(userService.getPlaygroundToken(userId)).thenReturn(accessTokenRequest); diff --git a/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java b/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java index 4d22f8ea..c6bf6068 100644 --- a/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java +++ b/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java @@ -1,6 +1,5 @@ package org.sopt.app.facade; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; @@ -12,7 +11,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.sopt.app.application.auth.PlaygroundAuthInfo.UserActiveInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.UserActiveInfo; import org.sopt.app.application.auth.PlaygroundAuthService; import org.sopt.app.application.description.DescriptionInfo; import org.sopt.app.application.description.DescriptionInfo.MainDescription; @@ -38,7 +37,7 @@ void SUCCESS_getMainDescriptionForUserActive() { User user = User.builder().playgroundId(1L).playgroundToken("token").build(); UserStatus userStatus = UserStatus.ACTIVE; Mockito.when(playgroundAuthService.getPlaygroundUserActiveInfo(anyString(), anyLong())) - .thenReturn(UserActiveInfo.builder().currentGeneration(34L).status(userStatus).build()); + .thenReturn(new UserActiveInfo(34L, userStatus)); Mockito.when(descriptionService.getMainDescription(userStatus)) .thenReturn(DescriptionInfo.MainDescription.builder().topDescription("activeTop") .bottomDescription("activeBottom").build()); @@ -54,7 +53,7 @@ void SUCCESS_getMainDescriptionForUserInactive() { User user = User.builder().playgroundId(1L).playgroundToken("token").build(); UserStatus userStatus = UserStatus.INACTIVE; Mockito.when(playgroundAuthService.getPlaygroundUserActiveInfo(anyString(), anyLong())) - .thenReturn(UserActiveInfo.builder().currentGeneration(29L).status(userStatus).build()); + .thenReturn(new UserActiveInfo(29L, userStatus)); Mockito.when(descriptionService.getMainDescription(userStatus)) .thenReturn(DescriptionInfo.MainDescription.builder().topDescription("inactiveTop") .bottomDescription("inactiveBottom").build()); diff --git a/src/test/java/org/sopt/app/facade/PokeFacadeTest.java b/src/test/java/org/sopt/app/facade/PokeFacadeTest.java index 4ad78216..83c3e045 100644 --- a/src/test/java/org/sopt/app/facade/PokeFacadeTest.java +++ b/src/test/java/org/sopt/app/facade/PokeFacadeTest.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -32,10 +31,10 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.sopt.app.application.auth.PlaygroundAuthInfo; -import org.sopt.app.application.auth.PlaygroundAuthInfo.ActiveUserIds; -import org.sopt.app.application.auth.PlaygroundAuthInfo.ActivityCardinalInfo; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfile; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.ActiveUserIds; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.ActivityCardinalInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundProfile; import org.sopt.app.application.auth.PlaygroundAuthService; import org.sopt.app.application.poke.FriendService; import org.sopt.app.application.poke.PokeHistoryService; @@ -71,7 +70,7 @@ class PokeFacadeTest { private static final String MESSAGES_HEADER_FOR_POKE = "ํ•จ๊ป˜ ๋ณด๋‚ผ ๋ฉ”์‹œ์ง€๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”"; private final Relationship relationship1 = Relationship.builder().pokeNum(1).build(); private final Relationship relationship2 = Relationship.builder().pokeNum(3).build(); - private final PlaygroundAuthInfo.ActiveUserIds activeUserIds = ActiveUserIds.builder().userIds(List.of(1L, 2L, 3L)).build(); + private final PlaygroundProfileInfo.ActiveUserIds activeUserIds = new ActiveUserIds(List.of(1L, 2L, 3L)); private final User user = User.builder().id(1L).playgroundToken("token").build(); private final UserProfile userProfile1 = UserProfile.builder().userId(1L).name("name1").playgroundId(1L).build(); private final UserProfile userProfile2 = UserProfile.builder().userId(2L).name("name2").playgroundId(2L).build(); @@ -170,7 +169,7 @@ void SUCCESS_getRecommendUserForNew() { "์ƒˆ๋กœ์šด ์นœ๊ตฌ", "์ƒˆ๋กœ์šด ์นœ๊ตฌ", true, false, false, "")); when(playgroundAuthService.getPlayGroundUserIds("token")).thenReturn(activeUserIds); - when(userService.getUserProfilesByPlaygroundIds(activeUserIds.getUserIds())).thenReturn( + when(userService.getUserProfilesByPlaygroundIds(activeUserIds.userIds())).thenReturn( userProfileListIncludingMe); when(friendService.isFriendEachOther(1L, 2L)).thenReturn(false); when(friendService.isFriendEachOther(1L, 3L)).thenReturn(true); diff --git a/src/test/java/org/sopt/app/facade/RankFacadeTest.java b/src/test/java/org/sopt/app/facade/RankFacadeTest.java new file mode 100644 index 00000000..7833f463 --- /dev/null +++ b/src/test/java/org/sopt/app/facade/RankFacadeTest.java @@ -0,0 +1,105 @@ +package org.sopt.app.facade; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.sopt.app.common.fixtures.SoptampPointFixture.PART_POINTS; +import static org.sopt.app.common.fixtures.SoptampPointFixture.PART_RANK_ANDROID; +import static org.sopt.app.common.fixtures.SoptampPointFixture.PART_RANK_DESIGN; +import static org.sopt.app.common.fixtures.SoptampPointFixture.PART_RANK_IOS; +import static org.sopt.app.common.fixtures.SoptampPointFixture.PART_RANK_PLAN; +import static org.sopt.app.common.fixtures.SoptampPointFixture.PART_RANK_SERVER; +import static org.sopt.app.common.fixtures.SoptampPointFixture.PART_RANK_WEB; +import static org.sopt.app.common.fixtures.SoptampPointFixture.POINT_1; +import static org.sopt.app.common.fixtures.SoptampPointFixture.POINT_2; +import static org.sopt.app.common.fixtures.SoptampPointFixture.POINT_3; +import static org.sopt.app.common.fixtures.SoptampPointFixture.SOPTAMP_POINT_LIST; +import static org.sopt.app.common.fixtures.SoptampUserFixture.SOPTAMP_USER_ID_LIST; +import static org.sopt.app.common.fixtures.SoptampUserFixture.SOPTAMP_USER_INFO_1; +import static org.sopt.app.common.fixtures.SoptampUserFixture.SOPTAMP_USER_INFO_2; +import static org.sopt.app.common.fixtures.SoptampUserFixture.SOPTAMP_USER_INFO_3; +import static org.sopt.app.common.fixtures.SoptampUserFixture.SOPTAMP_USER_INFO_LIST; + +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.sopt.app.application.soptamp.SoptampPointInfo.Main; +import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; +import org.sopt.app.application.soptamp.SoptampPointService; +import org.sopt.app.application.soptamp.SoptampUserService; + +@ExtendWith(MockitoExtension.class) +class RankFacadeTest { + + @Mock + private SoptampUserService soptampUserService; + + @Mock + private SoptampPointService soptampPointService; + + @InjectMocks + private RankFacade rankFacade; + + @Test + @DisplayName("SUCCESS_์†ํƒฌํ”„ ํฌ์ธํŠธ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฐ›์•„ ๋žญํฌ๋ฅผ ์กฐํšŒ") + void SUCCESS_findCurrentRanks() { + //given + given(soptampPointService.findCurrentGenerationPoints()).willReturn(SOPTAMP_POINT_LIST); + given(soptampUserService.findAllBySoptampUserIds(SOPTAMP_USER_ID_LIST)).willReturn(SOPTAMP_USER_INFO_LIST); + + //when + List
expected = List.of( + Main.builder().rank(1).nickname(SOPTAMP_USER_INFO_3.getNickname()).point(POINT_3.getPoints()).build(), + Main.builder().rank(2).nickname(SOPTAMP_USER_INFO_2.getNickname()).point(POINT_2.getPoints()).build(), + Main.builder().rank(3).nickname(SOPTAMP_USER_INFO_1.getNickname()).point(POINT_1.getPoints()).build() + ); + List
result = rankFacade.findCurrentRanks(); + + //then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); + } + + @Test + @DisplayName("SUCCESS_์†ํƒฌํ”„ ํฌ์ธํŠธ ํ•ด๋‹นํ•˜๋Š” ์œ ์ €๊ฐ€ ์—†๋‹ค๋ฉด ์Šฌ๋ž™ ์•Œ๋ฆผ์„ ๋ณด๋‚ด๊ธฐ") + void SUCCESS_findCurrentRanks_Requirement1() { + //given + given(soptampPointService.findCurrentGenerationPoints()).willReturn(SOPTAMP_POINT_LIST); + given(soptampUserService.findAllBySoptampUserIds(SOPTAMP_USER_ID_LIST)).willReturn( + List.of(SOPTAMP_USER_INFO_1, SOPTAMP_USER_INFO_2) // 3๋ฒˆ ์œ ์ €๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Œ + ); + + //when + List
expected = List.of( + Main.builder().rank(1).nickname(SOPTAMP_USER_INFO_2.getNickname()).point(POINT_2.getPoints()).build(), + Main.builder().rank(2).nickname(SOPTAMP_USER_INFO_1.getNickname()).point(POINT_1.getPoints()).build() + ); + List
result = rankFacade.findCurrentRanks(); + + //then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); + } + + @Test + @DisplayName("SUCCESS_ํŒŒํŠธ ๋žญํ‚น ์ฐพ๊ธฐ") + void SUCCESS_findAllPartRanks() { + //given + given(soptampPointService.findSumOfPointAllParts()).willReturn(PART_POINTS); + + //when + List result = rankFacade.findAllPartRanks(); + List expected = List.of( + PART_RANK_PLAN, + PART_RANK_DESIGN, + PART_RANK_WEB, + PART_RANK_IOS, + PART_RANK_ANDROID, + PART_RANK_SERVER + ); + + //then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); + } +} diff --git a/src/test/java/org/sopt/app/facade/SoptampFacadeTest.java b/src/test/java/org/sopt/app/facade/SoptampFacadeTest.java index a75b287e..63a081b0 100644 --- a/src/test/java/org/sopt/app/facade/SoptampFacadeTest.java +++ b/src/test/java/org/sopt/app/facade/SoptampFacadeTest.java @@ -1,15 +1,34 @@ package org.sopt.app.facade; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.sopt.app.common.fixtures.SoptampFixture.MISSION_ID; +import static org.sopt.app.common.fixtures.SoptampFixture.MISSION_LEVEL; +import static org.sopt.app.common.fixtures.SoptampFixture.MULTIPART_FILE_LIST; +import static org.sopt.app.common.fixtures.SoptampFixture.NICKNAME; +import static org.sopt.app.common.fixtures.SoptampFixture.SOPTAMP_USER_ID; +import static org.sopt.app.common.fixtures.SoptampFixture.STAMP_ID; +import static org.sopt.app.common.fixtures.SoptampFixture.STAMP_IMG_PATHS; +import static org.sopt.app.common.fixtures.SoptampFixture.USER_ID; + +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.sopt.app.application.mission.MissionInfo; import org.sopt.app.application.mission.MissionService; import org.sopt.app.application.s3.S3Service; import org.sopt.app.application.soptamp.SoptampPointService; +import org.sopt.app.application.soptamp.SoptampUserInfo; import org.sopt.app.application.soptamp.SoptampUserService; +import org.sopt.app.application.stamp.StampInfo; import org.sopt.app.application.stamp.StampService; +import org.sopt.app.common.fixtures.SoptampFixture; +import org.sopt.app.presentation.stamp.StampRequest; +import org.sopt.app.presentation.stamp.StampRequest.EditStampRequest; @ExtendWith(MockitoExtension.class) class SoptampFacadeTest { @@ -28,39 +47,133 @@ class SoptampFacadeTest { @InjectMocks private SoptampFacade soptampFacade; - /* TODO: ์•„๋ž˜ ๋ฉ”์„œ๋“œ ๊ตฌํ˜„ @Test - void getStampInfo() { + @DisplayName("SUCCESS_์Šคํƒฌํ”„ ์กฐํšŒํ•˜๊ธฐ") + void SUCCESS_getStampInfo() { + // given + final StampInfo.Stamp stampInfo = SoptampFixture.getStampInfo(); + given(soptampUserService.findByNickname(NICKNAME)).willReturn(SoptampFixture.getUserInfo()); + given(stampService.findStamp(MISSION_ID, USER_ID)).willReturn(stampInfo); + + // when + StampInfo.Stamp result = soptampFacade.getStampInfo(MISSION_ID, NICKNAME); + + // then + assertEquals(stampInfo, result); } + @Test - void uploadStamp() { + @DisplayName("SUCCESS_์Šคํƒฌํ”„ ์—…๋กœ๋“œํ•˜๊ธฐ") + void SUCCESS_uploadStamp() { + // given + final StampInfo.Stamp uploadedStamp = SoptampFixture.getStampInfo(); + final StampRequest.RegisterStampRequest registerStampRequest = SoptampFixture.getRegisterStampRequest(); + given(stampService.uploadStamp(registerStampRequest, SOPTAMP_USER_ID)).willReturn(uploadedStamp); + given(missionService.getMissionById(MISSION_ID)).willReturn(MissionInfo.Level.of(MISSION_LEVEL)); + given(soptampUserService.addPoint(SOPTAMP_USER_ID, MISSION_LEVEL)).willReturn(SoptampFixture.getUserInfo()); + + // when + StampInfo.Stamp result = soptampFacade.uploadStamp(SOPTAMP_USER_ID, registerStampRequest); + + // then + assertEquals(uploadedStamp, result); } @Test + @DisplayName("SUCCESS_์Šคํƒฌํ”„ ์—…๋กœ๋“œํ•˜๊ธฐ(์ด์ „ ๋ฒ„์ „)") void uploadStampDeprecated() { + // given + final StampInfo.Stamp uploadedStamp = SoptampFixture.getStampInfo(); + final StampRequest.RegisterStampRequest registerStampRequest = SoptampFixture.getRegisterStampRequest(); + given(s3Service.uploadDeprecated(MULTIPART_FILE_LIST)).willReturn(SoptampFixture.STAMP_IMG_PATHS); + given(stampService.uploadStampDeprecated(registerStampRequest, STAMP_IMG_PATHS, SOPTAMP_USER_ID, MISSION_ID)) + .willReturn(uploadedStamp); + given(missionService.getMissionById(MISSION_ID)).willReturn(MissionInfo.Level.of(MISSION_LEVEL)); + given(soptampUserService.addPoint(SOPTAMP_USER_ID, MISSION_LEVEL)).willReturn(SoptampFixture.getUserInfo()); + + // when + StampInfo.Stamp result = soptampFacade.uploadStampDeprecated( + SOPTAMP_USER_ID, MISSION_ID, registerStampRequest, MULTIPART_FILE_LIST); + + // then + assertEquals(uploadedStamp, result); } @Test - void editStamp() { + @DisplayName("SUCCESS_์Šคํƒฌํ”„ ์ˆ˜์ •ํ•˜๊ธฐ") + void SUCCESS_editStamp() { + // given + final StampInfo.Stamp editedStamp = SoptampFixture.getStampInfo(); + final EditStampRequest editStampRequest = SoptampFixture.getEditStampRequest(); + given(stampService.editStampContentsDeprecated(editStampRequest, SOPTAMP_USER_ID, MISSION_ID)) + .willReturn(editedStamp); + given(s3Service.uploadDeprecated(MULTIPART_FILE_LIST)).willReturn(SoptampFixture.STAMP_IMG_PATHS); + + // when + StampInfo.Stamp result = + soptampFacade.editStamp(editStampRequest, SOPTAMP_USER_ID, MISSION_ID, MULTIPART_FILE_LIST); + + // then + assertEquals(editedStamp, result); } @Test - void deleteStamp() { + @DisplayName("SUCCESS_์Šคํƒฌํ”„ ์‚ญ์ œํ•˜๊ธฐ") + void SUCCESS_deleteStamp() { + // given + given(stampService.getMissionIdByStampId(STAMP_ID)).willReturn(MISSION_ID); + given(missionService.getMissionById(MISSION_ID)).willReturn(MissionInfo.Level.of(MISSION_LEVEL)); + given(soptampUserService.subtractPoint(SOPTAMP_USER_ID, MISSION_LEVEL)) + .willReturn(SoptampFixture.getUserInfo()); + + // when + soptampFacade.deleteStamp(SOPTAMP_USER_ID, STAMP_ID); + + // then + then(soptampPointService).should().subtractPoint(SOPTAMP_USER_ID, MISSION_LEVEL); + then(stampService).should().deleteStampById(STAMP_ID); } @Test - void deleteStampAll() { + @DisplayName("SUCCESS_๋ชจ๋“  ์Šคํƒฌํ”„ ์‚ญ์ œํ•˜๊ธฐ") + void SUCCESS_deleteStampAll() { + // given & when + soptampFacade.deleteStampAll(SOPTAMP_USER_ID); + + // then + then(stampService).should().deleteAllStamps(SOPTAMP_USER_ID); + then(soptampUserService).should().initPoint(SOPTAMP_USER_ID); + then(soptampPointService).should().initPoint(SOPTAMP_USER_ID); } - /* TODO: UserController ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑํ•˜๋ฉฐ ์ž‘์„ฑ @Test - void editSoptampUserNickname() { + @DisplayName("SUCCESS_์†ํƒฌํ”„ ์œ ์ € ๋‹‰๋„ค์ž„ ์ˆ˜์ •ํ•˜๊ธฐ") + void SUCCESS_editSoptampUserNickname() { + // given + final SoptampUserInfo soptampUser = SoptampFixture.getUserInfo(); + given(soptampUserService.getSoptampUserInfo(USER_ID)).willReturn(soptampUser); + + // when + soptampFacade.editSoptampUserNickname(USER_ID, NICKNAME); + + // then + then(soptampUserService).should().editNickname(soptampUser, NICKNAME); } @Test - void editSoptampUserProfileMessage() { + @DisplayName("SUCCESS_์†ํƒฌํ”„ ์œ ์ € ํ”„๋กœํ•„ ๋ฉ”์‹œ์ง€ ์ˆ˜์ •ํ•˜๊ธฐ") + void SUCCESS_editSoptampUserProfileMessage() { + // given + final SoptampUserInfo soptampUser = SoptampFixture.getUserInfo(); + final String newProfileMessage = "new message"; + given(soptampUserService.getSoptampUserInfo(USER_ID)).willReturn(soptampUser); + + // when + soptampFacade.editSoptampUserProfileMessage(USER_ID, newProfileMessage); + + // then + then(soptampUserService).should().editProfileMessage(soptampUser, newProfileMessage); } - */ } \ No newline at end of file diff --git a/src/test/java/org/sopt/app/facade/UserFacadeTest.java b/src/test/java/org/sopt/app/facade/UserFacadeTest.java index f17bf4a8..49168994 100644 --- a/src/test/java/org/sopt/app/facade/UserFacadeTest.java +++ b/src/test/java/org/sopt/app/facade/UserFacadeTest.java @@ -13,8 +13,8 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.sopt.app.application.auth.PlaygroundAuthInfo; -import org.sopt.app.application.auth.PlaygroundAuthInfo.MainView; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo; +import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.MainView; import org.sopt.app.application.auth.PlaygroundAuthService; import org.sopt.app.application.notification.NotificationService; import org.sopt.app.application.operation.OperationInfo; @@ -41,7 +41,7 @@ class UserFacadeTest { void getMainViewInfo() { // given final boolean isNotificationConfirm = true; - final PlaygroundAuthInfo.MainView playgroundAuthInfo = PlaygroundAuthInfo.MainView.builder().build(); + final PlaygroundProfileInfo.MainView playgroundAuthInfo = new MainView(null); final UserResponse.Playground playground = UserResponse.Playground.builder().build(); final UserResponse.Operation operation = Operation.builder().build(); final UserResponse.MainView mainViewResponse = UserResponse.MainView.builder() diff --git a/src/test/java/org/sopt/app/interfaces/postgres/FriendRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/FriendRepositoryTest.java index 73164caa..d788427f 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/FriendRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/FriendRepositoryTest.java @@ -8,11 +8,11 @@ import org.sopt.app.common.config.QuerydslConfiguration; import org.sopt.app.domain.entity.Friend; import org.sopt.app.domain.entity.User; +import org.sopt.app.interfaces.postgres.friend.FriendRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; @DataJpaTest diff --git a/src/test/java/org/sopt/app/interfaces/postgres/PushTokenRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/PushTokenRepositoryTest.java new file mode 100644 index 00000000..85e52f6a --- /dev/null +++ b/src/test/java/org/sopt/app/interfaces/postgres/PushTokenRepositoryTest.java @@ -0,0 +1,70 @@ +package org.sopt.app.interfaces.postgres; + +import java.util.List; +import java.util.Optional; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.sopt.app.common.config.QuerydslConfiguration; +import org.sopt.app.domain.entity.PushToken; +import org.sopt.app.domain.enums.PushTokenPlatform; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +@DataJpaTest +@AutoConfigureTestDatabase(replace = Replace.NONE) +@Import(QuerydslConfiguration.class) +class PushTokenRepositoryTest { + + @Autowired + private PushTokenRepository pushTokenRepository; + + private PushToken pushToken1; + private PushToken pushToken2; + + @BeforeEach + void beforeTest() { + + pushToken1 = pushTokenRepository.save( + PushToken.builder() + .userId(1L) + .playgroundId(1L) + .token("token1") + .platform(PushTokenPlatform.Android) + .build() + ); + pushToken2 = pushTokenRepository.save( + PushToken.builder() + .userId(1L) + .playgroundId(1L) + .token("token2") + .platform(PushTokenPlatform.iOS) + .build() + ); + } + + @Test + @DisplayName("SUCCESS_์œ ์ € ์•„์ด๋””์™€ ํ† ํฐ์œผ๋กœ ํ‘ธ์‹œ ํ† ํฐ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ") + void SUCCESS_existsByUserIdAndToken() { + Assertions.assertThat(pushTokenRepository.existsByUserIdAndToken(pushToken1.getUserId(), pushToken1.getToken())).isTrue(); + } + + + @Test + @DisplayName("SUCCESS_์œ ์ € ์•„์ด๋””์™€ ํ† ํฐ์œผ๋กœ ํ‘ธ์‹œ ํ† ํฐ ์ฐพ๊ธฐ") + void SUCCESS_findByUserIdAndToken() { + Assertions.assertThat(pushTokenRepository.findByUserIdAndToken(pushToken1.getUserId(), pushToken1.getToken())) + .isEqualTo(Optional.of(pushToken1)); + } + + @Test + @DisplayName("SUCCESS_์œ ์ € ์•„์ด๋””๋กœ ํ‘ธ์‹œ ํ† ํฐ ๋ฆฌ์ŠคํŠธ ์ฐพ๊ธฐ") + void SUCCESS_findAllByUserId() { + Assertions.assertThat(pushTokenRepository.findAllByUserId(pushToken1.getUserId())) + .containsAll(List.of(pushToken1, pushToken2)); + } +} \ No newline at end of file diff --git a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java index 756d30f1..cd5704a9 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.Test; import org.sopt.app.common.config.QuerydslConfiguration; import org.sopt.app.domain.entity.SoptampPoint; +import org.sopt.app.interfaces.postgres.soptamp_point.SoptampPointRepository; +import org.sopt.app.interfaces.postgres.soptamp_point.SoptampPointRepositoryImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; @@ -15,7 +17,7 @@ @DataJpaTest @AutoConfigureTestDatabase(replace = Replace.NONE) -@Import(QuerydslConfiguration.class) +@Import({QuerydslConfiguration.class, SoptampPointRepositoryImpl.class}) class SoptampPointRepositoryTest { @Autowired