Skip to content

Commit

Permalink
feat: 유저의 온보딩 정보 조회 api 구현 (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
punchdrunkard authored Oct 7, 2024
1 parent e318df4 commit 6a8a8ff
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<BasicResponse<LoginResponse>> kakaoLogin(@RequestBody SocialLoginRequest request) {
Expand Down Expand Up @@ -143,4 +144,12 @@ public ResponseEntity<BasicResponse<UserIdResponse>> updateUserInfo(@AuthUser Us
UserIdResponse response = userService.updateUserInfo(user, request);
return ResponseEntity.ok(BasicResponse.ok("내 정보 수정 성공", response));
}

@PatchMapping("/onboarding-info")
@Operation(summary = "유저의 온보딩 응답 정보 조회 성공", description = "유저의 온보딩 응답 정보 조회 성공를 조회합니다.")
public ResponseEntity<BasicResponse<UserOnboardingResponse>> getOnboardingInfo(@AuthUser User user) {

UserOnboardingResponse response = userService.getOnboardingInfo(user);
return ResponseEntity.ok(BasicResponse.ok("유저의 온보딩 응답 정보 조회 성공", response));
}
}
Original file line number Diff line number Diff line change
@@ -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<Long> categoryIds;
private List<Long> moodIds;
private List<Long> companionIds;
private List<Long> priorityIds;

@Builder
private UserOnboardingResponse(List<Long> categoryIds, List<Long> moodIds, List<Long> companionIds,
List<Long> priorityIds) {
this.categoryIds = categoryIds;
this.moodIds = moodIds;
this.companionIds = companionIds;
this.priorityIds = priorityIds;
}
}
Original file line number Diff line number Diff line change
@@ -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<UserCategory, Long> {

@Query("SELECT uc.categoryId FROM UserCategory uc WHERE uc.userId = :userId")
List<Long> findCategoryIdsByUserId(@Param("userId") Long userId);

}
Original file line number Diff line number Diff line change
@@ -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<UserCompanion, Long> {

@Query("SELECT uc.companionId FROM UserCompanion uc WHERE uc.userId = :userId")
List<Long> findCompanionIdsByUserId(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
@@ -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<UserMood, Long> {


@Query("SELECT um.moodId FROM UserMood um WHERE um.userId = :userId")
List<Long> findMoodIdsByUserId(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
@@ -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<UserPriority, Long> {

@Query("SELECT up.priorityId FROM UserPriority up WHERE up.userId = :userId")
List<Long> findPriorityIdsByUserId(@Param("userId") Long userId);
}
21 changes: 18 additions & 3 deletions src/main/java/com/odiga/fiesta/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -163,6 +161,22 @@ private void saveUserPriorities(final Long userId, List<Long> priorityIds) {
);
}

public UserOnboardingResponse getOnboardingInfo(User user) {
validateUser(user);

List<Long> categoryIds = userCategoryRepository.findCategoryIdsByUserId(user.getId());
List<Long> moodIds = userMoodRepository.findMoodIdsByUserId(user.getId());
List<Long> companionIds = userCompanionRepository.findCompanionIdsByUserId(user.getId());
List<Long> priorityIds = userPriorityRepository.findPriorityIdsByUserId(user.getId());

return UserOnboardingResponse.builder()
.categoryIds(categoryIds)
.moodIds(moodIds)
.companionIds(companionIds)
.priorityIds(priorityIds)
.build();
}

private void validateCompanions(List<Long> companionIds) {
List<Companion> companions = companionRepository.findAllById(companionIds);
if (companions.size() != companionIds.size()) {
Expand Down Expand Up @@ -200,4 +214,5 @@ private void validateUser(User user) {
throw new CustomException(USER_NOT_FOUND);
}
}

}
41 changes: 41 additions & 0 deletions src/test/java/com/odiga/fiesta/user/service/UserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6a8a8ff

Please sign in to comment.