Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Wrap the primitive type of domain #100

Merged
merged 16 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 12 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
@@ -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
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,18 @@
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", nullable = false, unique = true)
val value: String
) {
init {
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (value.length > 34) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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", nullable = false)
val value: String
) {
init {
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (!value.endsWith("교육청")) throw SchoolException.SchoolNotValid()
leekyukin marked this conversation as resolved.
Show resolved Hide resolved
}
}
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", nullable = false)
val value: String
) {
init {
if (value.isBlank()) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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", nullable = false, unique = true)
val value: String
) {
init {
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (value.length != 7) throw SchoolException.SchoolNotValid()
leekyukin marked this conversation as resolved.
Show resolved Hide resolved
}
}
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", nullable = false, unique = true)
leekyukin marked this conversation as resolved.
Show resolved Hide resolved
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,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 Name(
@field:NotNull
@Column(name = "name", nullable = false)
val value: String
) {
init {
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (value.endsWith("학교")) throw SchoolException.SchoolNotValid()
if (value.length > 21) throw SchoolException.SchoolNotValid()
leekyukin marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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", nullable = false, unique = true)
val value: String
) {
init {
if (value.isBlank()) throw SchoolException.SchoolNotValid()
if (value.length >= 12) throw SchoolException.SchoolNotValid()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 = mutableListOf<Student>()

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

@OneToMany(mappedBy = "school", cascade = [CascadeType.ALL])
val teachers = mutableListOf<Teacher>()
leekyukin marked this conversation as resolved.
Show resolved Hide resolved

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0L
}
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.grade.value,
classroom = student.classroom.value,
number = student.number.value,
leekyukin marked this conversation as resolved.
Show resolved Hide resolved
)
if (hasStudent) {
throw SchoolException.StudentAlreadyExists()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.sexysisters.tojserverv2.domain.school.policy

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

Expand All @@ -15,7 +15,7 @@ import org.springframework.stereotype.Component
class DirectJoinPolicy : SchoolPolicy {

override fun check(student: Student, school: School) {
val studentCount = school.studentList.size
val studentCount = school.students.size
if (studentCount <= 5) {
student.engaged()
} else {
Expand Down
Loading