-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: dev
Are you sure you want to change the base?
Changes from 5 commits
60b5574
0214a15
a463d50
4dc67dc
4650d69
dfcdef3
9b607fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.sopt.app.application.playground.dto; | ||
|
||
public record PlayGroundUserSoptLevelResponse( | ||
Long id, | ||
String profileImage, | ||
int soptProjectCount | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,17 @@ | |
|
||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.app.application.auth.JwtTokenService; | ||
import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.*; | ||
import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.AppToken; | ||
import org.sopt.app.application.playground.PlaygroundAuthService; | ||
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.*; | ||
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.LoginInfo; | ||
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundMain; | ||
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile; | ||
import org.sopt.app.application.poke.PokeService; | ||
import org.sopt.app.application.soptamp.SoptampUserService; | ||
import org.sopt.app.application.user.UserService; | ||
import org.sopt.app.presentation.auth.AppAuthRequest.*; | ||
import org.sopt.app.domain.entity.User; | ||
import org.sopt.app.presentation.auth.AppAuthRequest.AccessTokenRequest; | ||
import org.sopt.app.presentation.auth.AppAuthRequest.CodeRequest; | ||
import org.sopt.app.presentation.auth.AppAuthResponse; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
@@ -20,6 +25,7 @@ public class AuthFacade { | |
private final UserService userService; | ||
private final PlaygroundAuthService playgroundAuthService; | ||
private final SoptampUserService soptampUserService; | ||
private final PokeService pokeService; | ||
|
||
@Transactional | ||
public AppAuthResponse loginWithPlayground(CodeRequest codeRequest) { | ||
|
@@ -66,4 +72,11 @@ public AppAuthResponse getRefreshToken(String refreshToken) { | |
.build(); | ||
} | ||
|
||
public int getUserSoptLevel(User user) { | ||
return playgroundAuthService.getUserSoptLevel(user); | ||
} | ||
|
||
public PlaygroundProfile getUserDetails(User user) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P4. user를 매개변수로 전달하는 것이 아닌 필요한 playgroundToken만 전달하는 것이 좋을 것 같아요 |
||
return playgroundAuthService.getPlayGroundProfile(user.getPlaygroundToken()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,25 @@ | |
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import jakarta.validation.Valid; | ||
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.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.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v2/user") | ||
|
@@ -28,6 +34,9 @@ public class UserController { | |
|
||
private final SoptampUserService soptampUserService; | ||
private final SoptampFacade soptampFacade; | ||
private final AuthFacade authFacade; | ||
private final PokeFacade pokeFacade; | ||
private final RankFacade rankFacade; | ||
|
||
@Operation(summary = "솝탬프 정보 조회") | ||
@ApiResponses({ | ||
|
@@ -62,4 +71,17 @@ public ResponseEntity<UserResponse.ProfileMessage> editProfileMessage( | |
return ResponseEntity.ok(response); | ||
} | ||
|
||
@Operation(summary = "유저 솝트로그 조회") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "success"), | ||
@ApiResponse(responseCode = "500", description = "server error", content = @Content) | ||
}) | ||
@GetMapping(value = "/sopt-log") | ||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P5. Controller에 비즈니스 로직을 포함하는 것은 @transactional을 사용하기 어려워 Controller에서의 비즈니스 로직 작성을 최대한 피하고 있었는데 기훈님 생각도 궁금합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음 제 생각에는 이 코드는 비즈니스 로직보다는, 각계층별로 데이터를 조회하고 매핑하여 반환하는 역할을 수행하기 때문에 비즈니스 로직보다는 , 응답 매핑 역할을 하는 어플리케이션 코드측에 속한다고 생각합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 흠 그렇군요! 기훈님 의견 들어보고 고민해보는 것도 재밌네용 저는 나중에 반환해야 할 api가 변경될 때도 고려를 했어요. 솝탬프는 이전 기수에서도 사라지려고 했었던 피쳐이기도 하고, 새로운 피쳐가 생기면 새로운 피쳐를 솝트로그에 나타내도록 할 수도 있을 것 같아서요 또한 Transactional(readonly=true)는 롤백 이후에도 변경감지를 위한 스냅샷을 보관하지 않아 메모리상 이점이 있다는 생각을 했는데, 그렇다면 DB 커넥션을 너무 오래 잡고 있는 거려나 생각이 들어서 Transactional에 대해서는 그냥 의견이었습니다! |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,14 @@ | |
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.util.List; | ||
import lombok.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
Comment on lines
+5
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P5. 기존에 사용하던 와일드 카드로 변경하는 것이 가독성에 좋을 것 같아요 |
||
import org.sopt.app.application.app_service.dto.AppServiceInfo; | ||
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile; | ||
import org.sopt.app.domain.enums.PlaygroundPart; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class UserResponse { | ||
|
@@ -103,4 +109,46 @@ public static AppService of(final AppServiceInfo appServiceInfo) { | |
.build(); | ||
} | ||
} | ||
|
||
@Getter | ||
@Builder | ||
public static class SoptLog { | ||
@Schema(description = "유저 이름", example = "차은우") | ||
private String userName; | ||
@Schema(description = "프로필 이미지 url", example = "www.png") | ||
private String profileImage; | ||
@Schema(description = "파트") | ||
private PlaygroundPart part; | ||
@Schema(description = "콕찌르기 횟수") | ||
private String pokeCount; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2. 콕 찌르기, 솝활동, 솝탬프 모두 뒤에 ~등, ~회, LV등을 붙이는 것 클라와 상의 후에 모두 붙이거나, 모두 붙이지 않거나 하는 것이 좋을 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 수정했습니다! |
||
@Schema(description = "", example = "14등") | ||
private String soptampRank; | ||
@Schema(description = "솝력 ", example = "LV.7") | ||
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(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P4. 매개변수가 많은 생성자는 builder 메서드를 활용하는 것이 더 유용할 것 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사용하지 않는 메소드라 제거했습니다 |
||
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(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2. 전부를 map으로 변환하고 찾는 것이 아닌 totalPoint를 이용해 sort된 유저를 1등부터 확인하며 userId와 일치하는 유저를 찾아 반환하는 것이 더 빠르게 순위를 반환하는 방법일 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 좋은 방법이네요 감사합니다!