Skip to content

Commit

Permalink
refactor: 사용자 프로필 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
geneaky committed Sep 18, 2024
1 parent 525d43d commit fbb65e8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/main/java/toy/bookchat/bookchat/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ public class User {

private final Long id;
private final String nickname;
private final String email;
private final String profileImageUrl;
private final Integer defaultProfileImageType;

@Builder
public User(Long id, String nickname, String profileImageUrl, Integer defaultProfileImageType) {
public User(Long id, String nickname, String email, String profileImageUrl, Integer defaultProfileImageType) {
this.id = id;
this.nickname = nickname;
this.email = email;
this.profileImageUrl = profileImageUrl;
this.defaultProfileImageType = defaultProfileImageType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import toy.bookchat.bookchat.db_module.user.UserEntity;
import toy.bookchat.bookchat.support.RateLimit;
import toy.bookchat.bookchat.domain.user.UserProfile;
import toy.bookchat.bookchat.domain.user.User;
import toy.bookchat.bookchat.domain.user.api.v1.request.ChangeUserNicknameRequest;
import toy.bookchat.bookchat.domain.user.api.v1.request.UserSignInRequest;
import toy.bookchat.bookchat.domain.user.api.v1.request.UserSignUpRequest;
Expand All @@ -34,6 +33,7 @@
import toy.bookchat.bookchat.security.token.openid.IdTokenManager;
import toy.bookchat.bookchat.security.user.TokenPayload;
import toy.bookchat.bookchat.security.user.UserPayload;
import toy.bookchat.bookchat.support.RateLimit;

@RequiredArgsConstructor

Expand All @@ -55,8 +55,8 @@ public class UserController {
*/
@GetMapping("/users/profile")
public UserProfileResponse userProfile(@UserPayload TokenPayload tokenPayload) {
UserProfile userProfile = userService.findUser(tokenPayload.getUserId());
return UserProfileResponse.of(userProfile);
User user = userService.findUser(tokenPayload.getUserId());
return UserProfileResponse.of(user);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Builder;
import lombok.Getter;
import toy.bookchat.bookchat.domain.user.UserProfile;
import toy.bookchat.bookchat.domain.user.User;

@Getter
@Builder
Expand All @@ -14,13 +14,13 @@ public class UserProfileResponse {
private String userProfileImageUri;
private Integer defaultProfileImageType;

public static UserProfileResponse of(UserProfile userProfile) {
public static UserProfileResponse of(User user) {
return UserProfileResponse.builder()
.userId(userProfile.getUserId())
.userNickname(userProfile.getUserNickname())
.userEmail(userProfile.getUserEmail())
.userProfileImageUri(userProfile.getUserProfileImageUri())
.defaultProfileImageType(userProfile.getDefaultProfileImageType())
.userId(user.getId())
.userNickname(user.getNickname())
.userEmail(user.getEmail())
.userProfileImageUri(user.getProfileImageUrl())
.defaultProfileImageType(user.getDefaultProfileImageType())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public User readUser(Long userId) {
return User.builder()
.id(userEntity.getId())
.nickname(userEntity.getNickname())
.email(userEntity.getEmail())
.profileImageUrl(userEntity.getProfileImageUrl())
.defaultProfileImageType(userEntity.getDefaultProfileImageType())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import toy.bookchat.bookchat.db_module.device.repository.DeviceRepository;
import toy.bookchat.bookchat.db_module.user.UserEntity;
import toy.bookchat.bookchat.db_module.user.repository.UserRepository;
import toy.bookchat.bookchat.infrastructure.s3.StorageService;
import toy.bookchat.bookchat.domain.user.UserProfile;
import toy.bookchat.bookchat.domain.user.User;
import toy.bookchat.bookchat.domain.user.api.v1.request.ChangeUserNicknameRequest;
import toy.bookchat.bookchat.domain.user.api.v1.request.UserSignInRequest;
import toy.bookchat.bookchat.domain.user.api.v1.request.UserSignUpRequest;
Expand All @@ -24,6 +23,7 @@
import toy.bookchat.bookchat.exception.conflict.device.DeviceAlreadyRegisteredException;
import toy.bookchat.bookchat.infrastructure.fcm.PushMessageBody;
import toy.bookchat.bookchat.infrastructure.fcm.service.PushService;
import toy.bookchat.bookchat.infrastructure.s3.StorageService;

@Service
public class UserService {
Expand Down Expand Up @@ -154,8 +154,7 @@ public MemberProfileResponse getMemberProfile(Long memberId) {
}

@Transactional(readOnly = true)
public UserProfile findUser(Long userId) {
UserEntity userEntity = userReader.readUserEntity(userId);
return UserProfile.from(userEntity);
public User findUser(Long userId) {
return userReader.readUser(userId);
}
}

0 comments on commit fbb65e8

Please sign in to comment.