Skip to content

Commit

Permalink
[#59] feat: 온보딩 설문 조회 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
NaMinhyeok committed Feb 14, 2025
1 parent afb1ab4 commit 33d0a89
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.nexters.jaknaesocore.domain.survey.dto;

import java.util.List;

public record OnboardingSurveyResponse(List<SurveyResponse> surveyResponses) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.nexters.jaknaesocore.domain.survey.model;

import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DiscriminatorValue("ONBOARDING")
public class OnboardingSurvey extends Survey {

public OnboardingSurvey(final String content, final SurveyBundle surveyBundle) {
super(content, surveyBundle);
}

@Override
public SurveyType getSurveyType() {
return SurveyType.ONBOARDING;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum SurveyType {
MULTIPLE_CHOICE,
BALANCE,
ONBOARDING,
;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.nexters.jaknaesocore.domain.survey.repository;

import org.nexters.jaknaesocore.domain.survey.model.OnboardingSurvey;
import org.springframework.data.jpa.repository.JpaRepository;

public interface OnboardingSurveyRepository extends JpaRepository<OnboardingSurvey, Long> {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.nexters.jaknaesocore.domain.member.repository.MemberRepository;
import org.nexters.jaknaesocore.domain.survey.dto.*;
import org.nexters.jaknaesocore.domain.survey.model.*;
import org.nexters.jaknaesocore.domain.survey.repository.OnboardingSurveyRepository;
import org.nexters.jaknaesocore.domain.survey.repository.SurveyBundleRepository;
import org.nexters.jaknaesocore.domain.survey.repository.SurveyRepository;
import org.nexters.jaknaesocore.domain.survey.repository.SurveySubmissionRepository;
Expand All @@ -27,6 +28,7 @@ public class SurveyService {
private final SurveyBundleRepository surveyBundleRepository;
private final SurveySubmissionRepository surveySubmissionRepository;
private final SurveyRepository surveyRepository;
private final OnboardingSurveyRepository onboardingSurveyRepository;

@Transactional(readOnly = true)
public SurveyResponse getNextSurvey(final Long bundleId, final Long memberId) {
Expand Down Expand Up @@ -134,4 +136,12 @@ public SurveySubmissionHistoryResponse getSurveySubmissionHistory(
Collectors.collectingAndThen(
Collectors.toList(), SurveySubmissionHistoryResponse::new));
}

@Transactional(readOnly = true)
public OnboardingSurveyResponse getOnboardingSurveys() {
List<OnboardingSurvey> onboardingSurveys = onboardingSurveyRepository.findAll();
return onboardingSurveys.stream()
.map(SurveyResponse::of)
.collect(Collectors.collectingAndThen(Collectors.toList(), OnboardingSurveyResponse::new));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,64 @@ void throwSurveyNotFoundException() {
tuple("나의 행복 지수는", "3점", null, "2025.01.03"),
tuple("나는 노는게 좋다.", "4점", "당연히 노는게 좋은거 아닌가?", "2025.02.01"));
}

@Test
void 온보딩_설문_목록을_가져온다() {
// given
Member member = Member.create("나민혁", "[email protected]");
memberRepository.save(member);
SurveyBundle surveyBundle = new SurveyBundle();

surveyBundleRepository.save(surveyBundle);

OnboardingSurvey survey1 =
new OnboardingSurvey(
"새로운 아이디어를 갖고 창의적인 것이 그/그녀에게 중요하다. 그/그녀는 일을 자신만의 독특한 방식으로 하는 것을 좋아한다.", surveyBundle);
OnboardingSurvey survey2 =
new OnboardingSurvey("그/그녀에게 부자가 되는 것은 중요하다. 많은 돈과 비싼 물건들을 가지길 원한다.", surveyBundle);
OnboardingSurvey survey3 =
new OnboardingSurvey(
"세상의 모든 사람들이 평등하게 대우받아야 한다고 생각한다. 그/그녀는 모든 사람이 인생에서 동등한 기회를 가져야 한다고 믿는다.",
surveyBundle);
OnboardingSurvey survey4 =
new OnboardingSurvey(
"그/그녀에게 자신의 능력을 보여주는 것이 매우 중요하다. 사람들이 자신이 하는 일을 인정해주길 바란다.", surveyBundle);

surveyRepository.saveAll(List.of(survey1, survey2, survey3, survey4));

List<KeywordScore> scores =
List.of(
KeywordScore.builder().keyword(Keyword.ADVENTURE).score(BigDecimal.ONE).build(),
KeywordScore.builder().keyword(Keyword.BENEVOLENCE).score(BigDecimal.TWO).build());

SurveyOption option1 =
SurveyOption.builder().survey(survey1).scores(scores).content("전혀 나와 같지않다.").build();
SurveyOption option2 =
SurveyOption.builder().survey(survey2).scores(scores).content("나와 같지 않다.").build();
SurveyOption option3 =
SurveyOption.builder().survey(survey3).scores(scores).content("나와 조금 같다.").build();
SurveyOption option4 =
SurveyOption.builder().survey(survey4).scores(scores).content("나와 같다.").build();

surveyOptionRepository.saveAll(List.of(option1, option2, option3, option4));
// when
OnboardingSurveyResponse response = surveyService.getOnboardingSurveys();
// then
then(response.surveyResponses())
.extracting("id", "contents", "surveyType")
.containsExactly(
tuple(
survey1.getId(),
"새로운 아이디어를 갖고 창의적인 것이 그/그녀에게 중요하다. 그/그녀는 일을 자신만의 독특한 방식으로 하는 것을 좋아한다.",
"ONBOARDING"),
tuple(survey2.getId(), "그/그녀에게 부자가 되는 것은 중요하다. 많은 돈과 비싼 물건들을 가지길 원한다.", "ONBOARDING"),
tuple(
survey3.getId(),
"세상의 모든 사람들이 평등하게 대우받아야 한다고 생각한다. 그/그녀는 모든 사람이 인생에서 동등한 기회를 가져야 한다고 믿는다.",
"ONBOARDING"),
tuple(
survey4.getId(),
"그/그녀에게 자신의 능력을 보여주는 것이 매우 중요하다. 사람들이 자신이 하는 일을 인정해주길 바란다.",
"ONBOARDING"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ public ApiResponse<SurveySubmissionHistoryResponse> getSurveyHistoryByMemberId(
SurveySubmissionHistoryCommand.builder().bundleId(bundleId).memberId(memberId).build();
return ApiResponse.success(surveyService.getSurveySubmissionHistory(command));
}

@GetMapping("/onboarding")
public ApiResponse<OnboardingSurveyResponse> getOnboardingSurvey() {
return ApiResponse.success(surveyService.getOnboardingSurveys());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,89 @@ void getSurveyHistory() throws Exception {
.with(csrf()))
.andExpect(status().isForbidden());
}

@WithMockCustomUser
@Test
void 온보딩_설문을_조회한다() throws Exception {
OnboardingSurveyResponse response =
new OnboardingSurveyResponse(
List.of(
new SurveyResponse(
1L,
"새로운 아이디어를 갖고 창의적인 것이 그/그녀에게 중요하다. 그/그녀는 일을 자신만의 독특한 방식으로 하는 것을 좋아한다.",
"ONBOARDING",
List.of(
new SurveyOptionsResponse(1L, "전혀 나와 같지 않다."),
new SurveyOptionsResponse(2L, "나와 같지 않다."),
new SurveyOptionsResponse(3L, "나와 조금 같다."),
new SurveyOptionsResponse(4L, "나와 어느정도 같다."),
new SurveyOptionsResponse(5L, "나와 같다."),
new SurveyOptionsResponse(6L, "나와 매우 같다."))),
new SurveyResponse(
2L,
"그/그녀에게 부자가 되는 것은 중요하다. 많은 돈과 비싼 물건들을 가지길 원한다.",
"ONBOARDING",
List.of(
new SurveyOptionsResponse(7L, "전혀 나와 같지 않다."),
new SurveyOptionsResponse(8L, "나와 같지 않다."),
new SurveyOptionsResponse(9L, "나와 조금 같다."),
new SurveyOptionsResponse(10L, "나와 어느정도 같다."),
new SurveyOptionsResponse(11L, "나와 같다."),
new SurveyOptionsResponse(12L, "나와 매우 같다."))),
new SurveyResponse(
3L,
"세상의 모든 사람들이 평등하게 대우받아야 한다고 생각한다. 그/그녀는 모든 사람이 인생에서 동등한 기회를 가져야 한다고 믿는다.",
"ONBOARDING",
List.of(
new SurveyOptionsResponse(13L, "전혀 나와 같지 않다."),
new SurveyOptionsResponse(14L, "나와 같지 않다."),
new SurveyOptionsResponse(15L, "나와 조금 같다."),
new SurveyOptionsResponse(16L, "나와 어느정도 같다."),
new SurveyOptionsResponse(17L, "나와 같다."),
new SurveyOptionsResponse(18L, "나와 매우 같다."))),
new SurveyResponse(
4L,
"그/그녀에게 자신의 능력을 보여주는 것이 매우 중요하다. 사람들이 자신이 하는 일을 인정해주길 바란다.",
"ONBOARDING",
List.of(
new SurveyOptionsResponse(19L, "전혀 나와 같지 않다."),
new SurveyOptionsResponse(20L, "나와 같지 않다."),
new SurveyOptionsResponse(21L, "나와 조금 같다."),
new SurveyOptionsResponse(22L, "나와 어느정도 같다."),
new SurveyOptionsResponse(23L, "나와 같다."),
new SurveyOptionsResponse(24L, "나와 매우 같다.")))));
given(surveyService.getOnboardingSurveys()).willReturn(response);

mockMvc
.perform(get("/api/v1/surveys/onboarding").with(csrf()))
.andExpect(status().isOk())
.andDo(
document(
"survey-get-onboarding",
resource(
ResourceSnippetParameters.builder()
.description("온보딩 설문 조회")
.tag("Survey Domain")
.responseFields(
fieldWithPath("result").type(SimpleType.STRING).description("결과"),
fieldWithPath("data.surveyResponses").description("온보딩 설문"),
fieldWithPath("data.surveyResponses[].id")
.type(SimpleType.NUMBER)
.description("설문 ID"),
fieldWithPath("data.surveyResponses[].contents")
.type(SimpleType.STRING)
.description("설문 내용"),
fieldWithPath("data.surveyResponses[].surveyType")
.type(SimpleType.STRING)
.description("설문 타입"),
fieldWithPath("data.surveyResponses[].options[].id")
.type(SimpleType.NUMBER)
.description("설문지 옵션 ID"),
fieldWithPath("data.surveyResponses[].options[].optionContents")
.type(SimpleType.STRING)
.description("설문지 옵션 내용"),
fieldWithPath("error").description("에러").optional())
.responseSchema(Schema.schema("onboardingSurveyResponse"))
.build())));
}
}

0 comments on commit 33d0a89

Please sign in to comment.