From 41d0aaafca6b69f7bee5d72a1c6beb8d59315534 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: Tue, 24 Oct 2023 14:59:54 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20User=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=EC=97=90=20=EC=A0=95=EB=B3=B4=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/coffeemeet/server/user/domain/Profile.java | 10 ++++++++++ src/main/java/coffeemeet/server/user/domain/User.java | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/coffeemeet/server/user/domain/Profile.java b/src/main/java/coffeemeet/server/user/domain/Profile.java index 97b82806..cc075942 100644 --- a/src/main/java/coffeemeet/server/user/domain/Profile.java +++ b/src/main/java/coffeemeet/server/user/domain/Profile.java @@ -69,4 +69,14 @@ private void validateProfileImage(String profileImageUrl) { } } + public void updateNickname(String nickname) { + validateNickname(nickname); + this.nickname = nickname; + } + + public void updateProfileImageUrl(String profileImageUrl) { + validateProfileImage(profileImageUrl); + this.profileImageUrl = profileImageUrl; + } + } diff --git a/src/main/java/coffeemeet/server/user/domain/User.java b/src/main/java/coffeemeet/server/user/domain/User.java index ca575d69..b28172da 100644 --- a/src/main/java/coffeemeet/server/user/domain/User.java +++ b/src/main/java/coffeemeet/server/user/domain/User.java @@ -63,4 +63,8 @@ public void updateBusinessCardUrl(String newBusinessCardUrl) { certification.updateBusinessCardUrl(newBusinessCardUrl); } + public void updateProfileImageUrl(String profileImageUrl) { + this.profile.updateProfileImageUrl(profileImageUrl); + } + } From 0fc7cdd3c3146e3a99d5195254c949658735af4f 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: Tue, 24 Oct 2023 15:01:18 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=EA=B4=80=EC=8B=AC=EC=82=AC=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/interest/domain/Keyword.java | 10 ++++ .../interest/service/InterestService.java | 49 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/main/java/coffeemeet/server/interest/service/InterestService.java diff --git a/src/main/java/coffeemeet/server/interest/domain/Keyword.java b/src/main/java/coffeemeet/server/interest/domain/Keyword.java index 717ad9e5..6b2f9aea 100644 --- a/src/main/java/coffeemeet/server/interest/domain/Keyword.java +++ b/src/main/java/coffeemeet/server/interest/domain/Keyword.java @@ -4,5 +4,15 @@ public enum Keyword { COOK, GAME, EXERCISE, + ; + + public static boolean isValidKeyword(String keyword) { + for (Keyword key : Keyword.values()) { + if (key.name().equals(keyword)) { + return true; + } + } + return false; + } } diff --git a/src/main/java/coffeemeet/server/interest/service/InterestService.java b/src/main/java/coffeemeet/server/interest/service/InterestService.java new file mode 100644 index 00000000..0541e43f --- /dev/null +++ b/src/main/java/coffeemeet/server/interest/service/InterestService.java @@ -0,0 +1,49 @@ +package coffeemeet.server.interest.service; + +import coffeemeet.server.interest.domain.Interest; +import coffeemeet.server.interest.domain.Keyword; +import coffeemeet.server.interest.repository.InterestRepository; +import coffeemeet.server.user.domain.User; +import coffeemeet.server.user.repository.UserRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class InterestService { + + private static final int MAX_INTERESTS = 3; + + private final InterestRepository interestRepository; + private final UserRepository userRepository; + + @Transactional + public void updateInterests(Long userId, List interests) { + validateInterests(interests); + + for (Keyword interest : interests) { + if (!Keyword.isValidKeyword(interest.name())) { + throw new IllegalArgumentException("유효한 관심사가 아닙니다."); + } + } + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); + + List currentInterests = interestRepository.findAllByUserId(userId); + interestRepository.deleteAll(currentInterests); + + for (Keyword keyword : interests) { + Interest newInterest = new Interest(keyword, user); + interestRepository.save(newInterest); + } + } + + private void validateInterests(List interests) { + if (interests.isEmpty() || interests.size() > MAX_INTERESTS) { + throw new IllegalArgumentException("최소 1개, 최대 3개의 관심사를 선택하세요."); + } + } + +} From 3e378e38e93fe01345f76c2a258c76d9dd29e59d 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: Tue, 24 Oct 2023 15:01:32 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EB=B0=8F=20=EC=A0=95=EB=B3=B4=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 19 +++++++++++++ .../server/user/dto/UpdateProfileRequest.java | 9 +++++++ .../server/user/service/UserService.java | 27 +++++++++++++++++-- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/main/java/coffeemeet/server/user/dto/UpdateProfileRequest.java diff --git a/src/main/java/coffeemeet/server/user/controller/UserController.java b/src/main/java/coffeemeet/server/user/controller/UserController.java index 86131025..3a5f14fd 100644 --- a/src/main/java/coffeemeet/server/user/controller/UserController.java +++ b/src/main/java/coffeemeet/server/user/controller/UserController.java @@ -3,13 +3,18 @@ import coffeemeet.server.common.annotation.Login; import coffeemeet.server.user.dto.AuthInfo; import coffeemeet.server.user.dto.MyProfileResponse; +import coffeemeet.server.user.dto.UpdateProfileRequest; import coffeemeet.server.user.dto.UserProfileResponse; import coffeemeet.server.user.service.UserService; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -29,4 +34,18 @@ public ResponseEntity findMyProfile(@Login AuthInfo authInfo) return ResponseEntity.ok(userService.findMyProfile(authInfo.userId())); } + @PatchMapping("/me/profile-image") + public ResponseEntity updateProfileImage(@Login AuthInfo authInfo, + @RequestParam String profileImageUrl) { + userService.updateProfileImage(authInfo.userId(), profileImageUrl); + return ResponseEntity.noContent().build(); + } + + @PatchMapping("/me") + public ResponseEntity updateProfileInfo(@Login AuthInfo authInfo, + @Valid @RequestBody UpdateProfileRequest request) { + userService.updateProfileInfo(authInfo.userId(), request.nickname(), request.interests()); + return ResponseEntity.noContent().build(); + } + } diff --git a/src/main/java/coffeemeet/server/user/dto/UpdateProfileRequest.java b/src/main/java/coffeemeet/server/user/dto/UpdateProfileRequest.java new file mode 100644 index 00000000..5cab1ba4 --- /dev/null +++ b/src/main/java/coffeemeet/server/user/dto/UpdateProfileRequest.java @@ -0,0 +1,9 @@ +package coffeemeet.server.user.dto; + +import coffeemeet.server.interest.domain.Keyword; +import jakarta.validation.constraints.NotBlank; +import java.util.List; + +public record UpdateProfileRequest(@NotBlank String nickname, List interests) { + +} diff --git a/src/main/java/coffeemeet/server/user/service/UserService.java b/src/main/java/coffeemeet/server/user/service/UserService.java index 40e64067..269ad88b 100644 --- a/src/main/java/coffeemeet/server/user/service/UserService.java +++ b/src/main/java/coffeemeet/server/user/service/UserService.java @@ -1,7 +1,9 @@ package coffeemeet.server.user.service; import coffeemeet.server.interest.domain.Interest; +import coffeemeet.server.interest.domain.Keyword; import coffeemeet.server.interest.repository.InterestRepository; +import coffeemeet.server.interest.service.InterestService; import coffeemeet.server.user.domain.User; import coffeemeet.server.user.dto.MyProfileResponse; import coffeemeet.server.user.dto.UserProfileResponse; @@ -17,6 +19,7 @@ public class UserService { private final UserRepository userRepository; private final InterestRepository interestRepository; + private final InterestService interestService; @Transactional public void updateBusinessCardUrl(Long userId, String businessCardUrl) { @@ -27,7 +30,7 @@ public void updateBusinessCardUrl(Long userId, String businessCardUrl) { public UserProfileResponse findUserProfile(String nickname) { User user = userRepository.findUserByProfileNickname(nickname) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); List interests = interestRepository.findAllByUserId(user.getId()); return UserProfileResponse.of(user, interests); @@ -35,10 +38,30 @@ public UserProfileResponse findUserProfile(String nickname) { public MyProfileResponse findMyProfile(Long userId) { User user = userRepository.findById(userId) - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); List interests = interestRepository.findAllByUserId(userId); return MyProfileResponse.of(user, interests); } + @Transactional + public void updateProfileImage(Long userId, String profileImageUrl) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); + user.updateProfileImageUrl(profileImageUrl); + } + + @Transactional + public void updateProfileInfo(Long userId, String nickname, List interests) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); + + if (nickname != null) { + user.getProfile().updateNickname(nickname); + } + if (interests != null && !interests.isEmpty()) { + interestService.updateInterests(userId, interests); + } + } + } From a6a5fbc9ca90c2e0b700bbe1ac004421a27bbb1e 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: Tue, 24 Oct 2023 17:15:31 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20DTO=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B2=80=EC=A6=9D=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coffeemeet/server/user/controller/UserController.java | 6 +++--- .../server/user/dto/UpdateProfileImageUrlRequest.java | 7 +++++++ .../coffeemeet/server/user/dto/UpdateProfileRequest.java | 5 ++++- .../java/coffeemeet/server/user/service/UserService.java | 8 ++------ 4 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 src/main/java/coffeemeet/server/user/dto/UpdateProfileImageUrlRequest.java diff --git a/src/main/java/coffeemeet/server/user/controller/UserController.java b/src/main/java/coffeemeet/server/user/controller/UserController.java index 3a5f14fd..c7223d70 100644 --- a/src/main/java/coffeemeet/server/user/controller/UserController.java +++ b/src/main/java/coffeemeet/server/user/controller/UserController.java @@ -3,6 +3,7 @@ import coffeemeet.server.common.annotation.Login; import coffeemeet.server.user.dto.AuthInfo; import coffeemeet.server.user.dto.MyProfileResponse; +import coffeemeet.server.user.dto.UpdateProfileImageUrlRequest; import coffeemeet.server.user.dto.UpdateProfileRequest; import coffeemeet.server.user.dto.UserProfileResponse; import coffeemeet.server.user.service.UserService; @@ -14,7 +15,6 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -36,8 +36,8 @@ public ResponseEntity findMyProfile(@Login AuthInfo authInfo) @PatchMapping("/me/profile-image") public ResponseEntity updateProfileImage(@Login AuthInfo authInfo, - @RequestParam String profileImageUrl) { - userService.updateProfileImage(authInfo.userId(), profileImageUrl); + @Valid @RequestBody UpdateProfileImageUrlRequest request) { + userService.updateProfileImage(authInfo.userId(), request.profileImageUrl()); return ResponseEntity.noContent().build(); } diff --git a/src/main/java/coffeemeet/server/user/dto/UpdateProfileImageUrlRequest.java b/src/main/java/coffeemeet/server/user/dto/UpdateProfileImageUrlRequest.java new file mode 100644 index 00000000..7f1c54ca --- /dev/null +++ b/src/main/java/coffeemeet/server/user/dto/UpdateProfileImageUrlRequest.java @@ -0,0 +1,7 @@ +package coffeemeet.server.user.dto; + +import jakarta.validation.constraints.NotBlank; + +public record UpdateProfileImageUrlRequest(@NotBlank String profileImageUrl) { + +} diff --git a/src/main/java/coffeemeet/server/user/dto/UpdateProfileRequest.java b/src/main/java/coffeemeet/server/user/dto/UpdateProfileRequest.java index 5cab1ba4..a0458198 100644 --- a/src/main/java/coffeemeet/server/user/dto/UpdateProfileRequest.java +++ b/src/main/java/coffeemeet/server/user/dto/UpdateProfileRequest.java @@ -2,8 +2,11 @@ import coffeemeet.server.interest.domain.Keyword; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.List; -public record UpdateProfileRequest(@NotBlank String nickname, List interests) { +public record UpdateProfileRequest(@NotBlank String nickname, + @NotNull @Size(min = 1, max = 3) List interests) { } diff --git a/src/main/java/coffeemeet/server/user/service/UserService.java b/src/main/java/coffeemeet/server/user/service/UserService.java index 269ad88b..78f3c518 100644 --- a/src/main/java/coffeemeet/server/user/service/UserService.java +++ b/src/main/java/coffeemeet/server/user/service/UserService.java @@ -56,12 +56,8 @@ public void updateProfileInfo(Long userId, String nickname, List intere User user = userRepository.findById(userId) .orElseThrow(() -> new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); - if (nickname != null) { - user.getProfile().updateNickname(nickname); - } - if (interests != null && !interests.isEmpty()) { - interestService.updateInterests(userId, interests); - } + user.getProfile().updateNickname(nickname); + interestService.updateInterests(userId, interests); } } From 95432e454c7f052f9958313489c9af25a18b59ac 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: Tue, 24 Oct 2023 17:17:08 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=EA=B4=80=EC=8B=AC=EC=82=AC=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coffeemeet/server/interest/domain/Keyword.java | 10 ---------- .../server/interest/service/InterestService.java | 14 ++++---------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/main/java/coffeemeet/server/interest/domain/Keyword.java b/src/main/java/coffeemeet/server/interest/domain/Keyword.java index 6b2f9aea..717ad9e5 100644 --- a/src/main/java/coffeemeet/server/interest/domain/Keyword.java +++ b/src/main/java/coffeemeet/server/interest/domain/Keyword.java @@ -4,15 +4,5 @@ public enum Keyword { COOK, GAME, EXERCISE, - ; - - public static boolean isValidKeyword(String keyword) { - for (Keyword key : Keyword.values()) { - if (key.name().equals(keyword)) { - return true; - } - } - return false; - } } diff --git a/src/main/java/coffeemeet/server/interest/service/InterestService.java b/src/main/java/coffeemeet/server/interest/service/InterestService.java index 0541e43f..a9906ed2 100644 --- a/src/main/java/coffeemeet/server/interest/service/InterestService.java +++ b/src/main/java/coffeemeet/server/interest/service/InterestService.java @@ -14,20 +14,20 @@ @RequiredArgsConstructor public class InterestService { - private static final int MAX_INTERESTS = 3; - private final InterestRepository interestRepository; private final UserRepository userRepository; @Transactional public void updateInterests(Long userId, List interests) { - validateInterests(interests); for (Keyword interest : interests) { - if (!Keyword.isValidKeyword(interest.name())) { + try { + Keyword.valueOf(interest.name()); + } catch (IllegalArgumentException e) { throw new IllegalArgumentException("유효한 관심사가 아닙니다."); } } + User user = userRepository.findById(userId) .orElseThrow(() -> new IllegalArgumentException("해당 사용자를 찾을 수 없습니다.")); @@ -40,10 +40,4 @@ public void updateInterests(Long userId, List interests) { } } - private void validateInterests(List interests) { - if (interests.isEmpty() || interests.size() > MAX_INTERESTS) { - throw new IllegalArgumentException("최소 1개, 최대 3개의 관심사를 선택하세요."); - } - } - }