Skip to content

Commit

Permalink
[FIX] 솝탬프 닉네임 설정 오류 수정 (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
kseysh authored Oct 16, 2024
2 parents c6fb754 + 999880a commit bd9afe7
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private List<SimplePokeProfile> makeSimplePokeProfilesForNotFriend(
playgroundProfile.getProfileImage(),
userProfile.getName(),
playgroundProfile.getLatestActivity().getGeneration(),
playgroundProfile.getLatestActivity().getPart()
playgroundProfile.getLatestActivity().getPlaygroundPart().getPartName()
);
}).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -109,8 +113,8 @@ public Long getGeneration() {
}
}

public String getPart() {
return cardinalInfo.split(",")[1];
public PlaygroundPart getPlaygroundPart() {
return findPlaygroundPartByPartName(cardinalInfo.split(",")[1]);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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;
Expand Down Expand Up @@ -50,28 +51,29 @@ 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);
}

private boolean isGenerationChanged(SoptampUser registeredUser, Long profileGeneration) {
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);
}
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/org/sopt/app/domain/enums/PlaygroundPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/sopt/app/facade/AuthFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/sopt/app/facade/PokeFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public List<SimplePokeProfile> 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),
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 11 additions & 7 deletions src/test/java/org/sopt/app/application/SoptampUserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -124,15 +123,16 @@ 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<SoptampUser> captor = ArgumentCaptor.forClass(SoptampUser.class);
verify(soptampUserRepository, times(1)).existsByNickname(anyString());
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());
}

Expand All @@ -145,22 +145,26 @@ 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<SoptampUser> captor = ArgumentCaptor.forClass(SoptampUser.class);
verify(soptampUserRepository, times(3)).existsByNickname(anyString());
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());
}

Expand Down

0 comments on commit bd9afe7

Please sign in to comment.