From b639277b559f0cae175e76b182536c743d1e145a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Mon, 30 Oct 2023 16:03:57 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=9C=A0=EC=A0=80=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EB=A1=9C=EC=A7=81=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interest/service/cq/InterestCommand.java | 6 ++++++ .../server/user/service/UserService.java | 14 ++++---------- .../server/user/service/cq/UserCommand.java | 7 +++++++ 3 files changed, 17 insertions(+), 10 deletions(-) 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); + } + }