diff --git a/src/main/java/coffeemeet/server/interest/service/cq/InterestCommand.java b/src/main/java/coffeemeet/server/interest/service/cq/InterestCommand.java index ae544fd4..404f4b6a 100644 --- a/src/main/java/coffeemeet/server/interest/service/cq/InterestCommand.java +++ b/src/main/java/coffeemeet/server/interest/service/cq/InterestCommand.java @@ -27,6 +27,12 @@ public void saveAll(List keywords, User user) { interestRepository.saveAll(interests); } + public void updateInterests(User user, List keywords) { + List currentInterests = findAllByUserId(user.getId()); + deleteAll(currentInterests); + saveAll(keywords, user); + } + public void deleteAll(List interests) { interestRepository.deleteAllInBatch(interests); } diff --git a/src/main/java/coffeemeet/server/user/service/UserService.java b/src/main/java/coffeemeet/server/user/service/UserService.java index 532d130c..15544f3a 100644 --- a/src/main/java/coffeemeet/server/user/service/UserService.java +++ b/src/main/java/coffeemeet/server/user/service/UserService.java @@ -7,7 +7,6 @@ import coffeemeet.server.certification.domain.Certification; import coffeemeet.server.certification.service.cq.CertificationQuery; import coffeemeet.server.common.media.S3MediaService; -import coffeemeet.server.interest.domain.Interest; import coffeemeet.server.interest.domain.Keyword; import coffeemeet.server.interest.service.cq.InterestCommand; import coffeemeet.server.interest.service.cq.InterestQuery; @@ -28,6 +27,7 @@ import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -98,12 +98,12 @@ public void updateProfileImage(Long userId, File file) { userCommand.updateUser(user); } + @Transactional public void updateProfileInfo(Long userId, String nickname, List keywords) { + userCommand.updateUserInfo(userId, nickname); User user = userQuery.getUserById(userId); - userQuery.hasDuplicatedNickname(nickname); - user.updateNickname(nickname); - updateInterests(user, keywords); + interestCommand.updateInterests(user, keywords); } public void checkDuplicatedNickname(String nickname) { @@ -127,10 +127,4 @@ private void deleteCurrentProfileImage(String profileImageUrl) { s3MediaService.delete(currentKey); } - private void updateInterests(User user, List keywords) { - List currentInterests = interestCommand.findAllByUserId(user.getId()); - interestCommand.deleteAll(currentInterests); - interestCommand.saveAll(keywords, user); - } - } diff --git a/src/main/java/coffeemeet/server/user/service/cq/UserCommand.java b/src/main/java/coffeemeet/server/user/service/cq/UserCommand.java index f41736b9..c458d9ba 100644 --- a/src/main/java/coffeemeet/server/user/service/cq/UserCommand.java +++ b/src/main/java/coffeemeet/server/user/service/cq/UserCommand.java @@ -13,6 +13,7 @@ public class UserCommand { private final UserRepository userRepository; + private final UserQuery userQuery; private final InterestRepository interestRepository; public Long saveUser(User user) { @@ -28,4 +29,10 @@ public void deleteUser(Long userId) { userRepository.deleteById(userId); } + public void updateUserInfo(Long userId, String nickname) { + User user = userQuery.getUserById(userId); + userQuery.hasDuplicatedNickname(nickname); + user.updateNickname(nickname); + } + }