diff --git a/lombok.config b/lombok.config index 8f7e8aa1..9b93073a 100644 --- a/lombok.config +++ b/lombok.config @@ -1 +1,2 @@ -lombok.addLombokGeneratedAnnotation = true \ No newline at end of file +lombok.addLombokGeneratedAnnotation = true +lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Qualifier \ No newline at end of file diff --git a/src/main/java/toy/bookchat/bookchat/domain/bookshelf/api/v1/request/CreateBookShelfRequest.java b/src/main/java/toy/bookchat/bookchat/domain/bookshelf/api/v1/request/CreateBookShelfRequest.java index a3298c1d..adba504f 100644 --- a/src/main/java/toy/bookchat/bookchat/domain/bookshelf/api/v1/request/CreateBookShelfRequest.java +++ b/src/main/java/toy/bookchat/bookchat/domain/bookshelf/api/v1/request/CreateBookShelfRequest.java @@ -68,10 +68,12 @@ public BookShelf toTarget() { return BookShelf.builder() .readingStatus(this.readingStatus) .star(this.star) + .pages(0) .build(); } return BookShelf.builder() .readingStatus(this.readingStatus) + .pages(0) .build(); } } diff --git a/src/main/java/toy/bookchat/bookchat/domain/user/api/v1/UserController.java b/src/main/java/toy/bookchat/bookchat/domain/user/api/v1/UserController.java index 30b2bc37..2ba7d6e8 100644 --- a/src/main/java/toy/bookchat/bookchat/domain/user/api/v1/UserController.java +++ b/src/main/java/toy/bookchat/bookchat/domain/user/api/v1/UserController.java @@ -100,8 +100,7 @@ public void userSignUp(@Valid @RequestPart UserSignUpRequest userSignUpRequest, @RequestHeader(OIDC) @NotBlank @Pattern(regexp = "^(Bearer)\\s.+") String bearerToken) { String oauth2MemberNumber = idTokenManager.getOAuth2MemberNumberFromIdToken(bearerToken, userSignUpRequest.getOauth2Provider()); - String userEmail = idTokenManager.getUserEmailFromToken(bearerToken, - userSignUpRequest.getOauth2Provider()); + String userEmail = idTokenManager.getUserEmailFromToken(bearerToken, userSignUpRequest.getOauth2Provider()); userService.registerNewUser(userSignUpRequest, userProfileImage, oauth2MemberNumber, userEmail); } diff --git a/src/main/java/toy/bookchat/bookchat/domain/user/service/UserService.java b/src/main/java/toy/bookchat/bookchat/domain/user/service/UserService.java index 8ec3d882..6f42fc23 100644 --- a/src/main/java/toy/bookchat/bookchat/domain/user/service/UserService.java +++ b/src/main/java/toy/bookchat/bookchat/domain/user/service/UserService.java @@ -6,6 +6,7 @@ import java.time.format.DateTimeFormatter; import java.util.UUID; import java.util.function.Consumer; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -25,6 +26,8 @@ import toy.bookchat.bookchat.infrastructure.fcm.service.PushService; import toy.bookchat.bookchat.infrastructure.s3.StorageService; +@RequiredArgsConstructor + @Service public class UserService { @@ -32,19 +35,10 @@ public class UserService { private final UserReader userReader; private final DeviceRepository deviceRepository; private final PushService pushService; + @Qualifier("userProfileStorageService") private final StorageService storageService; private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - public UserService(UserRepository userRepository, UserReader userReader, - DeviceRepository deviceRepository, PushService pushService, - @Qualifier("userProfileStorageService") StorageService storageService) { - this.userRepository = userRepository; - this.userReader = userReader; - this.deviceRepository = deviceRepository; - this.pushService = pushService; - this.storageService = storageService; - } - @Transactional(readOnly = true) public boolean isDuplicatedName(String nickname) { return userRepository.existsByNickname(nickname); @@ -53,25 +47,13 @@ public boolean isDuplicatedName(String nickname) { @Transactional public void registerNewUser(UserSignUpRequest userSignUpRequest, MultipartFile userProfileImage, String userName, String userEmail) { - if (imageExistent(userProfileImage)) { + if (doesImageExist(userProfileImage)) { uploadWithImage(userSignUpRequest, userProfileImage, userName, userEmail); return; } uploadWithoutImage(userSignUpRequest, userName, userEmail); } - private void uploadWithImage(UserSignUpRequest userSignUpRequest, - MultipartFile userProfileImage, String userName, String userEmail) { - String uploadFileUrl = storageService.upload(userProfileImage, UUID.randomUUID().toString(), - LocalDateTime.now().format(dateTimeFormatter)); - saveUser(userSignUpRequest, userName, userEmail, uploadFileUrl); - } - - private void uploadWithoutImage(UserSignUpRequest userSignUpRequest, String userName, - String userEmail) { - saveUser(userSignUpRequest, userName, userEmail, null); - } - @Transactional(readOnly = true) public UserEntity findUserByUsername(String oauth2MemberNumber) { return userReader.readUserEntity(oauth2MemberNumber); @@ -87,7 +69,7 @@ public void deleteUser(Long userId) { public void updateUserProfile(ChangeUserNicknameRequest changeUserNicknameRequest, MultipartFile userProfileImage, Long userId) { UserEntity userEntity = userReader.readUserEntity(userId); - if (imageExistent(userProfileImage)) { + if (doesImageExist(userProfileImage)) { updateNicknameWithProfileImage(changeUserNicknameRequest, userProfileImage, userEntity); return; } @@ -95,7 +77,43 @@ public void updateUserProfile(ChangeUserNicknameRequest changeUserNicknameReques userEntity.changeProfileImageUrl(null); } - private boolean imageExistent(MultipartFile userProfileImage) { + @Transactional + public void checkDevice(UserSignInRequest userSignInRequest, Long userId) { + deviceRepository.findByUserId(userId) + .ifPresentOrElse(changeDeviceIfApproved(userSignInRequest), + registerUserDevice(userSignInRequest, userId)); + } + + @Transactional + public void deleteDevice(Long userId) { + deviceRepository.deleteByUserId(userId); + } + + @Transactional(readOnly = true) + public MemberProfileResponse getMemberProfile(Long memberId) { + UserEntity userEntity = userReader.readUserEntity(memberId); + return MemberProfileResponse.of(userEntity); + } + + @Transactional(readOnly = true) + public User findUser(Long userId) { + return userReader.readUser(userId); + + } + + private void uploadWithImage(UserSignUpRequest userSignUpRequest, MultipartFile userProfileImage, String userName, + String userEmail) { + String uploadFileUrl = storageService.upload(userProfileImage, UUID.randomUUID().toString(), + LocalDateTime.now().format(dateTimeFormatter)); + saveUser(userSignUpRequest, userName, userEmail, uploadFileUrl); + } + + private void uploadWithoutImage(UserSignUpRequest userSignUpRequest, String userName, + String userEmail) { + saveUser(userSignUpRequest, userName, userEmail, null); + } + + private boolean doesImageExist(MultipartFile userProfileImage) { return userProfileImage != null; } @@ -107,8 +125,7 @@ private void updateNicknameWithProfileImage(ChangeUserNicknameRequest changeUser userEntity.changeProfileImageUrl(uploadFileUrl); } - private void saveUser(UserSignUpRequest userSignUpRequest, String userName, - String email, String profileImageUrl) { + private void saveUser(UserSignUpRequest userSignUpRequest, String userName, String email, String profileImageUrl) { userRepository.findByName(userName).ifPresentOrElse(user -> { throw new UserAlreadySignUpException(); }, () -> { @@ -117,13 +134,6 @@ private void saveUser(UserSignUpRequest userSignUpRequest, String userName, }); } - @Transactional - public void checkDevice(UserSignInRequest userSignInRequest, Long userId) { - deviceRepository.findByUserId(userId) - .ifPresentOrElse(changeDeviceIfApproved(userSignInRequest), - registerUserDevice(userSignInRequest, userId)); - } - private Runnable registerUserDevice(UserSignInRequest userSignInRequest, Long userId) { return () -> deviceRepository.save(userSignInRequest.createDevice(userId)); } @@ -142,19 +152,4 @@ private Consumer changeDeviceIfApproved(UserSignInRequest userSign }; } - @Transactional - public void deleteDevice(Long userId) { - deviceRepository.deleteByUserId(userId); - } - - @Transactional(readOnly = true) - public MemberProfileResponse getMemberProfile(Long memberId) { - UserEntity userEntity = userReader.readUserEntity(memberId); - return MemberProfileResponse.of(userEntity); - } - - @Transactional(readOnly = true) - public User findUser(Long userId) { - return userReader.readUser(userId); - } }