Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ApiResponse<QuestionSelectionResponse> saveSelectedQuestions(
);
}

@Operation(summary = "자소서 답변 저장/수정", description = "저장된 문항의 답변 내용을 작성하거나 수정합니다. 문항 내용은 수정하지 않습니다.")
@Operation(summary = "자소서 문항 답변 저장/수정", description = "저장된 문항의 내용과 답변을 함께 작성하거나 수정합니다.")
@PatchMapping("/answers")
public ApiResponse<QuestionAnswerResponse> saveAnswers(
@AuthenticationPrincipal UserDetailsImpl userDetails,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jobdri.jobdri_api.domain.analysis.dto.request;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;

Expand All @@ -15,6 +16,9 @@ public record AnswerItem(
@NotNull(message = "문항 ID는 필수입니다.")
Long questionId,

@NotBlank(message = "문항 내용은 필수입니다.")
String content,

@NotNull(message = "답변 내용은 필수입니다.")
String answer
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ public static Question create(MockApply mockApply, String content, int limit, St
public void updateAnswer(String answer) {
this.answer = answer;
}

public void updateContentAndAnswer(String content, String answer) {
this.content = content;
this.answer = answer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public QuestionAnswerResponse saveAnswers(
"해당 지원서의 문항을 찾을 수 없습니다. questionId=" + item.questionId()
);
}
question.updateAnswer(normalizeAnswer(item.answer()));
question.updateContentAndAnswer(item.content().trim(), normalizeAnswer(item.answer()));
}

return new QuestionAnswerResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void saveSelectedQuestionsThrowsWhenUserDoesNotOwnMockApply() {
}

@Test
@DisplayName("저장된 문항의 답변만 작성하거나 수정한다")
@DisplayName("저장된 문항의 내용과 답변을 함께 작성하거나 수정한다")
void saveAnswers() {
User user = saveUser("answer-save@example.com");
MockApply mockApply = saveMockApply(user);
Expand All @@ -320,15 +320,20 @@ void saveAnswers() {
Long questionId = selected.questions().get(0).questionId();

QuestionAnswerResponse response = questionService.saveAnswers(user, mockApply.getId(), new QuestionAnswerSaveRequest(List.of(
new QuestionAnswerSaveRequest.AnswerItem(questionId, "저는 백엔드 개발 경험을 바탕으로 지원했습니다.")
new QuestionAnswerSaveRequest.AnswerItem(
questionId,
"지원 동기와 입사 후 목표를 작성해주세요.",
"저는 백엔드 개발 경험을 바탕으로 지원했습니다."
)
)));

assertThat(response.questions()).hasSize(1);
assertThat(response.sequence()).isEqualTo(1);
assertThat(response.questions().get(0).content()).isEqualTo("지원 동기를 작성해주세요.");
assertThat(response.questions().get(0).content()).isEqualTo("지원 동기와 입사 후 목표를 작성해주세요.");
assertThat(response.questions().get(0).answer()).isEqualTo("저는 백엔드 개발 경험을 바탕으로 지원했습니다.");
assertThat(questionRepository.findById(questionId).orElseThrow().getAnswer())
.isEqualTo("저는 백엔드 개발 경험을 바탕으로 지원했습니다.");
Question savedQuestion = questionRepository.findById(questionId).orElseThrow();
assertThat(savedQuestion.getContent()).isEqualTo("지원 동기와 입사 후 목표를 작성해주세요.");
assertThat(savedQuestion.getAnswer()).isEqualTo("저는 백엔드 개발 경험을 바탕으로 지원했습니다.");
}

@Test
Expand All @@ -344,7 +349,7 @@ void saveAnswersReturnsSequence() {
Long questionId = selected.questions().get(0).questionId();

QuestionAnswerResponse response = questionService.saveAnswers(user, secondMockApply.getId(), new QuestionAnswerSaveRequest(List.of(
new QuestionAnswerSaveRequest.AnswerItem(questionId, "두 번째 지원 답변입니다.")
new QuestionAnswerSaveRequest.AnswerItem(questionId, "재지원 답변 문항입니다.", "두 번째 지원 답변입니다.")
)));

assertThat(response.mockApplyId()).isEqualTo(secondMockApply.getId());
Expand All @@ -363,7 +368,7 @@ void saveAnswersReturnsStoredSequence() {
Long questionId = selected.questions().get(0).questionId();

QuestionAnswerResponse response = questionService.saveAnswers(user, mockApply.getId(), new QuestionAnswerSaveRequest(List.of(
new QuestionAnswerSaveRequest.AnswerItem(questionId, "네 번째 지원 답변입니다.")
new QuestionAnswerSaveRequest.AnswerItem(questionId, "재지원 저장 순번 문항입니다.", "네 번째 지원 답변입니다.")
)));

assertThat(response.mockApplyId()).isEqualTo(mockApply.getId());
Expand All @@ -382,7 +387,7 @@ void saveAnswersThrowsWhenQuestionDoesNotBelongToMockApply() {
Long otherQuestionId = otherSelected.questions().get(0).questionId();

assertThatThrownBy(() -> questionService.saveAnswers(user, mockApply.getId(), new QuestionAnswerSaveRequest(List.of(
new QuestionAnswerSaveRequest.AnswerItem(otherQuestionId, "답변")
new QuestionAnswerSaveRequest.AnswerItem(otherQuestionId, "다른 지원서 문항", "답변")
))))
.isInstanceOf(GeneralException.class)
.extracting("code")
Expand Down
Loading