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

refactor [#167] 유저 정보 조회 API - 컨트롤러 계층에서 url 생성하도록 리펙토링 #168

Merged
merged 1 commit into from
Jan 23, 2025
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 @@ -7,6 +7,7 @@
import org.sopt.confeti.global.common.BaseResponse;
import org.sopt.confeti.global.message.SuccessMessage;
import org.sopt.confeti.global.util.ApiResponseUtil;
import org.sopt.confeti.global.util.S3FileHandler;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -19,11 +20,11 @@
public class UserInfoController {

private final UserInfoFacade userInfoFacade;
private final S3FileHandler s3FileHandler;

@GetMapping
public ResponseEntity<BaseResponse<?>> getUserInfo(@RequestHeader("Authorization") Long userId) {
public ResponseEntity<BaseResponse<?>> getUserInfo(@RequestHeader("Authorization") long userId) {
UserInfoDTO userInfo = userInfoFacade.getUserInfo(userId);
UserInfoResponse user = UserInfoResponse.from(userInfo);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, user);
return ApiResponseUtil.success(SuccessMessage.SUCCESS, UserInfoResponse.of(userInfo, s3FileHandler));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.sopt.confeti.api.user.dto.response;

import org.sopt.confeti.api.user.facade.dto.response.UserInfoDTO;
import org.sopt.confeti.global.util.S3FileHandler;

public record UserInfoResponse (
Long userId,
String profileUrl,
String username
) {
public static UserInfoResponse from (UserInfoDTO userInfoDTO) {
return new UserInfoResponse(userInfoDTO.userId(), userInfoDTO.profileUrl(), userInfoDTO.username());
public static UserInfoResponse of(final UserInfoDTO userInfoDTO, final S3FileHandler s3FileHandler) {
return new UserInfoResponse(
userInfoDTO.userId(),
s3FileHandler.getFileUrl(userInfoDTO.profilePath()),
userInfoDTO.username()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class UserInfoFacade {

@Transactional
public UserInfoDTO getUserInfo(Long userId) {
User user = userService.findById(userId);
return UserInfoDTO.from(user);
return UserInfoDTO.from(
userService.findById(userId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

import org.sopt.confeti.domain.user.User;

public record UserInfoDTO (Long userId, String profileUrl, String username){
public static UserInfoDTO from (User user) {
return new UserInfoDTO(user.getId(), user.getProfilePath(), user.getUsername());
public record UserInfoDTO (
long userId,
String profilePath,
String username
){
public static UserInfoDTO from (final User user) {
return new UserInfoDTO(
user.getId(),
user.getProfilePath(),
user.getUsername()
);
}
}