From 4bd1a1d1d92f9dc86ef1ba73391cc4806fbb995b Mon Sep 17 00:00:00 2001 From: haroya01 Date: Tue, 10 Oct 2023 04:07:25 +0900 Subject: [PATCH] =?UTF-8?q?refector:=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=A1=B0=ED=9A=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuthenticationController.java | 10 +++++++--- .../dto/UserProfileResponse.java | 18 ++++++++++++++++++ .../AuthenticationServiceInterface.java | 1 + .../domain/image/Service/FindImageService.java | 6 ++++++ .../Service/FindImageServiceInterface.java | 2 ++ .../domain/repository/ImageRepository.java | 6 ++++++ .../user/service/UserProfileService.java | 13 +++++++++++++ .../service/UserProfileServiceInterface.java | 4 ++++ .../user/service/UserServiceInterface.java | 1 + 9 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/controller/AuthenticationController.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/controller/AuthenticationController.java index a5a0c65..cb6de98 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/controller/AuthenticationController.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/controller/AuthenticationController.java @@ -9,9 +9,11 @@ import lombok.RequiredArgsConstructor; import megabrain.gyeongnamgyeongmae.domain.authentication.domain.entity.OAuthVendorName; import megabrain.gyeongnamgyeongmae.domain.authentication.dto.PhoneAuthenticationRequest; +import megabrain.gyeongnamgyeongmae.domain.authentication.dto.UserProfileResponse; import megabrain.gyeongnamgyeongmae.domain.authentication.dto.UserRegisterRequest; import megabrain.gyeongnamgyeongmae.domain.authentication.service.AuthenticationServiceInterface; import megabrain.gyeongnamgyeongmae.domain.user.domain.entity.User; +import megabrain.gyeongnamgyeongmae.domain.user.service.UserProfileServiceInterface; import megabrain.gyeongnamgyeongmae.domain.user.service.UserServiceInterface; import megabrain.gyeongnamgyeongmae.global.anotation.LoginRequired; import org.springframework.http.HttpStatus; @@ -25,6 +27,7 @@ public class AuthenticationController { private final AuthenticationServiceInterface authenticationService; private final UserServiceInterface userService; + private final UserProfileServiceInterface userProfileService; @PostMapping("register/{auth-vendor}") @Operation(summary = "회원가입/로그인 요청", description = "회원의 OAuth 회원가입/로그인을 요청합니다.") @@ -82,9 +85,10 @@ public ResponseEntity logout() { @ApiResponse(responseCode = "200", description = "회원 정보 반환"), @ApiResponse(responseCode = "401", description = "세션 로그인 필요"), }) - public ResponseEntity getMyProfile() { - User logedInUser = this.authenticationService.getLoginUser(); - return new ResponseEntity<>(logedInUser, HttpStatus.OK); + public ResponseEntity getMyProfile() { + User logedInUser = authenticationService.getLoginUser(); + UserProfileResponse userProfileResponse = userProfileService.getUserProfile(logedInUser); + return ResponseEntity.ok(userProfileResponse); } @GetMapping("phone") diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/dto/UserProfileResponse.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/dto/UserProfileResponse.java index e88b44e..5b3a3cb 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/dto/UserProfileResponse.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/dto/UserProfileResponse.java @@ -2,6 +2,7 @@ import lombok.*; import megabrain.gyeongnamgyeongmae.domain.user.domain.entity.Address; +import megabrain.gyeongnamgyeongmae.domain.user.domain.entity.User; @Builder @Getter @@ -13,4 +14,21 @@ public class UserProfileResponse { private String nickname; private String introduce; private Address address; + + private String profileImageUrl; + + public static UserProfileResponse of(User user) { + return UserProfileResponse.builder() + .id(user.getId()) + .phoneNumber(user.getPhoneNumber()) + .nickname(user.getNickname()) + .introduce(user.getIntroduce()) + .address(user.getAddress()) + .profileImageUrl("https://yt3.ggpht.com/a/default-user=s88-c-k-c0x00ffffff-no-rj") + .build(); + } + + public void setNewImageUrl(String newImageUrl) { + this.profileImageUrl = newImageUrl; + } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/service/AuthenticationServiceInterface.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/service/AuthenticationServiceInterface.java index 8f712b2..081ed08 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/service/AuthenticationServiceInterface.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/authentication/service/AuthenticationServiceInterface.java @@ -2,6 +2,7 @@ import megabrain.gyeongnamgyeongmae.domain.authentication.domain.entity.OAuthUserProfile; import megabrain.gyeongnamgyeongmae.domain.authentication.domain.entity.OAuthVendorName; +import megabrain.gyeongnamgyeongmae.domain.authentication.dto.UserProfileResponse; import megabrain.gyeongnamgyeongmae.domain.user.domain.entity.User; public interface AuthenticationServiceInterface { diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/Service/FindImageService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/Service/FindImageService.java index 0d3e44d..1fef58d 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/Service/FindImageService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/Service/FindImageService.java @@ -31,4 +31,10 @@ private List findImageByAuctionItemId(Long id) { public Image findFirstImageByAuctionItemId(Long id) { return imageRepository.findFirstImageByAuctionItemId(id); } + + + @Override + public Image findFirstImageByUserId(Long id) { + return imageRepository.findFirstImageByUserId(id); + } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/Service/FindImageServiceInterface.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/Service/FindImageServiceInterface.java index 45940fe..fd35f83 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/Service/FindImageServiceInterface.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/Service/FindImageServiceInterface.java @@ -9,4 +9,6 @@ public interface FindImageServiceInterface { List findImageByAuctionItemIdBackUrls(Long id); Image findFirstImageByAuctionItemId(Long id); + + Image findFirstImageByUserId(Long id); } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/domain/repository/ImageRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/domain/repository/ImageRepository.java index 7159cf4..579a072 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/domain/repository/ImageRepository.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/image/domain/repository/ImageRepository.java @@ -19,4 +19,10 @@ public interface ImageRepository extends JpaRepository { "SELECT * FROM images where auction_id = :id AND removed = FALSE ORDER BY created_at ASC LIMIT 1 ", nativeQuery = true) Image findFirstImageByAuctionItemId(Long id); + + @Query( + value = + "SELECT * FROM images where user_id = :id AND removed = FALSE ", + nativeQuery = true) + Image findFirstImageByUserId(Long id); } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserProfileService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserProfileService.java index 6ab0185..af070e5 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserProfileService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserProfileService.java @@ -16,7 +16,10 @@ import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Comment.AuctionItemCommentService; import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Item.AuctionItemService; import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Search.AuctionItemSearchService; +import megabrain.gyeongnamgyeongmae.domain.authentication.dto.UserProfileResponse; import megabrain.gyeongnamgyeongmae.domain.image.Service.FindImageServiceInterface; +import megabrain.gyeongnamgyeongmae.domain.image.domain.entity.Image; +import megabrain.gyeongnamgyeongmae.domain.user.domain.entity.User; import megabrain.gyeongnamgyeongmae.domain.user.dto.UserItemSearchDto; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -108,4 +111,14 @@ public AuctionItemSearchResponse findBuyAuctionItemIdsByUserId(Long userId, Long SearchItemDto searchItemDto = SearchItemDto.builder().user_id(userId).page(page).build(); return auctionItemSearchService.findAuctionItemByRequest(searchItemDto); } + + @Override + public UserProfileResponse getUserProfile(User user) { + Image image = findImageService.findFirstImageByUserId(user.getId()); + UserProfileResponse userProfile = UserProfileResponse.of(user); + if (image != null) { + userProfile.setNewImageUrl(image.getImageUrl()); + } + return userProfile; + } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserProfileServiceInterface.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserProfileServiceInterface.java index d0d2ae5..af3834c 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserProfileServiceInterface.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserProfileServiceInterface.java @@ -2,6 +2,8 @@ import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.Comment.CommentSearchResponse; import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemSearchResponse; +import megabrain.gyeongnamgyeongmae.domain.authentication.dto.UserProfileResponse; +import megabrain.gyeongnamgyeongmae.domain.user.domain.entity.User; import megabrain.gyeongnamgyeongmae.domain.user.dto.UserItemSearchDto; import megabrain.gyeongnamgyeongmae.domain.user.dto.UserProfile.SearchByUserDto; @@ -16,4 +18,6 @@ AuctionItemSearchResponse findPostAuctionItemIdsByUserId( CommentSearchResponse findGetLikeCommentByUserId(Long userId, Long page); AuctionItemSearchResponse findBuyAuctionItemIdsByUserId(Long userId, Long page); + + UserProfileResponse getUserProfile(User user); } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserServiceInterface.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserServiceInterface.java index 5886625..938b27f 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserServiceInterface.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/user/service/UserServiceInterface.java @@ -22,4 +22,5 @@ public interface UserServiceInterface { List findAllUser(); Address getAddressByCoordinate(Float latitude, Float longitude); + }