diff --git a/src/main/java/org/sopt/app/application/friend/FriendRecommender.java b/src/main/java/org/sopt/app/application/friend/FriendRecommender.java index 0188d7c3..8827e265 100644 --- a/src/main/java/org/sopt/app/application/friend/FriendRecommender.java +++ b/src/main/java/org/sopt/app/application/friend/FriendRecommender.java @@ -71,7 +71,7 @@ private List makeSimplePokeProfilesForNotFriend( playgroundProfile.getProfileImage(), userProfile.getName(), playgroundProfile.getLatestActivity().getGeneration(), - playgroundProfile.getLatestActivity().getPart() + playgroundProfile.getLatestActivity().getPlaygroundPart().getPartName() ); }).toList(); } diff --git a/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java index 200cc1dd..c5f92678 100755 --- a/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/playground/PlaygroundAuthService.java @@ -154,4 +154,8 @@ public PlaygroundPost getPlaygroundHotPost(String playgroundToken) { private String convertPlaygroundWebPageUrl(Long postId) { return playgroundWebPageUrl + "/?feed=" + postId; } + + public boolean isCurrentGeneration(Long generation) { + return generation.equals(currentGeneration); + } } diff --git a/src/main/java/org/sopt/app/application/playground/dto/PlaygroundProfileInfo.java b/src/main/java/org/sopt/app/application/playground/dto/PlaygroundProfileInfo.java index fce0f4bf..bcb28b04 100755 --- a/src/main/java/org/sopt/app/application/playground/dto/PlaygroundProfileInfo.java +++ b/src/main/java/org/sopt/app/application/playground/dto/PlaygroundProfileInfo.java @@ -1,11 +1,14 @@ package org.sopt.app.application.playground.dto; +import static org.sopt.app.domain.enums.PlaygroundPart.findPlaygroundPartByPartName; + import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.constraints.NotNull; import java.util.*; import lombok.*; import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.common.response.ErrorCode; +import org.sopt.app.domain.enums.PlaygroundPart; import org.sopt.app.domain.enums.UserStatus; @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -99,7 +102,8 @@ public ActivityCardinalInfo getLatestActivity() { @AllArgsConstructor(access = AccessLevel.PUBLIC) public static class ActivityCardinalInfo { - private String cardinalInfo; + private String cardinalInfo; // "{generation},{part}" + // part = 기획, 디자인, 서버, 안드로이드, iOS, 웹 / 회장, 부회장, 총무, {team} 팀장, {part} 파트장, public Long getGeneration() { try { @@ -109,8 +113,8 @@ public Long getGeneration() { } } - public String getPart() { - return cardinalInfo.split(",")[1]; + public PlaygroundPart getPlaygroundPart() { + return findPlaygroundPartByPartName(cardinalInfo.split(",")[1]); } } 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 7ab544dd..6bc20d17 100755 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java @@ -1,7 +1,7 @@ package org.sopt.app.application.soptamp; import static org.sopt.app.domain.entity.soptamp.SoptampUser.createNewSoptampUser; -import static org.sopt.app.domain.enums.PlaygroundPart.findPlaygroundPart; +import static org.sopt.app.domain.enums.PlaygroundPart.findPlaygroundPartByPartName; import java.util.*; import lombok.*; @@ -10,6 +10,7 @@ import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.common.response.ErrorCode; import org.sopt.app.domain.entity.soptamp.SoptampUser; +import org.sopt.app.domain.enums.PlaygroundPart; import org.sopt.app.interfaces.postgres.SoptampUserRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,19 +51,19 @@ public void upsertSoptampUser(PlaygroundProfile profile, Long userId) { private void updateSoptampUser(SoptampUser registeredUser, PlaygroundProfile profile){ ActivityCardinalInfo lastActivity = profile.getLatestActivity(); - String uniqueNickname = generateUniqueNickname(profile.getName(), lastActivity.getPart()); + String uniqueNickname = generateUniqueNickname(profile.getName(), lastActivity.getPlaygroundPart()); registeredUser.updateChangedGenerationInfo( lastActivity.getGeneration(), - findPlaygroundPart(lastActivity.getPart()), + findPlaygroundPartByPartName(lastActivity.getPlaygroundPart().getPartName()), uniqueNickname ); } private void createSoptampUser(PlaygroundProfile profile, Long userId) { ActivityCardinalInfo lastActivity = profile.getLatestActivity(); - String uniqueNickname = generateUniqueNickname(profile.getName(), lastActivity.getPart()); - SoptampUser newSoptampUser = createNewSoptampUser(userId, uniqueNickname, - lastActivity.getGeneration(), findPlaygroundPart(lastActivity.getPart())); + PlaygroundPart part = lastActivity.getPlaygroundPart(); + String uniqueNickname = generateUniqueNickname(profile.getName(), part); + SoptampUser newSoptampUser = createNewSoptampUser(userId, uniqueNickname, lastActivity.getGeneration(), part); soptampUserRepository.save(newSoptampUser); } @@ -70,8 +71,9 @@ private boolean isGenerationChanged(SoptampUser registeredUser, Long profileGene return !registeredUser.getGeneration().equals(profileGeneration); } - private String generateUniqueNickname(String nickname, String part) { - StringBuilder uniqueNickname = new StringBuilder().append(part).append(nickname); + private String generateUniqueNickname(String nickname, PlaygroundPart part) { + String prefixPartName = part.getShortedPartName(); + StringBuilder uniqueNickname = new StringBuilder().append(prefixPartName).append(nickname); if (soptampUserRepository.existsByNickname(uniqueNickname.toString())) { return addSuffixToNickname(uniqueNickname); } diff --git a/src/main/java/org/sopt/app/domain/enums/PlaygroundPart.java b/src/main/java/org/sopt/app/domain/enums/PlaygroundPart.java index 7b23cf88..b2f67212 100755 --- a/src/main/java/org/sopt/app/domain/enums/PlaygroundPart.java +++ b/src/main/java/org/sopt/app/domain/enums/PlaygroundPart.java @@ -7,20 +7,35 @@ @AllArgsConstructor @Getter public enum PlaygroundPart { + PRESIDENT("회장", "회장"), + VICE_PRESIDENT("부회장", "부회장"), + GENERAL_AFFAIR("총무", "총무"), + MEDIA_TEAM_LEADER("미디어 팀장", "미팀장"), + OPERATIONS_TEAM_LEADER("운영 팀장", "운팀장"), + MAKERS_TEAM_LEADER("메이커스 팀장", "메팀장"), + PLAN("기획", "기획"), + PLAN_PART_LEADER("기획 파트장", "기획파트장"), DESIGN("디자인", "디자인"), + DESIGN_PART_LEADER("디자인 파트장", "디자인파트장"), ANDROID("안드로이드", "안드"), + ANDROID_PART_LEADER("안드로이드 파트장", "안드파트장"), IOS("iOS", "아요"), + IOS_PART_LEADER("iOS 파트장", "아요파트장"), WEB("웹", "웹"), + WEB_PART_LEADER("웹 파트장", "웹파트장"), SERVER("서버", "서버"), + SERVER_PART_LEADER("서버 파트장", "서버파트장"), + // 파트장이 솝탬프 파트별 랭킹에 관여할 수 있으려면 각 파트의 shortedPartName이 접두사로 필요하다 + NONE("미상", "선배"), ; final String partName; - final String soptampNickname; + final String shortedPartName; - public static PlaygroundPart findPlaygroundPart(String partName) { + public static PlaygroundPart findPlaygroundPartByPartName(String partName) { return Arrays.stream(PlaygroundPart.values()) - .filter(playgroundPart -> playgroundPart.soptampNickname.equals(partName)) + .filter(playgroundPart -> playgroundPart.partName.equals(partName)) .findAny() .orElse(PlaygroundPart.NONE); } diff --git a/src/main/java/org/sopt/app/facade/AuthFacade.java b/src/main/java/org/sopt/app/facade/AuthFacade.java index 99fa3b86..610f9840 100755 --- a/src/main/java/org/sopt/app/facade/AuthFacade.java +++ b/src/main/java/org/sopt/app/facade/AuthFacade.java @@ -28,16 +28,19 @@ public AppAuthResponse loginWithPlayground(CodeRequest codeRequest) { PlaygroundProfile playgroundProfile = playgroundAuthService.getPlaygroundMemberProfile( playgroundToken, playgroundInfo.getId() ); + Long latestGeneration = playgroundProfile.getLatestActivity().getGeneration(); Long userId = userService.upsertUser(LoginInfo.of(playgroundInfo, playgroundToken)); - soptampUserService.upsertSoptampUser(playgroundProfile, userId); + if(playgroundAuthService.isCurrentGeneration(latestGeneration)){ + soptampUserService.upsertSoptampUser(playgroundProfile, userId); + } AppToken appToken = jwtTokenService.issueNewTokens(userId, playgroundInfo.getId()); return AppAuthResponse.builder() .playgroundToken(playgroundToken) .accessToken(appToken.getAccessToken()) .refreshToken(appToken.getRefreshToken()) - .status(playgroundAuthService.getStatus(playgroundProfile.getLatestActivity().getGeneration())) + .status(playgroundAuthService.getStatus(latestGeneration)) .build(); } diff --git a/src/main/java/org/sopt/app/facade/PokeFacade.java b/src/main/java/org/sopt/app/facade/PokeFacade.java index fb8dca4f..bb88b48d 100755 --- a/src/main/java/org/sopt/app/facade/PokeFacade.java +++ b/src/main/java/org/sopt/app/facade/PokeFacade.java @@ -131,8 +131,8 @@ public List getFriend(User user) { friendProfile.getProfileImage(), friendProfile.getName(), "", - friendProfile.getActivities().get(0).getGeneration(), - friendProfile.getActivities().get(0).getPart(), + friendProfile.getActivities().getFirst().getGeneration(), + friendProfile.getActivities().getFirst().getPlaygroundPart().getPartName(), friendRelationInfo.getPokeNum(), friendRelationInfo.getRelationName(), createMutualFriendNames(user.getId(), friendId), @@ -245,7 +245,7 @@ private PokeInfo.PokedUserInfo getFriendUserInfo(User user, Long friendUserId) { .name(pokedUserPlaygroundProfile.getName()) .profileImage(pokedUserPlaygroundProfile.getProfileImage()) .generation(latestActivity.getGeneration()) - .part(latestActivity.getPart()) + .part(latestActivity.getPlaygroundPart().getPartName()) .relation(relationInfo) .mutualFriendNames(mutualFriendNames) .build(); diff --git a/src/test/java/org/sopt/app/application/SoptampUserServiceTest.java b/src/test/java/org/sopt/app/application/SoptampUserServiceTest.java index ccec1ccb..f83835ef 100755 --- a/src/test/java/org/sopt/app/application/SoptampUserServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampUserServiceTest.java @@ -28,7 +28,6 @@ import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.domain.entity.soptamp.SoptampUser; -import org.sopt.app.domain.enums.PlaygroundPart; import org.sopt.app.interfaces.postgres.SoptampUserRepository; @ExtendWith(MockitoExtension.class) @@ -124,7 +123,7 @@ void SUCCESS_upsertSoptampUserIfEmpty() { Long userId = 1L; //when soptampUserService.upsertSoptampUser(profile, userId); - String expectedNickname = profile.getLatestActivity().getPart() + profile.getName(); + String expectedNickname = profile.getLatestActivity().getPlaygroundPart().getShortedPartName()+ profile.getName(); //then ArgumentCaptor captor = ArgumentCaptor.forClass(SoptampUser.class); @@ -132,7 +131,8 @@ void SUCCESS_upsertSoptampUserIfEmpty() { verify(soptampUserRepository, times(1)).save(captor.capture()); assertThat(captor.getValue().getUserId()).isEqualTo(userId); assertThat(captor.getValue().getNickname()).isEqualTo(expectedNickname); - assertThat(captor.getValue().getPart().getPartName()).isEqualTo(profile.getLatestActivity().getPart()); + assertThat(captor.getValue().getPart().getPartName()) + .isEqualTo(profile.getLatestActivity().getPlaygroundPart().getPartName()); assertThat(captor.getValue().getGeneration()).isEqualTo(profile.getLatestActivity().getGeneration()); } @@ -145,14 +145,17 @@ void SUCCESS_upsertSoptampUserIfEmpty() { .activities(List.of(new ActivityCardinalInfo("35,서버"))) .build(); given(soptampUserRepository.findByUserId(anyLong())).willReturn(Optional.empty()); - given(soptampUserRepository.existsByNickname(profile.getLatestActivity().getPart() + profile.getName())) + given(soptampUserRepository.existsByNickname( + profile.getLatestActivity().getPlaygroundPart().getShortedPartName() + profile.getName())) .willReturn(true); - given(soptampUserRepository.existsByNickname(profile.getLatestActivity().getPart() + profile.getName() + 'A')) + given(soptampUserRepository.existsByNickname( + profile.getLatestActivity().getPlaygroundPart().getShortedPartName() + profile.getName() + 'A')) .willReturn(true); //when soptampUserService.upsertSoptampUser(profile, userId); - String expectedNickname = profile.getLatestActivity().getPart() + profile.getName() + 'B'; + String expectedNickname = + profile.getLatestActivity().getPlaygroundPart().getShortedPartName() + profile.getName() + 'B'; //then ArgumentCaptor captor = ArgumentCaptor.forClass(SoptampUser.class); @@ -160,7 +163,8 @@ void SUCCESS_upsertSoptampUserIfEmpty() { verify(soptampUserRepository, times(1)).save(captor.capture()); assertThat(captor.getValue().getUserId()).isEqualTo(userId); assertThat(captor.getValue().getNickname()).isEqualTo(expectedNickname); - assertThat(captor.getValue().getPart().getPartName()).isEqualTo(profile.getLatestActivity().getPart()); + assertThat(captor.getValue().getPart().getPartName()) + .isEqualTo(profile.getLatestActivity().getPlaygroundPart().getPartName()); assertThat(captor.getValue().getGeneration()).isEqualTo(profile.getLatestActivity().getGeneration()); }