diff --git a/src/main/java/com/odiga/fiesta/user/controller/UserController.java b/src/main/java/com/odiga/fiesta/user/controller/UserController.java index 969010df..101258c3 100644 --- a/src/main/java/com/odiga/fiesta/user/controller/UserController.java +++ b/src/main/java/com/odiga/fiesta/user/controller/UserController.java @@ -37,6 +37,7 @@ import com.odiga.fiesta.user.dto.response.UserBadgeResponse; import com.odiga.fiesta.user.dto.response.UserIdResponse; import com.odiga.fiesta.user.dto.response.UserInfoResponse; +import com.odiga.fiesta.user.dto.response.UserOnboardingResponse; import com.odiga.fiesta.user.service.UserService; import io.swagger.v3.oas.annotations.Operation; @@ -58,7 +59,7 @@ public class UserController { private final AuthService authService; private final BadgeService badgeService; private final FestivalService festivalService; - + @PostMapping("/oauth/login") @Operation(summary = "소셜 로그인", description = "소셜 로그인을 진행합니다.") public ResponseEntity> kakaoLogin(@RequestBody SocialLoginRequest request) { @@ -143,4 +144,12 @@ public ResponseEntity> updateUserInfo(@AuthUser Us UserIdResponse response = userService.updateUserInfo(user, request); return ResponseEntity.ok(BasicResponse.ok("내 정보 수정 성공", response)); } + + @PatchMapping("/onboarding-info") + @Operation(summary = "유저의 온보딩 응답 정보 조회 성공", description = "유저의 온보딩 응답 정보 조회 성공를 조회합니다.") + public ResponseEntity> getOnboardingInfo(@AuthUser User user) { + + UserOnboardingResponse response = userService.getOnboardingInfo(user); + return ResponseEntity.ok(BasicResponse.ok("유저의 온보딩 응답 정보 조회 성공", response)); + } } diff --git a/src/main/java/com/odiga/fiesta/user/dto/response/UserOnboardingResponse.java b/src/main/java/com/odiga/fiesta/user/dto/response/UserOnboardingResponse.java new file mode 100644 index 00000000..d0ff836a --- /dev/null +++ b/src/main/java/com/odiga/fiesta/user/dto/response/UserOnboardingResponse.java @@ -0,0 +1,25 @@ +package com.odiga.fiesta.user.dto.response; + +import java.util.List; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@Getter +public class UserOnboardingResponse { + private List categoryIds; + private List moodIds; + private List companionIds; + private List priorityIds; + + @Builder + private UserOnboardingResponse(List categoryIds, List moodIds, List companionIds, + List priorityIds) { + this.categoryIds = categoryIds; + this.moodIds = moodIds; + this.companionIds = companionIds; + this.priorityIds = priorityIds; + } +} diff --git a/src/main/java/com/odiga/fiesta/user/repository/UserCategoryRepository.java b/src/main/java/com/odiga/fiesta/user/repository/UserCategoryRepository.java index dee3fb3c..271ab90e 100644 --- a/src/main/java/com/odiga/fiesta/user/repository/UserCategoryRepository.java +++ b/src/main/java/com/odiga/fiesta/user/repository/UserCategoryRepository.java @@ -1,8 +1,16 @@ package com.odiga.fiesta.user.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import com.odiga.fiesta.user.domain.mapping.UserCategory; public interface UserCategoryRepository extends JpaRepository { + + @Query("SELECT uc.categoryId FROM UserCategory uc WHERE uc.userId = :userId") + List findCategoryIdsByUserId(@Param("userId") Long userId); + } diff --git a/src/main/java/com/odiga/fiesta/user/repository/UserCompanionRepository.java b/src/main/java/com/odiga/fiesta/user/repository/UserCompanionRepository.java index d265e72d..97c67c40 100644 --- a/src/main/java/com/odiga/fiesta/user/repository/UserCompanionRepository.java +++ b/src/main/java/com/odiga/fiesta/user/repository/UserCompanionRepository.java @@ -1,8 +1,15 @@ package com.odiga.fiesta.user.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import com.odiga.fiesta.user.domain.mapping.UserCompanion; public interface UserCompanionRepository extends JpaRepository { + + @Query("SELECT uc.companionId FROM UserCompanion uc WHERE uc.userId = :userId") + List findCompanionIdsByUserId(@Param("userId") Long userId); } diff --git a/src/main/java/com/odiga/fiesta/user/repository/UserMoodRepository.java b/src/main/java/com/odiga/fiesta/user/repository/UserMoodRepository.java index 7f7d8087..6630b5c6 100644 --- a/src/main/java/com/odiga/fiesta/user/repository/UserMoodRepository.java +++ b/src/main/java/com/odiga/fiesta/user/repository/UserMoodRepository.java @@ -1,8 +1,16 @@ package com.odiga.fiesta.user.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import com.odiga.fiesta.user.domain.mapping.UserMood; public interface UserMoodRepository extends JpaRepository { + + + @Query("SELECT um.moodId FROM UserMood um WHERE um.userId = :userId") + List findMoodIdsByUserId(@Param("userId") Long userId); } diff --git a/src/main/java/com/odiga/fiesta/user/repository/UserPriorityRepository.java b/src/main/java/com/odiga/fiesta/user/repository/UserPriorityRepository.java index 272c85c1..a05372f6 100644 --- a/src/main/java/com/odiga/fiesta/user/repository/UserPriorityRepository.java +++ b/src/main/java/com/odiga/fiesta/user/repository/UserPriorityRepository.java @@ -1,8 +1,16 @@ package com.odiga.fiesta.user.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import com.odiga.fiesta.user.domain.mapping.UserPriority; +import io.lettuce.core.dynamic.annotation.Param; + public interface UserPriorityRepository extends JpaRepository { + + @Query("SELECT up.priorityId FROM UserPriority up WHERE up.userId = :userId") + List findPriorityIdsByUserId(@Param("userId") Long userId); } diff --git a/src/main/java/com/odiga/fiesta/user/service/UserService.java b/src/main/java/com/odiga/fiesta/user/service/UserService.java index 3fa3ebd4..54967e21 100644 --- a/src/main/java/com/odiga/fiesta/user/service/UserService.java +++ b/src/main/java/com/odiga/fiesta/user/service/UserService.java @@ -42,6 +42,7 @@ import com.odiga.fiesta.user.dto.response.ProfileCreateResponse; import com.odiga.fiesta.user.dto.response.UserIdResponse; import com.odiga.fiesta.user.dto.response.UserInfoResponse; +import com.odiga.fiesta.user.dto.response.UserOnboardingResponse; import com.odiga.fiesta.user.repository.UserCategoryRepository; import com.odiga.fiesta.user.repository.UserCompanionRepository; import com.odiga.fiesta.user.repository.UserMoodRepository; @@ -57,9 +58,6 @@ @RequiredArgsConstructor public class UserService { - private final FestivalRepository festivalRepository; - private final FestivalService festivalService; - private final UserCategoryRepository userCategoryRepository; private final UserCompanionRepository userCompanionRepository; private final UserMoodRepository userMoodRepository; @@ -163,6 +161,22 @@ private void saveUserPriorities(final Long userId, List priorityIds) { ); } + public UserOnboardingResponse getOnboardingInfo(User user) { + validateUser(user); + + List categoryIds = userCategoryRepository.findCategoryIdsByUserId(user.getId()); + List moodIds = userMoodRepository.findMoodIdsByUserId(user.getId()); + List companionIds = userCompanionRepository.findCompanionIdsByUserId(user.getId()); + List priorityIds = userPriorityRepository.findPriorityIdsByUserId(user.getId()); + + return UserOnboardingResponse.builder() + .categoryIds(categoryIds) + .moodIds(moodIds) + .companionIds(companionIds) + .priorityIds(priorityIds) + .build(); + } + private void validateCompanions(List companionIds) { List companions = companionRepository.findAllById(companionIds); if (companions.size() != companionIds.size()) { @@ -200,4 +214,5 @@ private void validateUser(User user) { throw new CustomException(USER_NOT_FOUND); } } + } diff --git a/src/test/java/com/odiga/fiesta/user/service/UserServiceTest.java b/src/test/java/com/odiga/fiesta/user/service/UserServiceTest.java index 131797d9..d47d0628 100644 --- a/src/test/java/com/odiga/fiesta/user/service/UserServiceTest.java +++ b/src/test/java/com/odiga/fiesta/user/service/UserServiceTest.java @@ -37,6 +37,7 @@ import com.odiga.fiesta.user.dto.request.UserInfoUpdateRequest; import com.odiga.fiesta.user.dto.response.ProfileCreateResponse; import com.odiga.fiesta.user.dto.response.UserIdResponse; +import com.odiga.fiesta.user.dto.response.UserOnboardingResponse; import com.odiga.fiesta.user.repository.UserCategoryRepository; import com.odiga.fiesta.user.repository.UserCompanionRepository; import com.odiga.fiesta.user.repository.UserMoodRepository; @@ -193,6 +194,46 @@ void updateUserInfo_ExceedStatusMessageLength() { assertThat(exception.getErrorCode()).isEqualTo(INVALID_STATUS_MESSAGE_LENGTH); } + @DisplayName("유저의 온보딩 정보 조회 - 성공") + @Test + void getOnboardingInfo() { + // given + User user = createNoProfileUser(); + + ProfileCreateRequest request = ProfileCreateRequest.builder() + .priorityIds(List.of(1L, 2L)) + .moodIds(List.of(1L, 2L)) + .categoryIds(List.of(1L, 2L)) + .companionIds(List.of(1L, 2L)) + .build(); + + UserType userType = UserType.builder() + .id(1L) + .name("힐링러") + .profileImage("힐링러 프로필 이미지") + .cardImage("힐링러 카드 이미지") + .build(); + + given(userRepository.existsById(user.getId())).willReturn(true); + given(userCategoryRepository.findCategoryIdsByUserId(user.getId())).willReturn(request.getCategoryIds()); + given(userMoodRepository.findMoodIdsByUserId(user.getId())).willReturn(request.getMoodIds()); + given(userCompanionRepository.findCompanionIdsByUserId(user.getId())).willReturn(request.getCompanionIds()); + given(userPriorityRepository.findPriorityIdsByUserId(user.getId())).willReturn(request.getPriorityIds()); + + // when + UserOnboardingResponse onboardingInfo = userService.getOnboardingInfo(user); + + // then + assertThat(onboardingInfo) + .extracting("categoryIds", "moodIds", "companionIds", "priorityIds") + .containsExactly( + request.getCategoryIds(), + request.getMoodIds(), + request.getCompanionIds(), + request.getPriorityIds() + ); + } + User createNoProfileUser() { return User.builder() .id(1L)