Skip to content

Commit

Permalink
refactor: phone number value class
Browse files Browse the repository at this point in the history
  • Loading branch information
gimhanul committed Aug 29, 2023
1 parent bfb013b commit 72e144f
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.bamdoliro.maru.infrastructure.thymeleaf.ProcessTemplateService;
import com.bamdoliro.maru.infrastructure.thymeleaf.Templates;
import com.bamdoliro.maru.shared.annotation.UseCase;
import com.bamdoliro.maru.shared.constants.Schedule;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.utils.PdfMerger;
Expand Down Expand Up @@ -39,7 +40,8 @@ public ByteArrayResource execute(User user) {
"form", form,
"grade21", subjectMap.getSubjectListOf(2, 1),
"grade22", subjectMap.getSubjectListOf(2, 2),
"grade31", subjectMap.getSubjectListOf(3, 1)
"grade31", subjectMap.getSubjectListOf(3, 1),
"year", Schedule.getAdmissionYear()
);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfDocument mergedDocument = new PdfDocument(new PdfWriter(outputStream));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.bamdoliro.maru.domain.form.domain.value;

import com.bamdoliro.maru.domain.form.domain.type.Gender;
import jakarta.persistence.AttributeOverride;
import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import lombok.AccessLevel;
Expand All @@ -24,8 +27,12 @@ public class Applicant {
@Column(nullable = false, length = 20)
private String name;

@Column(nullable = false, length = 11)
private String phoneNumber;

@Embedded
@AttributeOverrides({
@AttributeOverride(name = "value", column = @Column(name = "phone_number", nullable = false, length = 11)),
})
private PhoneNumber phoneNumber;

@Column(nullable = false)
private LocalDate birthday;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ public class Education {
public boolean isQualificationExamination() {
return graduationType.equals(GraduationType.QUALIFICATION_EXAMINATION);
}

public boolean isGraduated() {
return graduationType.equals(GraduationType.GRADUATED);
}

public boolean isExpected() {
return graduationType.equals(GraduationType.EXPECTED);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bamdoliro.maru.domain.form.domain.value;

import jakarta.persistence.AttributeOverride;
import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
Expand All @@ -17,8 +19,11 @@ public class Parent {
@Column(name = "parent_name", nullable = false, length = 20)
private String name;

@Column(name = "parent_phone_number", nullable = false, length = 11)
private String phoneNumber;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "value", column = @Column(name = "parent_phone_number", nullable = false, length = 11)),
})
private PhoneNumber phoneNumber;

@Column(name = "parent_relation", nullable = false, length = 20)
private String relation;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.bamdoliro.maru.domain.form.domain.value;

import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Embeddable
public class PhoneNumber {

private String value;

@Override
public String toString() {
if (value.length() == 10) {
return value.substring(0, 3) + "-" + value.substring(3, 6) + "-" + value.substring(6);
} else if (value.length() == 11) {
return value.substring(0, 3) + "-" + value.substring(3, 7) + "-" + value.substring(7);
}

return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.bamdoliro.maru.domain.form.domain.value;

import jakarta.persistence.AttributeOverride;
import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -16,9 +19,15 @@ public class Teacher {
@Column(name = "teacher_name", nullable = true, length = 20)
private String name;

@Column(name = "teacher_phone_number", nullable = true, length = 11)
private String phoneNumber;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "value", column = @Column(name = "teacher_phone_number", nullable = true, length = 11)),
})
private PhoneNumber phoneNumber;

@Column(name = "teacher_mobile_phone_number", nullable = true, length = 11)
private String mobilePhoneNumber;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "value", column = @Column(name = "teacher_mobile_phone_number", nullable = true, length = 11)),
})
private PhoneNumber mobilePhoneNumber;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.bamdoliro.maru.domain.form.domain.type.Gender;
import com.bamdoliro.maru.domain.form.domain.value.Applicant;
import com.bamdoliro.maru.domain.form.domain.value.PhoneNumber;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Past;
Expand Down Expand Up @@ -41,7 +42,7 @@ public Applicant toValue() {
return new Applicant(
identificationPictureUri,
name,
phoneNumber,
new PhoneNumber(phoneNumber),
birthday,
gender
);
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.GraduationType;
import com.bamdoliro.maru.domain.form.domain.value.Education;
import com.bamdoliro.maru.domain.form.domain.value.PhoneNumber;
import com.bamdoliro.maru.domain.form.domain.value.School;
import com.bamdoliro.maru.domain.form.domain.value.Teacher;
import jakarta.annotation.Nullable;
Expand Down Expand Up @@ -53,8 +54,16 @@ public Education toValue() {
return new Education(
graduationType,
graduationYear,
new School(schoolName, schoolLocation, schoolCode),
new Teacher(teacherName, teacherPhoneNumber, teacherMobilePhoneNumber)
new School(
schoolName,
schoolLocation,
schoolCode
),
new Teacher(
teacherName,
new PhoneNumber(teacherPhoneNumber),
new PhoneNumber(teacherMobilePhoneNumber)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.bamdoliro.maru.domain.form.domain.value.Address;
import com.bamdoliro.maru.domain.form.domain.value.Parent;
import com.bamdoliro.maru.domain.form.domain.value.PhoneNumber;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class ParentRequest {
public Parent toValue() {
return new Parent(
name,
phoneNumber,
new PhoneNumber(phoneNumber),
relation,
new Address(
zoneCode,
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.Gender;
import com.bamdoliro.maru.domain.form.domain.value.Applicant;
import com.bamdoliro.maru.domain.form.domain.value.PhoneNumber;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand All @@ -20,7 +21,7 @@ public class ApplicantResponse {
public ApplicantResponse(Applicant applicant) {
this.identificationPictureUri = applicant.getIdentificationPictureUri();
this.name = applicant.getName();
this.phoneNumber = applicant.getPhoneNumber();
this.phoneNumber = applicant.getPhoneNumber().toString();
this.birthday = applicant.getBirthday();
this.gender = applicant.getGender();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public EducationResponse(Education education) {
this.schoolLocation = education.getSchool().getLocation();
this.schoolCode = education.getSchool().getCode();
this.teacherName = education.getTeacher().getName();
this.teacherPhoneNumber = education.getTeacher().getPhoneNumber();
this.teacherPhoneNumber = education.getTeacher().getPhoneNumber().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ParentResponse {

public ParentResponse(Parent parent) {
this.name = parent.getName();
this.phoneNumber = parent.getPhoneNumber();
this.phoneNumber = parent.getPhoneNumber().toString();
this.relation = parent.getRelation();
this.zoneCode = parent.getAddress().getZoneCode();
this.address = parent.getAddress().getAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import lombok.experimental.UtilityClass;

import java.time.LocalDate;
import java.time.LocalDateTime;

@UtilityClass
public class Schedule {

public final LocalDateTime START = LocalDateTime.of(2023, 10, 16, 9, 0);
public static final LocalDateTime START = LocalDateTime.of(2023, 10, 16, 9, 0);
public static final LocalDateTime END = LocalDateTime.of(2023, 10, 19, 17, 0);
public static final LocalDateTime ANNOUNCEMENT_OF_FIRST_PASS = LocalDateTime.of(2023, 10, 23, 15, 0);
public static final LocalDateTime ANNOUNCEMENT_OF_SECOND_PASS = LocalDateTime.of(2023, 11, 2, 15, 0);

public static final String SELECT_FIRST_PASS_CRON = "0 0 1 20 10 ?";

public static int getAdmissionYear() {
return START.plusYears(1L).getYear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.bamdoliro.maru.domain.form.service.CalculateFormScoreService;
import com.bamdoliro.maru.infrastructure.thymeleaf.ProcessTemplateService;
import com.bamdoliro.maru.infrastructure.thymeleaf.Templates;
import com.bamdoliro.maru.shared.constants.Schedule;
import com.bamdoliro.maru.shared.fixture.FormFixture;
import com.bamdoliro.maru.shared.util.SaveFileUtil;
import com.itextpdf.kernel.pdf.PdfDocument;
Expand Down Expand Up @@ -61,7 +62,8 @@ class GeneratePdfServiceTest {
"form", form,
"grade21", form.getGrade().getSubjectList().getSubjectMap().getSubjectListOf(2, 1),
"grade22", form.getGrade().getSubjectList().getSubjectMap().getSubjectListOf(2, 2),
"grade31", form.getGrade().getSubjectList().getSubjectMap().getSubjectListOf(3, 1)
"grade31", form.getGrade().getSubjectList().getSubjectMap().getSubjectListOf(3, 1),
"year", Schedule.getAdmissionYear()
);

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Expand Down
23 changes: 14 additions & 9 deletions src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.bamdoliro.maru.domain.form.domain.value.Education;
import com.bamdoliro.maru.domain.form.domain.value.Grade;
import com.bamdoliro.maru.domain.form.domain.value.Parent;
import com.bamdoliro.maru.domain.form.domain.value.PhoneNumber;
import com.bamdoliro.maru.domain.form.domain.value.School;
import com.bamdoliro.maru.domain.form.domain.value.Subject;
import com.bamdoliro.maru.domain.form.domain.value.SubjectList;
Expand Down Expand Up @@ -51,13 +52,13 @@ public static Form createForm(FormType type) {
new Applicant(
"https://maru.com/photo.png",
"김밤돌",
"01012345678",
new PhoneNumber("01012345678"),
LocalDate.of(2005, 4, 15),
Gender.FEMALE
),
new Parent(
"김이로",
"01012345678",
new PhoneNumber("01012345678"),
"엄마",
new Address(
"18071",
Expand All @@ -69,7 +70,7 @@ public static Form createForm(FormType type) {
GraduationType.EXPECTED,
"2021",
new School("비전중학교", "경기도", "7631003"),
new Teacher("나교사", "0519701234", "01012344321")
new Teacher("나교사", new PhoneNumber("0519701234"), new PhoneNumber("01012344321"))
),
new Grade(
new SubjectList(
Expand Down Expand Up @@ -115,13 +116,13 @@ public static Form createRandomForm(User user) {
new Applicant(
"https://maru.com/photo.png",
"김밤돌",
"01012345678",
new PhoneNumber("01012345678"),
LocalDate.of(2005, 4, 15),
Gender.FEMALE
),
new Parent(
"김이로",
"01012345678",
new PhoneNumber("01012345678"),
"엄마",
new Address(
"18071",
Expand All @@ -133,7 +134,7 @@ public static Form createRandomForm(User user) {
GraduationType.EXPECTED,
"2021",
new School("비전중학교", "경기도", "7631003"),
new Teacher("나교사", "0519701234", "01012344321")
new Teacher("나교사", new PhoneNumber("0519701234"), new PhoneNumber("01012344321"))
),
new Grade(
new SubjectList(
Expand Down Expand Up @@ -194,13 +195,13 @@ public static Form createQualificationExaminationForm(FormType type) {
new Applicant(
"https://maru.com/photo.png",
"김밤돌",
"01012345678",
new PhoneNumber("01012345678"),
LocalDate.of(2005, 4, 15),
Gender.FEMALE
),
new Parent(
"김이로",
"01012345678",
new PhoneNumber("01012345678"),
"엄마",
new Address(
"18071",
Expand All @@ -211,7 +212,11 @@ public static Form createQualificationExaminationForm(FormType type) {
new Education(
GraduationType.QUALIFICATION_EXAMINATION,
"2021",
null,
new School(
"비전중학교",
"경기도",
"7631003"
),
null
),
new Grade(
Expand Down

0 comments on commit 72e144f

Please sign in to comment.