Skip to content

Commit

Permalink
[fix] API 변경사항 수정 (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarlgnszx committed Nov 30, 2024
1 parent 4650d69 commit dfcdef3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 25 deletions.
23 changes: 23 additions & 0 deletions src/main/java/org/sopt/app/application/user/UserService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.app.application.user;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
Expand All @@ -8,7 +9,10 @@
import org.sopt.app.common.exception.NotFoundException;
import org.sopt.app.common.exception.UnauthorizedException;
import org.sopt.app.common.response.ErrorCode;
import org.sopt.app.domain.entity.Icons;
import org.sopt.app.domain.entity.User;
import org.sopt.app.domain.enums.IconType;
import org.sopt.app.interfaces.postgres.IconRepository;
import org.sopt.app.interfaces.postgres.UserRepository;
import org.sopt.app.presentation.auth.AppAuthRequest.AccessTokenRequest;
import org.springframework.stereotype.Service;
Expand All @@ -21,6 +25,7 @@
public class UserService {

private final UserRepository userRepository;
private final IconRepository iconRepository;

@Transactional
public Long upsertUser(LoginInfo loginInfo) {
Expand Down Expand Up @@ -82,4 +87,22 @@ public List<Long> getAllPlaygroundIds() {
public boolean isUserExist(Long userId) {
return userRepository.existsById(userId);
}

public Long getDuration(Long myGeneration, Long currentGeneration) {
long monthsBetweenGenerations = (currentGeneration - myGeneration) * 6;
LocalDate now = LocalDate.now();
int currentMonth = now.getMonthValue();
int startMonth = (currentGeneration % 2 == 0) ? 3 : 9;
int monthsSinceStart = currentMonth - startMonth;
if (monthsSinceStart < 0) {
monthsSinceStart += 12;
}
return monthsBetweenGenerations + monthsSinceStart;
}

public List<String> getIcons(IconType iconType) {
return iconRepository.findAllByIconType(iconType).stream()
.map(Icons::getIconUrl)
.toList();
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/sopt/app/facade/AuthFacade.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sopt.app.facade;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.sopt.app.application.auth.JwtTokenService;
import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.AppToken;
Expand All @@ -11,6 +12,7 @@
import org.sopt.app.application.soptamp.SoptampUserService;
import org.sopt.app.application.user.UserService;
import org.sopt.app.domain.entity.User;
import org.sopt.app.domain.enums.IconType;
import org.sopt.app.presentation.auth.AppAuthRequest.AccessTokenRequest;
import org.sopt.app.presentation.auth.AppAuthRequest.CodeRequest;
import org.sopt.app.presentation.auth.AppAuthResponse;
Expand Down Expand Up @@ -79,4 +81,12 @@ public int getUserSoptLevel(User user) {
public PlaygroundProfile getUserDetails(User user) {
return playgroundAuthService.getPlayGroundProfile(user.getPlaygroundToken());
}

public Long getDuration(Long Mygeneration, Long generation) {
return userService.getDuration(Mygeneration, generation);
}

public List<String> getIcons(IconType iconType) {
return userService.getIcons(iconType);
}
}
17 changes: 15 additions & 2 deletions src/main/java/org/sopt/app/presentation/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile;
import org.sopt.app.application.soptamp.SoptampUserService;
import org.sopt.app.domain.entity.User;
import org.sopt.app.domain.enums.IconType;
import org.sopt.app.facade.AuthFacade;
import org.sopt.app.facade.PokeFacade;
import org.sopt.app.facade.RankFacade;
import org.sopt.app.facade.SoptampFacade;
import org.sopt.app.presentation.user.UserResponse.SoptLog;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -37,6 +40,8 @@ public class UserController {
private final AuthFacade authFacade;
private final PokeFacade pokeFacade;
private final RankFacade rankFacade;
@Value("${sopt.current.generation}")
private Long generation;

@Operation(summary = "솝탬프 정보 조회")
@ApiResponses({
Expand Down Expand Up @@ -80,8 +85,16 @@ public ResponseEntity<UserResponse.ProfileMessage> editProfileMessage(
public ResponseEntity<UserResponse.SoptLog> getUserSoptLog(@AuthenticationPrincipal User user) {
int soptLevel = authFacade.getUserSoptLevel(user);
Long pokeCount = pokeFacade.getUserPokeCount(user.getId());
Long soptampRank = rankFacade.findUserRank(user.getId());
PlaygroundProfile playgroundProfile = authFacade.getUserDetails(user);
return ResponseEntity.ok(SoptLog.of(soptLevel, pokeCount, soptampRank, playgroundProfile));
Long soptampRank = null;
Long soptDuring = null;
Boolean isActive = playgroundProfile.getLatestActivity().getGeneration() == generation;
if (isActive) {
soptampRank = rankFacade.findUserRank(user.getId());
} else {
soptDuring = authFacade.getDuration(playgroundProfile.getLatestActivity().getGeneration(), generation);
}
List<String> icons = authFacade.getIcons(isActive ? IconType.ACTIVE : IconType.INACTIVE);
return ResponseEntity.ok(SoptLog.of(soptLevel, pokeCount, soptampRank, soptDuring,isActive,icons, playgroundProfile));
}
}
44 changes: 21 additions & 23 deletions src/main/java/org/sopt/app/presentation/user/UserResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,26 @@ public static class SoptLog {
private String soptLevel;
@Schema(description = "유저 소개", example = "false")
private String profileMessage;

public static SoptLog of(final String userName, final String profileImage, final PlaygroundPart part, final String pokeCount, final String soptampRank, final String soptLevel, final String profileMessage) {
return SoptLog.builder()
.userName(userName)
.profileImage(profileImage)
.part(part)
.pokeCount(pokeCount)
.soptampRank(soptampRank)
.soptLevel(soptLevel)
.profileMessage(profileMessage)
.build();
}
public static SoptLog of(int soptLevel, Long pokeCount, Long soptampRank, PlaygroundProfile playgroundProfile) {
return SoptLog.builder()
.soptLevel("LV." + soptLevel)
.pokeCount(pokeCount.toString())
.soptampRank(soptampRank.toString())
.userName(playgroundProfile.getName())
.profileImage(playgroundProfile.getProfileImage())
.part(playgroundProfile.getLatestActivity().getPlaygroundPart())
.profileMessage(playgroundProfile.getIntroduction())
.build();
}
@Schema(description = "솝트와", example = "37개월")
private String during;
private List<String> icons;
private Boolean isActive;

public static SoptLog of(int soptLevel, Long pokeCount, Long soptampRank, Long during, Boolean isActive,
List<String> icons,
PlaygroundProfile playgroundProfile) {
return SoptLog.builder()
.soptLevel("Lv." + soptLevel)
.pokeCount(pokeCount + "회")
.soptampRank(soptampRank != null ? soptampRank +"등" : null)
.userName(playgroundProfile.getName())
.profileImage(playgroundProfile.getProfileImage())
.part(playgroundProfile.getLatestActivity().getPlaygroundPart())
.profileMessage(playgroundProfile.getIntroduction())
.during(during != null ? during + "개월": null)
.isActive(isActive)
.icons(icons)
.build();
}
}
}

0 comments on commit dfcdef3

Please sign in to comment.