diff --git a/src/main/java/com/bamdoliro/maru/domain/form/domain/value/SubjectList.java b/src/main/java/com/bamdoliro/maru/domain/form/domain/value/SubjectList.java index 11992f5e..2afa1a7a 100644 --- a/src/main/java/com/bamdoliro/maru/domain/form/domain/value/SubjectList.java +++ b/src/main/java/com/bamdoliro/maru/domain/form/domain/value/SubjectList.java @@ -10,9 +10,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import java.util.HashMap; import java.util.List; -import java.util.stream.Collectors; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/com/bamdoliro/maru/presentation/form/dto/request/GradeRequest.java b/src/main/java/com/bamdoliro/maru/presentation/form/dto/request/GradeRequest.java index 708bb66e..08d3ec42 100644 --- a/src/main/java/com/bamdoliro/maru/presentation/form/dto/request/GradeRequest.java +++ b/src/main/java/com/bamdoliro/maru/presentation/form/dto/request/GradeRequest.java @@ -2,6 +2,7 @@ import com.bamdoliro.maru.domain.form.domain.type.Certificate; import com.bamdoliro.maru.domain.form.domain.value.Grade; +import com.bamdoliro.maru.domain.form.domain.value.Subject; import com.bamdoliro.maru.domain.form.domain.value.SubjectList; import jakarta.annotation.Nullable; import jakarta.validation.Valid; @@ -10,6 +11,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.ArrayList; import java.util.List; @Getter @@ -48,12 +50,13 @@ public class GradeRequest { private List certificateList; public Grade toValue() { + List subjectList = new ArrayList<>(); + this.subjectList.stream() + .map(SubjectRequest::toValue) + .forEach(subjectList::addAll); + return new Grade( - new SubjectList( - subjectList.stream() - .map(SubjectRequest::toValue) - .toList() - ), + new SubjectList(subjectList), attendance1 == null ? null : attendance1.toValue(), attendance2 == null ? null : attendance2.toValue(), attendance3 == null ? null : attendance3.toValue(), diff --git a/src/main/java/com/bamdoliro/maru/presentation/form/dto/request/SubjectRequest.java b/src/main/java/com/bamdoliro/maru/presentation/form/dto/request/SubjectRequest.java index 9d228ac6..cb300429 100644 --- a/src/main/java/com/bamdoliro/maru/presentation/form/dto/request/SubjectRequest.java +++ b/src/main/java/com/bamdoliro/maru/presentation/form/dto/request/SubjectRequest.java @@ -2,43 +2,50 @@ import com.bamdoliro.maru.domain.form.domain.type.AchievementLevel; import com.bamdoliro.maru.domain.form.domain.value.Subject; -import jakarta.validation.constraints.Max; -import jakarta.validation.constraints.Min; +import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + @Getter @NoArgsConstructor @AllArgsConstructor public class SubjectRequest { - @NotNull(message = "필수값입니다.") - @Min(value = 1, message = "1 이상이여야 합니다.") - @Max(value = 3, message = "3 이하여야 합니다.") - private Integer grade; - - @NotNull(message = "필수값입니다.") - @Min(value = 1, message = "1 이상이여야 합니다.") - @Max(value = 2, message = "2 이하여야 합니다.") - private Integer semester; - @NotBlank(message = "필수값입니다.") @Size(max = 15, message = "15자 이하여야 합니다.") private String subjectName; - @NotNull(message = "필수값입니다.") - private AchievementLevel achievementLevel; + @Nullable + private AchievementLevel achievementLevel21; + + @Nullable + private AchievementLevel achievementLevel22; + + @Nullable + private AchievementLevel achievementLevel31; + + public List toValue() { + List subjectList = new ArrayList<>(); + + if (Objects.nonNull(achievementLevel21)) { + subjectList.add(new Subject(2, 1, subjectName, achievementLevel21)); + } + + if (Objects.nonNull(achievementLevel22)) { + subjectList.add(new Subject(2, 2, subjectName, achievementLevel22)); + } + + if (Objects.nonNull(achievementLevel31)) { + subjectList.add(new Subject(3, 1, subjectName, achievementLevel31)); + } - public Subject toValue() { - return new Subject( - grade, - semester, - subjectName, - achievementLevel - ); + return subjectList; } } diff --git a/src/test/java/com/bamdoliro/maru/presentation/form/FormControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/form/FormControllerTest.java index cfc65229..6e78f9e6 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/form/FormControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/form/FormControllerTest.java @@ -141,18 +141,21 @@ class FormControllerTest extends RestDocsTestSupport { fieldWithPath("education.teacherMobilePhoneNumber") .type(JsonFieldType.STRING) .description("작성 교사 휴대전화번호 (없는 경우 null)"), - fieldWithPath("grade.subjectList[].grade") - .type(JsonFieldType.NUMBER) - .description("학년 (검정고시는 1로 통일)"), - fieldWithPath("grade.subjectList[].semester") - .type(JsonFieldType.NUMBER) - .description("학기 (검정고시는 1로 통일)"), fieldWithPath("grade.subjectList[].subjectName") .type(JsonFieldType.STRING) .description("과목명"), - fieldWithPath("grade.subjectList[].achievementLevel") + fieldWithPath("grade.subjectList[].achievementLevel21") + .type(JsonFieldType.STRING) + .description("2학년 1학기 성취도 (성적이 없는 경우 null)") + .optional(), + fieldWithPath("grade.subjectList[].achievementLevel22") .type(JsonFieldType.STRING) - .description("성취도 (A-E)"), + .description("2학년 2학기 성취도 (성적이 없는 경우 null)") + .optional(), + fieldWithPath("grade.subjectList[].achievementLevel31") + .type(JsonFieldType.STRING) + .description("3학년 1학기 성취도 (성적이 없는 경우 null)") + .optional(), fieldWithPath("grade.certificateList[]") .type(JsonFieldType.ARRAY) .description("자격증 리스트"), @@ -645,18 +648,21 @@ class FormControllerTest extends RestDocsTestSupport { fieldWithPath("education.teacherMobilePhoneNumber") .type(JsonFieldType.STRING) .description("작성 교사 휴대전화번호 (없는 경우 null)"), - fieldWithPath("grade.subjectList[].grade") - .type(JsonFieldType.NUMBER) - .description("학년 (검정고시는 1로 통일)"), - fieldWithPath("grade.subjectList[].semester") - .type(JsonFieldType.NUMBER) - .description("학기 (검정고시는 1로 통일)"), fieldWithPath("grade.subjectList[].subjectName") .type(JsonFieldType.STRING) .description("과목명"), - fieldWithPath("grade.subjectList[].achievementLevel") + fieldWithPath("grade.subjectList[].achievementLevel21") + .type(JsonFieldType.STRING) + .description("2학년 1학기 성취도 (성적이 없는 경우 null)") + .optional(), + fieldWithPath("grade.subjectList[].achievementLevel22") .type(JsonFieldType.STRING) - .description("성취도 (A-E)"), + .description("2학년 2학기 성취도 (성적이 없는 경우 null)") + .optional(), + fieldWithPath("grade.subjectList[].achievementLevel31") + .type(JsonFieldType.STRING) + .description("3학년 1학기 성취도 (성적이 없는 경우 null)") + .optional(), fieldWithPath("grade.certificateList[]") .type(JsonFieldType.ARRAY) .description("자격증 리스트"), diff --git a/src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java b/src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java index c17b1c72..15659a0c 100644 --- a/src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java +++ b/src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java @@ -22,10 +22,10 @@ import com.bamdoliro.maru.presentation.form.dto.request.AttendanceRequest; import com.bamdoliro.maru.presentation.form.dto.request.DocumentRequest; import com.bamdoliro.maru.presentation.form.dto.request.EducationRequest; -import com.bamdoliro.maru.presentation.form.dto.request.SubmitFormDraftRequest; import com.bamdoliro.maru.presentation.form.dto.request.GradeRequest; import com.bamdoliro.maru.presentation.form.dto.request.ParentRequest; import com.bamdoliro.maru.presentation.form.dto.request.SubjectRequest; +import com.bamdoliro.maru.presentation.form.dto.request.SubmitFormDraftRequest; import com.bamdoliro.maru.presentation.form.dto.request.UpdateFormRequest; import com.bamdoliro.maru.presentation.form.dto.response.ApplicantResponse; import com.bamdoliro.maru.presentation.form.dto.response.AttendanceResponse; @@ -67,7 +67,8 @@ public static Form createForm(FormType type) { new Teacher("나교사", "0519701234", "01012344321") ), new Grade( - new SubjectList(List.of( + new SubjectList( + List.of( new Subject(2, 1, "국어", AchievementLevel.A), new Subject(2, 1, "수학", AchievementLevel.A), new Subject(2, 1, "사회", AchievementLevel.A), @@ -169,24 +170,13 @@ public static SubmitFormDraftRequest createFormRequest(FormType type) { "01012344321" ), new GradeRequest( - List.of(new SubjectRequest(2, 1, "국어", AchievementLevel.A), - new SubjectRequest(2, 1, "수학", AchievementLevel.A), - new SubjectRequest(2, 1, "사회", AchievementLevel.A), - new SubjectRequest(2, 1, "과학", AchievementLevel.A), - new SubjectRequest(2, 1, "영어", AchievementLevel.A), - new SubjectRequest(2, 1, "체육", AchievementLevel.A), - new SubjectRequest(2, 2, "국어", AchievementLevel.A), - new SubjectRequest(2, 2, "수학", AchievementLevel.A), - new SubjectRequest(2, 2, "사회", AchievementLevel.A), - new SubjectRequest(2, 2, "과학", AchievementLevel.A), - new SubjectRequest(2, 2, "영어", AchievementLevel.A), - new SubjectRequest(2, 2, "체육", AchievementLevel.A), - new SubjectRequest(3, 1, "국어", AchievementLevel.A), - new SubjectRequest(3, 1, "수학", AchievementLevel.B), - new SubjectRequest(3, 1, "사회", AchievementLevel.A), - new SubjectRequest(3, 1, "과학", AchievementLevel.A), - new SubjectRequest(3, 1, "영어", AchievementLevel.A), - new SubjectRequest(3, 1, "체육", AchievementLevel.A) + List.of(new SubjectRequest("국어", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("수학", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("사회", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("과학", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("영어", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("체육", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("한문", null, AchievementLevel.A, null) ), new AttendanceRequest(0, 0, 0, 2), new AttendanceRequest(2, 1, 0, 0), @@ -216,11 +206,12 @@ public static SubmitFormDraftRequest createQualificationExaminationFormRequest(F null ), new GradeRequest( - List.of(new SubjectRequest(1, 1, "국어", AchievementLevel.A), - new SubjectRequest(1, 1, "수학", AchievementLevel.E), - new SubjectRequest(1, 1, "사회", AchievementLevel.A), - new SubjectRequest(1, 1, "과학", AchievementLevel.D), - new SubjectRequest(1, 1, "영어", AchievementLevel.A) + List.of(new SubjectRequest("국어", AchievementLevel.A, null, null), + new SubjectRequest("수학", AchievementLevel.A, null, null), + new SubjectRequest("사회", AchievementLevel.A, null, null), + new SubjectRequest("과학", AchievementLevel.A, null, null), + new SubjectRequest("영어", AchievementLevel.A, null, null), + new SubjectRequest("도덕", AchievementLevel.A, null, null) ), null, null, @@ -250,24 +241,13 @@ public static UpdateFormRequest createUpdateFormRequest(FormType type) { "01012344321" ), new GradeRequest( - List.of(new SubjectRequest(2, 1, "국어", AchievementLevel.A), - new SubjectRequest(2, 1, "수학", AchievementLevel.A), - new SubjectRequest(2, 1, "사회", AchievementLevel.A), - new SubjectRequest(2, 1, "과학", AchievementLevel.A), - new SubjectRequest(2, 1, "영어", AchievementLevel.A), - new SubjectRequest(2, 1, "체육", AchievementLevel.A), - new SubjectRequest(2, 2, "국어", AchievementLevel.A), - new SubjectRequest(2, 2, "수학", AchievementLevel.A), - new SubjectRequest(2, 2, "사회", AchievementLevel.A), - new SubjectRequest(2, 2, "과학", AchievementLevel.A), - new SubjectRequest(2, 2, "영어", AchievementLevel.A), - new SubjectRequest(2, 2, "체육", AchievementLevel.A), - new SubjectRequest(3, 1, "국어", AchievementLevel.A), - new SubjectRequest(3, 1, "수학", AchievementLevel.B), - new SubjectRequest(3, 1, "사회", AchievementLevel.A), - new SubjectRequest(3, 1, "과학", AchievementLevel.A), - new SubjectRequest(3, 1, "영어", AchievementLevel.A), - new SubjectRequest(3, 1, "체육", AchievementLevel.A) + List.of(new SubjectRequest("국어", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("수학", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("사회", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("과학", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("영어", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("체육", AchievementLevel.A, AchievementLevel.A, AchievementLevel.A), + new SubjectRequest("한문", null, AchievementLevel.A, null) ), new AttendanceRequest(0, 0, 0, 2), new AttendanceRequest(2, 1, 0, 0),