Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ public record SoptActivities(
String team
){
}

/**
* generation 최댓값 기준으로 최신 활동을 찾아 반환.
* lastGeneration 필드와 관계없이 계산.
*/
public SoptActivities getLatestActivity() {
if (soptActivities == null) return null;
return soptActivities.stream()
.max(java.util.Comparator.comparingInt(SoptActivities::generation))
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class PokeMessageService {
private static final int MESSAGES_QUANTITY_AT_ONCE = 4;
private static final String MESSAGES_HEADER_FOR_POKE = "함께 보낼 메시지를 선택해주세요";
private static final String MESSAGES_HEADER_FOR_REPLY = "답장하고 싶은 메시지를 선택해주세요";
// TODO : 추후 고정 메세지 db에서 관리하도록 변경
private static final String FIXED_MESSAGE = "콕 \uD83D\uDC48";
private final PokeMessageRepository messageRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.util.*;
import lombok.*;

import org.sopt.app.application.platform.dto.PlatformUserInfoResponse;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.ActivityCardinalInfo;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile;
import org.sopt.app.application.rank.CachedUserInfo;
Expand Down Expand Up @@ -43,37 +45,40 @@ public SoptampUserInfo editProfileMessage(Long userId, String profileMessage) {
}

@Transactional
public void upsertSoptampUser(PlaygroundProfile profile, Long userId) {
public void upsertSoptampUser(PlatformUserInfoResponse profile, Long userId) {
if (profile == null) return;
var latest = profile.getLatestActivity();
if (latest == null) return;

Optional<SoptampUser> user = soptampUserRepository.findByUserId(userId);
if (user.isEmpty()) {
this.createSoptampUser(profile, userId);
this.createSoptampUser(profile, userId, latest);
return;
}
SoptampUser registeredUser = user.get();
if(this.isGenerationChanged(registeredUser, profile.getLatestActivity().getGeneration())) {
updateSoptampUser(registeredUser, profile);
if(this.isGenerationChanged(registeredUser, (long)profile.lastGeneration())) {
updateSoptampUser(registeredUser, profile, latest);
}
}

private void updateSoptampUser(SoptampUser registeredUser, PlaygroundProfile profile){
ActivityCardinalInfo lastActivity = profile.getLatestActivity();
private void updateSoptampUser(SoptampUser registeredUser, PlatformUserInfoResponse profile, PlatformUserInfoResponse.SoptActivities latest){
Long userId = registeredUser.getUserId();
String newNickname = generateUniqueNickname(profile.getName(), lastActivity.getPlaygroundPart());
String part = latest.part() == null ? "미상" : latest.part();
String newNickname = generateUniqueNickname(profile.name(), part);
registeredUser.initTotalPoints();
registeredUser.updateChangedGenerationInfo(
lastActivity.getGeneration(),
findPlaygroundPartByPartName(lastActivity.getPlaygroundPart().getPartName()),
newNickname
(long)profile.lastGeneration(),
findPlaygroundPartByPartName(part),
newNickname
);
rankCacheService.removeRank(userId);
rankCacheService.createNewRank(userId);
}

private void createSoptampUser(PlaygroundProfile profile, Long userId) {
ActivityCardinalInfo lastActivity = profile.getLatestActivity();
PlaygroundPart part = lastActivity.getPlaygroundPart();
String uniqueNickname = generateUniqueNickname(profile.getName(), part);
SoptampUser newSoptampUser = createNewSoptampUser(userId, uniqueNickname, lastActivity.getGeneration(), part);
private void createSoptampUser(PlatformUserInfoResponse profile, Long userId, PlatformUserInfoResponse.SoptActivities latest) {
String part = latest.part() == null ? "미상" : latest.part();
String uniqueNickname = generateUniqueNickname(profile.name(), part);
SoptampUser newSoptampUser = createNewSoptampUser(userId, uniqueNickname, (long)profile.lastGeneration(), findPlaygroundPartByPartName(part));
soptampUserRepository.save(newSoptampUser);
rankCacheService.createNewRank(userId);
}
Expand All @@ -82,8 +87,8 @@ private boolean isGenerationChanged(SoptampUser registeredUser, Long profileGene
return !registeredUser.getGeneration().equals(profileGeneration);
}

private String generateUniqueNickname(String nickname, PlaygroundPart part) {
String prefixPartName = part.getShortedPartName();
private String generateUniqueNickname(String nickname, String part) {
String prefixPartName = "iOS".equalsIgnoreCase(part) ? "아요" : part;
StringBuilder uniqueNickname = new StringBuilder().append(prefixPartName).append(nickname);
if (soptampUserRepository.existsByNickname(uniqueNickname.toString())) {
return addSuffixToNickname(uniqueNickname);
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/sopt/app/facade/HomeFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import org.sopt.app.application.meeting.MeetingResponse;
import org.sopt.app.application.meeting.MeetingService;
import org.sopt.app.application.platform.PlatformService;
import org.sopt.app.application.platform.dto.PlatformUserInfoResponse;
import org.sopt.app.application.playground.PlaygroundAuthService;
import org.sopt.app.application.playground.dto.PlaygroundPopularPost;
import org.sopt.app.application.playground.dto.PlaygroundRecentPost;
import org.sopt.app.application.soptamp.SoptampUserService;
import org.sopt.app.common.config.OperationConfig;
import org.sopt.app.common.config.OperationConfigCategory;
import org.sopt.app.common.utils.ActivityDurationCalculator;
Expand Down Expand Up @@ -48,6 +50,7 @@ public class HomeFacade {
private final MeetingService meetingService;
private final OperationConfigService operationConfigService;
private final PlatformService platformService;
private final SoptampUserService soptampUserService;

// TODO : deprecated 된것으로 인지
// @Transactional(readOnly = true)
Expand All @@ -66,13 +69,18 @@ public HomeDescriptionResponse getHomeMainDescription(Long userId) {
duration
);
}
@Transactional(readOnly = true)

@Transactional
public List<AppServiceEntryStatusResponse> checkAppServiceEntryStatus(Long userId) {
if(userId == null){
return this.getOnlyAppServiceInfo();
}
UserStatus status = platformService.getStatus(userId);

// TODO : 추후 유저 생성 api response 변경해 생성 api 쪽에서 soptamp user upsert 하도록 변경
PlatformUserInfoResponse platformUserInfo = platformService.getPlatformUserInfoResponse(userId);
soptampUserService.upsertSoptampUser(platformUserInfo, userId);

return appServiceService.getAllAppService().stream()
.filter(appServiceInfo -> isServiceVisibleToUser(appServiceInfo, status))
.map(appServiceInfo -> appServiceBadgeService.getAppServiceEntryStatusResponse(
Expand All @@ -88,13 +96,13 @@ private List<AppServiceEntryStatusResponse> getOnlyAppServiceInfo() {
}

private boolean isServiceVisibleToUser(AppServiceInfo appServiceInfo, UserStatus status) {
if (appServiceInfo == null || status == null) return false;
if (status == UserStatus.ACTIVE) {
return appServiceInfo.getActiveUser();
}
if (status == UserStatus.INACTIVE) {
return appServiceInfo.getInactiveUser();
}

return false;
}

Expand Down