Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 솝트 로그 API 개발 - #437 #459

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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;
}
Comment on lines +91 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. 현재 홈화면에서 사용되는 ActivityDurationCalculator 사용하면 될 것 같습니다!


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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4. user를 매개변수로 전달하는 것이 아닌 필요한 playgroundToken만 전달하는 것이 좋을 것 같아요

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;
Comment on lines +89 to +90
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. Long 값을 null로 전달하는 것보다 isActive 값에 따라서 ResponseEntity를 return하는 것이 좋아보여요.
팩토리 메서드 패턴을 이용해서 클라에 전달할 때만 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();
}
}
}