Skip to content

Commit

Permalink
Merge pull request #100 from Sexy-Sisters/refactor
Browse files Browse the repository at this point in the history
[Refactor] Wrap the primitive type of domain
  • Loading branch information
leekyukin authored Dec 20, 2022
2 parents 3ddb712 + 9cf2174 commit 9331d68
Show file tree
Hide file tree
Showing 77 changed files with 577 additions and 274 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sexysisters.tojserverv2.domain.approve

import com.sexysisters.tojserverv2.domain.BaseTimeEntity
import com.sexysisters.tojserverv2.domain.student.Student
import com.sexysisters.tojserverv2.domain.student.domain.Student
import javax.persistence.CascadeType
import javax.persistence.Entity
import javax.persistence.FetchType
Expand Down Expand Up @@ -38,7 +38,7 @@ class Approve(
acceptor = acceptor,
)
applicant.approves.add(initApprove)
acceptor.acceptorList.add(initApprove)
acceptor.acceptors.add(initApprove)
return initApprove
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sexysisters.tojserverv2.domain.approve

import com.sexysisters.tojserverv2.domain.student.Student
import com.sexysisters.tojserverv2.domain.student.domain.Student

interface ApproveReader {
fun getApprove(applicant: Student, acceptor: Student): Approve
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.sexysisters.tojserverv2.domain.approve.policy

import com.sexysisters.tojserverv2.domain.approve.exception.ApproveException
import com.sexysisters.tojserverv2.domain.student.Status
import com.sexysisters.tojserverv2.domain.student.Student
import com.sexysisters.tojserverv2.domain.student.domain.Status
import com.sexysisters.tojserverv2.domain.student.domain.Student
import org.springframework.core.annotation.Order
import org.springframework.stereotype.Component

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sexysisters.tojserverv2.domain.approve.policy

import com.sexysisters.tojserverv2.domain.student.Student
import com.sexysisters.tojserverv2.domain.student.engaged
import com.sexysisters.tojserverv2.domain.student.domain.Student
import com.sexysisters.tojserverv2.domain.student.domain.engaged
import org.springframework.core.annotation.Order
import org.springframework.stereotype.Component

Expand All @@ -15,7 +15,7 @@ class ApproveCountPolicy : ApprovePolicy {

override fun check(applicant: Student, acceptor: Student) {
val school = acceptor.school!!
val studentCapacity = school.studentList.size
val studentCapacity = school.students.size
val neededCount = studentCapacity / 5
val approveCount = applicant.approves.size
val isOver = approveCount >= neededCount
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sexysisters.tojserverv2.domain.approve.policy

import com.sexysisters.tojserverv2.domain.student.Student
import com.sexysisters.tojserverv2.domain.student.domain.Student

interface ApprovePolicy {
fun check(applicant: Student, acceptor: Student)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sexysisters.tojserverv2.domain.approve.policy

import com.sexysisters.tojserverv2.domain.approve.exception.ApproveException
import com.sexysisters.tojserverv2.domain.student.Student
import com.sexysisters.tojserverv2.domain.student.domain.Student
import org.springframework.core.annotation.Order
import org.springframework.stereotype.Component

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sexysisters.tojserverv2.domain.school

import com.sexysisters.tojserverv2.domain.school.domain.School

interface SchoolReader {
fun getSchool(code: String): School
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sexysisters.tojserverv2.domain.school

import com.sexysisters.tojserverv2.domain.school.domain.School

interface SchoolStore {
fun store(school: School): School
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sexysisters.tojserverv2.domain.school.domain

import com.sexysisters.tojserverv2.domain.school.exception.SchoolException
import javax.persistence.Column
import javax.persistence.Embeddable
import javax.validation.constraints.NotNull

@Embeddable
class Address(
@field:NotNull
@Column(name = "address", unique = true)
val value: String
) {
init {
val MAX_LENGTH = 34
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (value.length > MAX_LENGTH) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sexysisters.tojserverv2.domain.school.domain

import com.sexysisters.tojserverv2.domain.school.exception.SchoolException
import javax.persistence.Column
import javax.persistence.Embeddable
import javax.validation.constraints.NotNull

@Embeddable
class Belong(
@field:NotNull
@Column(name = "belong")
val value: String
) {
init {
val BELONG_FORMAT = "ꡐ윑청"
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (!value.endsWith(BELONG_FORMAT)) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sexysisters.tojserverv2.domain.school.domain

import com.sexysisters.tojserverv2.domain.school.exception.SchoolException
import javax.persistence.Column
import javax.persistence.Embeddable
import javax.validation.constraints.NotNull

@Embeddable
class Birthday(
@field:NotNull
@Column(name = "code")
val value: String
) {
init {
if (value.isBlank()) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sexysisters.tojserverv2.domain.school.domain

import com.sexysisters.tojserverv2.domain.school.exception.SchoolException
import javax.persistence.Column
import javax.persistence.Embeddable
import javax.validation.constraints.NotNull

@Embeddable
class Code(
@field:NotNull
@Column(name = "code", unique = true)
val value: String
) {
init {
val CODE_LENGTH = 7
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (value.length != CODE_LENGTH) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sexysisters.tojserverv2.domain.school.type
package com.sexysisters.tojserverv2.domain.school.domain

enum class Division(
val description: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sexysisters.tojserverv2.domain.school.domain

import com.sexysisters.tojserverv2.domain.school.exception.SchoolException
import javax.persistence.Column
import javax.persistence.Embeddable
import javax.validation.constraints.NotNull

@Embeddable
class HomePageAddress(
@field:NotNull
@Column(name = "home_page_address", unique = true)
val value: String
) {
init {
if (value.isBlank()) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sexysisters.tojserverv2.domain.school.type
package com.sexysisters.tojserverv2.domain.school.domain

enum class Kind(
val description: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sexysisters.tojserverv2.domain.school.domain

import com.sexysisters.tojserverv2.domain.school.exception.SchoolException
import javax.persistence.Column
import javax.persistence.Embeddable
import javax.validation.constraints.NotNull

@Embeddable
class Name(
@field:NotNull
@Column(name = "name")
val value: String
) {
init {
val MAX_LENGTH = 21
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (value.endsWith("학ꡐ")) throw SchoolException.SchoolNotValid()
if (value.length > MAX_LENGTH) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sexysisters.tojserverv2.domain.school.domain

import com.sexysisters.tojserverv2.domain.school.exception.SchoolException
import javax.persistence.Column
import javax.persistence.Embeddable
import javax.validation.constraints.NotNull

@Embeddable
class Phone(
@field:NotNull
@Column(name = "phone", unique = true)
val value: String
) {
init {
val MIN_LENGTH = 11
val MAX_LENTH = 12
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (value.length !in MIN_LENGTH..MAX_LENTH) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.sexysisters.tojserverv2.domain.school.domain

import com.sexysisters.tojserverv2.domain.BaseTimeEntity
import com.sexysisters.tojserverv2.domain.student.domain.Student
import com.sexysisters.tojserverv2.domain.teacher.domain.Teacher
import com.sexysisters.tojserverv2.domain.wiki.domain.Wiki
import javax.persistence.*

@Entity
@Table(name = "tbl_school")
class School(
@Embedded val code: Code,
@Embedded val belong: Belong,
@Embedded val name: Name,
@Embedded val address: Address,
@Embedded val birthday: Birthday,
@Embedded val homePageAddress: HomePageAddress,
@Embedded val phone: Phone,
// TODO :: 평점
) : BaseTimeEntity() {

@Enumerated(EnumType.STRING)
var division: Division? = null

@Enumerated(EnumType.STRING)
var kind: Kind? = null

@OneToMany(mappedBy = "school", cascade = [CascadeType.ALL])
val students = mutableSetOf<Student>()

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "wiki_id")
var wiki: Wiki? = null

@OneToMany(mappedBy = "school", cascade = [CascadeType.ALL])
val teachers = mutableSetOf<Teacher>()

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0L

fun getCodeValue() = code.value
fun getBelongValue() = belong.value
fun getNameValue() = name.value
fun getAddressValue() = address.value
fun getBirthdayValue() = birthday.value
fun getHomePageAddressValue() = homePageAddress.value
fun getPhoneValue() = phone.value
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.sexysisters.tojserverv2.domain.school.policy

import com.sexysisters.tojserverv2.domain.school.School
import com.sexysisters.tojserverv2.domain.school.domain.School
import com.sexysisters.tojserverv2.domain.school.exception.SchoolException
import com.sexysisters.tojserverv2.domain.student.Student
import com.sexysisters.tojserverv2.domain.student.domain.Student
import com.sexysisters.tojserverv2.infrastructure.student.StudentRepository
import org.springframework.core.annotation.Order
import org.springframework.stereotype.Component
Expand All @@ -19,9 +19,9 @@ class AlreadyExistsStudentPolicy(
override fun check(student: Student, school: School) {
val hasStudent = studentRepository.checkAlreadyExists(
school = school,
grade = student.grade,
classroom = student.classroom,
number = student.number,
grade = student.getGradeValue(),
classroom = student.getClassroomValue(),
number = student.getNumberValue(),
)
if (hasStudent) {
throw SchoolException.StudentAlreadyExists()
Expand Down
Loading

0 comments on commit 9331d68

Please sign in to comment.