-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(#24): 답변 작성 API 구현 #55
Merged
The head ref may contain hidden characters: "feature/#24-feat-\uB2F5\uBCC0-\uC791\uC131-api"
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ada5c1
[#24] feat: 답변 작성 API 구현
NaMinhyeok 4998426
[#24] refactor: 명확한 필드명 사용
NaMinhyeok 2f5b7f6
[#24] refactor: uri 동사에서 명사로 변경
NaMinhyeok a787195
[#24] fix: member 필드 추가 반영
NaMinhyeok 8fb91a7
[#24] refactor: dto 네이밍 command로 변경
NaMinhyeok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...ore/src/main/java/org/nexters/jaknaesocore/domain/survey/dto/SurveySubmissionCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package org.nexters.jaknaesocore.domain.survey.dto; | ||
|
||
public record SurveySubmissionCommand(Long optionId, String comment) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
jaknaeso-core/src/main/resources/sql/024/001_alter_table_survey_submission.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE survey_submission | ||
RENAME COLUMN comment TO retrospective; |
50 changes: 50 additions & 0 deletions
50
jaknaeso-core/src/test/java/org/nexters/jaknaesocore/domain/survey/model/SurveyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.nexters.jaknaesocore.domain.survey.model; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.assertj.core.api.BDDAssertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.nexters.jaknaesocore.common.support.error.CustomException; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
class SurveyTest { | ||
|
||
@Test | ||
void 설문의_선택지를_ID를_통해_찾는다() { | ||
// given | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
BalanceSurvey survey = new BalanceSurvey("설문", surveyBundle); | ||
|
||
SurveyOption option1 = createSurveyOptionWithId(survey, "옵션1", 1L); | ||
SurveyOption option2 = createSurveyOptionWithId(survey, "옵션2", 2L); | ||
SurveyOption option3 = createSurveyOptionWithId(survey, "옵션3", 3L); | ||
|
||
// when | ||
SurveyOption foundOption = survey.getOptionById(2L); | ||
|
||
// then | ||
BDDAssertions.then(foundOption).extracting("id", "content").containsExactly(2L, "옵션2"); | ||
} | ||
|
||
@Test | ||
void 설문의_선택지를_ID를_통해_찾을_수_없을_때_예외를_발생한다() { | ||
// given | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
BalanceSurvey survey = new BalanceSurvey("설문", surveyBundle); | ||
|
||
SurveyOption option1 = createSurveyOptionWithId(survey, "옵션1", 1L); | ||
SurveyOption option2 = createSurveyOptionWithId(survey, "옵션2", 2L); | ||
SurveyOption option3 = createSurveyOptionWithId(survey, "옵션3", 3L); | ||
// when | ||
// then | ||
BDDAssertions.thenThrownBy(() -> survey.getOptionById(4L)) | ||
.isInstanceOf(CustomException.class) | ||
.isEqualTo(CustomException.SURVEY_OPTION_NOT_FOUND); | ||
} | ||
|
||
private SurveyOption createSurveyOptionWithId(Survey survey, String content, Long id) { | ||
SurveyOption option = SurveyOption.builder().survey(survey).content(content).build(); | ||
ReflectionTestUtils.setField(option, "id", id); | ||
return option; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,7 @@ | |
import org.nexters.jaknaesocore.common.support.IntegrationTest; | ||
import org.nexters.jaknaesocore.domain.member.model.Member; | ||
import org.nexters.jaknaesocore.domain.member.repository.MemberRepository; | ||
import org.nexters.jaknaesocore.domain.survey.model.BalanceSurvey; | ||
import org.nexters.jaknaesocore.domain.survey.model.Keyword; | ||
import org.nexters.jaknaesocore.domain.survey.model.KeywordScore; | ||
import org.nexters.jaknaesocore.domain.survey.model.SurveyBundle; | ||
import org.nexters.jaknaesocore.domain.survey.model.SurveyOption; | ||
import org.nexters.jaknaesocore.domain.survey.model.SurveySubmission; | ||
import org.nexters.jaknaesocore.domain.survey.model.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
class SurveySubmissionRepositoryTest extends IntegrationTest { | ||
|
@@ -76,7 +71,7 @@ void findByMember_IdAndDeletedAtIsNull() { | |
@Test | ||
void 회원이_제출한_가장_마지막_설문을_조회한다() { | ||
// given | ||
Member member = Member.create(); | ||
Member member = Member.create("나민혁", "[email protected]"); | ||
memberRepository.save(member); | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
surveyBundleRepository.save(surveyBundle); | ||
|
@@ -125,7 +120,7 @@ void findByMember_IdAndDeletedAtIsNull() { | |
@Test | ||
void 번들에서_제출한_설문을_조회한다() { | ||
// given | ||
Member member = Member.create(); | ||
Member member = Member.create("나민혁", "[email protected]"); | ||
memberRepository.save(member); | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
surveyBundleRepository.save(surveyBundle); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
package org.nexters.jaknaesocore.domain.survey.service; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static org.assertj.core.api.BDDAssertions.tuple; | ||
import static org.assertj.core.api.BDDAssertions.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.nexters.jaknaesocore.common.support.IntegrationTest; | ||
import org.nexters.jaknaesocore.common.support.error.CustomException; | ||
import org.nexters.jaknaesocore.domain.member.model.Member; | ||
import org.nexters.jaknaesocore.domain.member.repository.MemberRepository; | ||
import org.nexters.jaknaesocore.domain.survey.dto.SurveyHistoryResponse; | ||
import org.nexters.jaknaesocore.domain.survey.dto.SurveyResponse; | ||
import org.nexters.jaknaesocore.domain.survey.dto.SurveySubmissionCommand; | ||
import org.nexters.jaknaesocore.domain.survey.model.*; | ||
import org.nexters.jaknaesocore.domain.survey.model.BalanceSurvey; | ||
import org.nexters.jaknaesocore.domain.survey.model.Keyword; | ||
import org.nexters.jaknaesocore.domain.survey.model.KeywordScore; | ||
|
@@ -30,10 +32,10 @@ class SurveyServiceTest extends IntegrationTest { | |
@Autowired private SurveyService surveyService; | ||
|
||
@Autowired private MemberRepository memberRepository; | ||
@Autowired private SurveySubmissionRepository surveySubmissionRepository; | ||
@Autowired private SurveyBundleRepository surveyBundleRepository; | ||
@Autowired private SurveyRepository surveyRepository; | ||
@Autowired private SurveyOptionRepository surveyOptionRepository; | ||
@Autowired private SurveySubmissionRepository surveySubmissionRepository; | ||
|
||
@AfterEach | ||
void tearDown() { | ||
|
@@ -73,10 +75,111 @@ void getNextSurvey() { | |
.containsExactly(tuple(option.getId(), "질문 옵션 내용")); | ||
} | ||
|
||
@DisplayName("submitSurvey 메서드는") | ||
@Nested | ||
class submitSurvey { | ||
|
||
@DisplayName("회원이 존재하지 않으면") | ||
@Nested | ||
class whenMemberNotFound { | ||
@Test | ||
@DisplayName("예외를 발생시킨다") | ||
void throwMemberNotFoundException() { | ||
// given | ||
Member member = Member.create("나민혁", "[email protected]"); | ||
memberRepository.save(member); | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
surveyBundleRepository.save(surveyBundle); | ||
BalanceSurvey balanceSurvey = new BalanceSurvey("질문내용", surveyBundle); | ||
surveyRepository.save(balanceSurvey); | ||
List<KeywordScore> scores = | ||
List.of( | ||
KeywordScore.builder().keyword(Keyword.ACHIEVEMENT).score(BigDecimal.ONE).build(), | ||
KeywordScore.builder().keyword(Keyword.BENEVOLENCE).score(BigDecimal.TWO).build()); | ||
SurveyOption option = | ||
SurveyOption.builder().survey(balanceSurvey).scores(scores).content("질문 옵션 내용").build(); | ||
surveyOptionRepository.save(option); | ||
|
||
SurveySubmissionCommand request = | ||
new SurveySubmissionCommand(option.getId(), "나는 행복한게 좋으니까"); | ||
|
||
// when | ||
// then | ||
thenThrownBy(() -> surveyService.submitSurvey(balanceSurvey.getId(), 0L, request)) | ||
.isEqualTo(CustomException.MEMBER_NOT_FOUND); | ||
} | ||
} | ||
|
||
@DisplayName("설문을 저장한다") | ||
@Nested | ||
class shouldSubmitted { | ||
@Test | ||
void 설문에_응답을_제출한다() { | ||
// given | ||
Member member = Member.create("나민혁", "[email protected]"); | ||
memberRepository.save(member); | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
surveyBundleRepository.save(surveyBundle); | ||
BalanceSurvey balanceSurvey = new BalanceSurvey("질문내용", surveyBundle); | ||
surveyRepository.save(balanceSurvey); | ||
List<KeywordScore> scores = | ||
List.of( | ||
KeywordScore.builder().keyword(Keyword.ACHIEVEMENT).score(BigDecimal.ONE).build(), | ||
KeywordScore.builder().keyword(Keyword.BENEVOLENCE).score(BigDecimal.TWO).build()); | ||
SurveyOption option = | ||
SurveyOption.builder().survey(balanceSurvey).scores(scores).content("질문 옵션 내용").build(); | ||
surveyOptionRepository.save(option); | ||
|
||
SurveySubmissionCommand request = | ||
new SurveySubmissionCommand(option.getId(), "나는 행복한게 좋으니까"); | ||
|
||
// when | ||
surveyService.submitSurvey(balanceSurvey.getId(), member.getId(), request); | ||
// then | ||
List<SurveySubmission> submissions = surveySubmissionRepository.findAll(); | ||
then(submissions).hasSize(1); | ||
then(submissions.getFirst()) | ||
.extracting("member.id", "survey.id", "selectedOption.id", "retrospective") | ||
.containsExactly(member.getId(), balanceSurvey.getId(), option.getId(), "나는 행복한게 좋으니까"); | ||
} | ||
} | ||
|
||
@DisplayName("설문이 존재하지 않으면") | ||
@Nested | ||
class whenSurveyNotFound { | ||
@Test | ||
@DisplayName("예외를 발생시킨다") | ||
void throwSurveyNotFoundException() { | ||
// given | ||
Member member = Member.create("나민혁", "[email protected]"); | ||
memberRepository.save(member); | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
surveyBundleRepository.save(surveyBundle); | ||
BalanceSurvey balanceSurvey = new BalanceSurvey("질문내용", surveyBundle); | ||
surveyRepository.save(balanceSurvey); | ||
List<KeywordScore> scores = | ||
List.of( | ||
KeywordScore.builder().keyword(Keyword.ACHIEVEMENT).score(BigDecimal.ONE).build(), | ||
KeywordScore.builder().keyword(Keyword.BENEVOLENCE).score(BigDecimal.TWO).build()); | ||
SurveyOption option = | ||
SurveyOption.builder().survey(balanceSurvey).scores(scores).content("질문 옵션 내용").build(); | ||
surveyOptionRepository.save(option); | ||
|
||
SurveySubmissionCommand request = | ||
new SurveySubmissionCommand(option.getId(), "나는 행복한게 좋으니까"); | ||
|
||
// when | ||
// then | ||
thenThrownBy(() -> surveyService.submitSurvey(0L, member.getId(), request)) | ||
.isEqualTo(CustomException.SURVEY_NOT_FOUND); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
void 설문_기록이_없으면_1번_번들을_제공한다() { | ||
// given | ||
Member member = Member.create(); | ||
Member member = Member.create("나민혁", "[email protected]"); | ||
memberRepository.save(member); | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
surveyBundleRepository.save(surveyBundle); | ||
|
@@ -115,7 +218,7 @@ void getNextSurvey() { | |
@Test | ||
void 설문_기록이_일정_개수_이하이면_기록과_함께_번들ID를_제공한다() { | ||
// given | ||
Member member = Member.create(); | ||
Member member = Member.create("나민혁", "[email protected]"); | ||
memberRepository.save(member); | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
surveyBundleRepository.save(surveyBundle); | ||
|
@@ -164,7 +267,7 @@ void getNextSurvey() { | |
@Test | ||
void 설문_기록이_번들_크기만큼_있으면_다음_번들ID를_제공한다() { | ||
// given | ||
Member member = Member.create(); | ||
Member member = Member.create("나민혁", "[email protected]"); | ||
memberRepository.save(member); | ||
SurveyBundle surveyBundle1 = new SurveyBundle(); | ||
SurveyBundle surveyBundle2 = new SurveyBundle(); | ||
|
@@ -217,7 +320,7 @@ void getNextSurvey() { | |
@Test | ||
void 진행할_다음_설문_번들이_존재하지_않으면_예외를_발생한다() { | ||
// given | ||
Member member = Member.create(); | ||
Member member = Member.create("나민혁", "[email protected]"); | ||
memberRepository.save(member); | ||
SurveyBundle surveyBundle = new SurveyBundle(); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이게 자동으로 생성되는 건가요? (전에 뭐라고 하셨던 것 같은데 기억이 안 나서 여쭤봅니다!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 템플릿을 쓰고있어서 test 를 치면 자동으로
이렇게 생성되게 사용하고있어요... 손에 너무 습관이 들어서 안지운것 같습니다