Skip to content

Commit

Permalink
refactor [#167] 컨트롤러 계층에서 url 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1hyun committed Jan 23, 2025
1 parent 8e45b03 commit 0c92c72
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
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()
);
}
}

0 comments on commit 0c92c72

Please sign in to comment.