Skip to content

Commit

Permalink
refactor: 유저 업데이트 로직 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
1o18z committed Oct 30, 2023
1 parent 5ba3fc4 commit b639277
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public void saveAll(List<Keyword> keywords, User user) {
interestRepository.saveAll(interests);
}

public void updateInterests(User user, List<Keyword> keywords) {
List<Interest> currentInterests = findAllByUserId(user.getId());
deleteAll(currentInterests);
saveAll(keywords, user);
}

public void deleteAll(List<Interest> interests) {
interestRepository.deleteAllInBatch(interests);
}
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/coffeemeet/server/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +27,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -98,12 +98,12 @@ public void updateProfileImage(Long userId, File file) {
userCommand.updateUser(user);
}

@Transactional
public void updateProfileInfo(Long userId, String nickname,
List<Keyword> 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) {
Expand All @@ -127,10 +127,4 @@ private void deleteCurrentProfileImage(String profileImageUrl) {
s3MediaService.delete(currentKey);
}

private void updateInterests(User user, List<Keyword> keywords) {
List<Interest> currentInterests = interestCommand.findAllByUserId(user.getId());
interestCommand.deleteAll(currentInterests);
interestCommand.saveAll(keywords, user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class UserCommand {

private final UserRepository userRepository;
private final UserQuery userQuery;
private final InterestRepository interestRepository;

public Long saveUser(User user) {
Expand All @@ -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);
}

}

0 comments on commit b639277

Please sign in to comment.