33import static org .sopt .app .domain .entity .soptamp .SoptampUser .createNewSoptampUser ;
44import static org .sopt .app .domain .enums .SoptPart .findSoptPartByPartName ;
55
6- import java .util .*;
7-
6+ import java .util .List ;
7+ import java .util .Optional ;
8+ import lombok .RequiredArgsConstructor ;
89import org .sopt .app .application .platform .dto .PlatformUserInfoResponse ;
910import org .sopt .app .application .rank .CachedUserInfo ;
1011import org .sopt .app .application .rank .RankCacheService ;
2021import org .springframework .stereotype .Service ;
2122import org .springframework .transaction .annotation .Transactional ;
2223
23- import lombok .RequiredArgsConstructor ;
24-
2524@ Service
2625@ RequiredArgsConstructor
2726public class SoptampUserService {
@@ -47,7 +46,8 @@ public SoptampUserInfo editProfileMessage(Long userId, String profileMessage) {
4746 SoptampUser soptampUser = soptampUserRepository .findByUserId (userId )
4847 .orElseThrow (() -> new BadRequestException (ErrorCode .USER_NOT_FOUND ));
4948 soptampUser .updateProfileMessage (profileMessage );
50- rankCacheService .updateCachedUserInfo (soptampUser .getUserId (), CachedUserInfo .of (SoptampUserInfo .of (soptampUser )));
49+ rankCacheService .updateCachedUserInfo (soptampUser .getUserId (),
50+ CachedUserInfo .of (SoptampUserInfo .of (soptampUser )));
5151 return SoptampUserInfo .of (soptampUser );
5252 }
5353
@@ -58,52 +58,61 @@ public SoptampUserInfo editProfileMessage(Long userId, String profileMessage) {
5858 public void upsertSoptampUser (PlatformUserInfoResponse profile , Long userId ) {
5959 if (profile == null )
6060 return ;
61- var latest = profile .getLatestActivity ();
62- if (latest == null )
63- return ;
6461
6562 if (appjamMode ) {
63+ var latest = profile .getLatestActivity ();
64+ if (latest == null ) {
65+ return ;
66+ }
6667 upsertSoptampUserForAppjam (profile , userId , latest );
6768 } else {
68- upsertSoptampUserNormal (profile , userId , latest );
69+ var latestSopt = profile .getLatestSoptActivity ();
70+ if (latestSopt == null ) {
71+ return ;
72+ }
73+ upsertSoptampUserNormal (profile , userId , latestSopt );
6974 }
7075 }
7176
7277 /* ==================== NORMAL 시즌용 upsert ==================== */
7378
7479 // 기본 시즌용 upsert (파트 + 이름 기반 닉네임)
7580 private void upsertSoptampUserNormal (PlatformUserInfoResponse profile , Long userId ,
76- PlatformUserInfoResponse .SoptActivities latest ) {
81+ PlatformUserInfoResponse .SoptActivities latest ) {
7782 Optional <SoptampUser > user = soptampUserRepository .findByUserId (userId );
7883 if (user .isEmpty ()) {
7984 this .createSoptampUserNormal (profile , userId , latest );
8085 return ;
8186 }
8287 SoptampUser registeredUser = user .get ();
83- if (this .isGenerationChanged (registeredUser , (long )profile .lastGeneration ())) {
88+ if (this .isGenerationChanged (registeredUser , (long ) profile .lastGeneration ())) {
8489 updateSoptampUserNormal (registeredUser , profile , latest );
8590 }
8691 }
8792
88- private void updateSoptampUserNormal (SoptampUser registeredUser , PlatformUserInfoResponse profile , PlatformUserInfoResponse .SoptActivities latest ){
93+ private void updateSoptampUserNormal (SoptampUser registeredUser , PlatformUserInfoResponse profile ,
94+ PlatformUserInfoResponse .SoptActivities latest ) {
8995 Long userId = registeredUser .getUserId ();
9096 String part = latest .part () == null ? "미상" : latest .part ();
9197 String newNickname = generatePartBasedUniqueNickname (profile .name (), part , userId );
9298
9399 registeredUser .initTotalPoints ();
94100 registeredUser .updateChangedGenerationInfo (
95- (long )profile .lastGeneration (),
96- findSoptPartByPartName (part ),
101+ (long ) profile .lastGeneration (),
102+ findSoptPartByPartName (part ),
97103 newNickname
98104 );
99105 rankCacheService .removeRank (userId );
100106 rankCacheService .createNewRank (userId );
101107 }
102108
103- private void createSoptampUserNormal (PlatformUserInfoResponse profile , Long userId , PlatformUserInfoResponse .SoptActivities latest ) {
104- String part = latest .part () == null ? "미상" : latest .part ();
109+ private void createSoptampUserNormal (PlatformUserInfoResponse profile , Long userId ,
110+ PlatformUserInfoResponse .SoptActivities latestSopt
111+ ) {
112+ String part = latestSopt .part () == null ? "미상" : latestSopt .part ();
105113 String uniqueNickname = generatePartBasedUniqueNickname (profile .name (), part , null );
106- SoptampUser newSoptampUser = createNewSoptampUser (userId , uniqueNickname , (long )profile .lastGeneration (), findSoptPartByPartName (part ));
114+ SoptampUser newSoptampUser = createNewSoptampUser (userId , uniqueNickname , (long ) profile .lastGeneration (),
115+ findSoptPartByPartName (part ));
107116 soptampUserRepository .save (newSoptampUser );
108117 rankCacheService .createNewRank (userId );
109118 }
@@ -115,8 +124,8 @@ private boolean isGenerationChanged(SoptampUser registeredUser, Long profileGene
115124 // ==================== 앱잼 시즌용 upsert ====================
116125
117126 private void upsertSoptampUserForAppjam (PlatformUserInfoResponse profile ,
118- Long userId ,
119- PlatformUserInfoResponse .SoptActivities latest ) {
127+ Long userId ,
128+ PlatformUserInfoResponse .SoptActivities latest ) {
120129 Optional <SoptampUser > userOpt = soptampUserRepository .findByUserId (userId );
121130
122131 if (userOpt .isEmpty ()) {
@@ -137,37 +146,36 @@ private void upsertSoptampUserForAppjam(PlatformUserInfoResponse profile,
137146 String uniqueNickname = generateUniqueNicknameInternal (baseNickname , userId );
138147
139148 String part = latest .part () == null ? "미상" : latest .part ();
140-
149+ // 앱잼 시즌: 파트, Makers 무관 buildAppjamBaseNickname이 자연스럽게 처리
141150 registeredUser .updateChangedGenerationInfo (
142- (long ) profile .lastGeneration (),
143- findSoptPartByPartName (part ),
144- uniqueNickname
145- );
151+ (long ) profile .lastGeneration (),
152+ findSoptPartByPartName (part ),
153+ uniqueNickname
154+ );
146155
147156 // 앱잼 변환 시점에 한 번 포인트 초기화
148157 registeredUser .initTotalPoints ();
149158 }
150159
151160 private void createSoptampUserAppjam (PlatformUserInfoResponse profile ,
152- Long userId ,
153- PlatformUserInfoResponse .SoptActivities latest ) {
161+ Long userId ,
162+ PlatformUserInfoResponse .SoptActivities latest ) {
154163
155164 String baseNickname = buildAppjamBaseNickname (profile , userId );
156165
157166 // 새 유저: 전체에서 중복 검사
158167 String uniqueNickname = generateUniqueNicknameInternal (
159- baseNickname ,
160- null
161- );
168+ baseNickname ,
169+ null
170+ );
162171
163172 String part = latest .part () == null ? "미상" : latest .part ();
164173
165174 SoptampUser newSoptampUser = createNewSoptampUser (
166- userId ,
167- uniqueNickname ,
168- (long ) profile .lastGeneration (),
169- findSoptPartByPartName (part )
170- );
175+ userId ,
176+ uniqueNickname ,
177+ (long ) profile .lastGeneration (),
178+ findSoptPartByPartName (part ));
171179 newSoptampUser .initTotalPoints (); // 새 시즌이니 0점부터
172180
173181 soptampUserRepository .save (newSoptampUser );
@@ -180,8 +188,10 @@ private boolean needsAppjamNicknameMigration(SoptampUser user) {
180188 return true ;
181189 }
182190
183- // SoptPart 기준으로 "서버", "기획" 같은 축약/프리픽스를 모두 검사
191+ // SoptPart 기준으로 "서버", "기획" 같은 축약/프리픽스를 모두 검사 (SOPT 파트만)
184192 for (SoptPart part : SoptPart .values ()) {
193+ if (!part .isSoptPart ())
194+ continue ;
185195 String prefix = part .getShortedPartName ();
186196 if (nickname .startsWith (prefix )) {
187197 // 서버김솝트, 디자인김솝트 등 → 기존 시즌(파트 기반) 닉네임이므로 앱잼 변환 필요
@@ -200,8 +210,8 @@ private boolean needsAppjamNicknameMigration(SoptampUser user) {
200210 */
201211 private String buildAppjamBaseNickname (PlatformUserInfoResponse profile , Long userId ) {
202212 return appjamUserRepository .findByUserId (userId )
203- .map (appjamUser -> appjamUser .getTeamName () + profile .name ())
204- .orElseGet (() -> profile .lastGeneration () + "기" + profile .name ());
213+ .map (appjamUser -> appjamUser .getTeamName () + profile .name ())
214+ .orElseGet (() -> profile .lastGeneration () + "기" + profile .name ());
205215 }
206216
207217 // ==================== 닉네임 유니크 로직 공통부 ====================
@@ -218,7 +228,7 @@ private String generatePartBasedUniqueNickname(String name, String part, Long cu
218228
219229 /**
220230 * baseNickname을 기준으로, 전역 유니크 닉네임 생성
221- * - currentUserIdOrNull == null : 새 유저 생성 (그냥 existsByNickname)
231+ * - currentUserIdOrNull == null : 새 유저 생성 (그냥 existsByNickname)
222232 * - currentUserIdOrNull != null : 내 row는 제외하고 중복 체크
223233 */
224234 private String generateUniqueNicknameInternal (String baseNickname , Long currentUserIdOrNull ) {
0 commit comments