Skip to content

Commit

Permalink
refector: 유저 프로필 조회 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
haroya01 committed Oct 9, 2023
1 parent b7b1c8b commit 4bd1a1d
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 회원가입/로그인을 요청합니다.")
Expand Down Expand Up @@ -82,9 +85,10 @@ public ResponseEntity<HttpStatus> logout() {
@ApiResponse(responseCode = "200", description = "회원 정보 반환"),
@ApiResponse(responseCode = "401", description = "세션 로그인 필요"),
})
public ResponseEntity<User> getMyProfile() {
User logedInUser = this.authenticationService.getLoginUser();
return new ResponseEntity<>(logedInUser, HttpStatus.OK);
public ResponseEntity<UserProfileResponse> getMyProfile() {
User logedInUser = authenticationService.getLoginUser();
UserProfileResponse userProfileResponse = userProfileService.getUserProfile(logedInUser);
return ResponseEntity.ok(userProfileResponse);
}

@GetMapping("phone")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.*;
import megabrain.gyeongnamgyeongmae.domain.user.domain.entity.Address;
import megabrain.gyeongnamgyeongmae.domain.user.domain.entity.User;

@Builder
@Getter
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ private List<Image> findImageByAuctionItemId(Long id) {
public Image findFirstImageByAuctionItemId(Long id) {
return imageRepository.findFirstImageByAuctionItemId(id);
}


@Override
public Image findFirstImageByUserId(Long id) {
return imageRepository.findFirstImageByUserId(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface FindImageServiceInterface {
List<String> findImageByAuctionItemIdBackUrls(Long id);

Image findFirstImageByAuctionItemId(Long id);

Image findFirstImageByUserId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ public interface ImageRepository extends JpaRepository<Image, Long> {
"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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,4 +18,6 @@ AuctionItemSearchResponse findPostAuctionItemIdsByUserId(
CommentSearchResponse findGetLikeCommentByUserId(Long userId, Long page);

AuctionItemSearchResponse findBuyAuctionItemIdsByUserId(Long userId, Long page);

UserProfileResponse getUserProfile(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public interface UserServiceInterface {
List<User> findAllUser();

Address getAddressByCoordinate(Float latitude, Float longitude);

}

0 comments on commit 4bd1a1d

Please sign in to comment.