Skip to content

Commit

Permalink
Merge pull request #48 from Bamdoliro/pref/#45-grade
Browse files Browse the repository at this point in the history
[개선] 성적 입력 형식 변경
  • Loading branch information
gimhanul authored Jul 27, 2023
2 parents c24fa4a + e2748b8 commit aeae889
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -10,6 +11,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Getter
Expand Down Expand Up @@ -48,12 +50,13 @@ public class GradeRequest {
private List<Certificate> certificateList;

public Grade toValue() {
List<Subject> 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Subject> toValue() {
List<Subject> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("자격증 리스트"),
Expand Down Expand Up @@ -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("자격증 리스트"),
Expand Down
66 changes: 23 additions & 43 deletions src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit aeae889

Please sign in to comment.