Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
add domain & vo(with rename)
Browse files Browse the repository at this point in the history
  • Loading branch information
dojinyou committed Jan 29, 2024
1 parent 2d2911a commit c69c4ad
Show file tree
Hide file tree
Showing 20 changed files with 180 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.studentcenter.weave.bootstrap.adapter.api
import com.studentcenter.weave.bootstrap.adapter.dto.DomainAddressResponse
import com.studentcenter.weave.bootstrap.adapter.dto.MajorsResponse
import com.studentcenter.weave.bootstrap.adapter.dto.UniversitiesResponse
import com.studentcenter.weave.domain.vo.UniversityName
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
Expand All @@ -20,10 +21,10 @@ interface UnivApi {

@Operation(summary = "Get all major by university")
@GetMapping("/{univName}/majors")
fun getAllMajorByUniv(@PathVariable univName: String): MajorsResponse
fun getAllMajorByUniv(@PathVariable univName: UniversityName): MajorsResponse

@Operation(summary = "Get domain address by university")
@GetMapping("/{univName}/domain-address")
fun getDomainAddressByUniv(@PathVariable univName: String): DomainAddressResponse
fun getDomainAddressByUniv(@PathVariable univName: UniversityName): DomainAddressResponse

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.studentcenter.weave.bootstrap.adapter.dto.DomainAddressResponse
import com.studentcenter.weave.bootstrap.adapter.dto.MajorsResponse
import com.studentcenter.weave.bootstrap.adapter.dto.UniversitiesResponse
import com.studentcenter.weave.bootstrap.common.exception.ApiExceptionType
import com.studentcenter.weave.domain.vo.University
import com.studentcenter.weave.domain.vo.UniversityName
import com.studentcenter.weave.support.common.exception.CustomException
import org.springframework.web.bind.annotation.RestController

Expand All @@ -14,35 +14,35 @@ class UnivRestController : UnivApi {

override fun findAll(): UniversitiesResponse {
return UniversitiesResponse(listOf(
University(KU),
University(DKU),
University(MJU),
UniversityName(KU),
UniversityName(DKU),
UniversityName(MJU),
))
}

override fun getAllMajorByUniv(univName: String): MajorsResponse {
override fun getAllMajorByUniv(univName: UniversityName): MajorsResponse {
validUnivName(univName)

return MajorsResponse(
if (KU == univName) KU_MAJORS
else if (DKU == univName) DKU_MAJORS
if (KU == univName.value) KU_MAJORS
else if (DKU == univName.value) DKU_MAJORS
else MJU_MAJORS
)
}

override fun getDomainAddressByUniv(univName: String): DomainAddressResponse {
override fun getDomainAddressByUniv(univName: UniversityName): DomainAddressResponse {
validUnivName(univName)

return DomainAddressResponse(
if (KU == univName) "konkuk.ac.kr"
else if (DKU == univName) "dankook.ac.kr"
if (KU == univName.value) "konkuk.ac.kr"
else if (DKU == univName.value) "dankook.ac.kr"
else "mju.ac.kr"
)

}

private fun validUnivName(univName: String) {
if (setOf(KU, DKU, MJU).contains(univName)) {
private fun validUnivName(univName: UniversityName) {
if (setOf(KU, DKU, MJU).contains(univName.value)) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.studentcenter.weave.bootstrap.adapter.dto
import com.studentcenter.weave.domain.enum.Gender
import com.studentcenter.weave.domain.enum.Mbti
import com.studentcenter.weave.domain.vo.BirthYear
import com.studentcenter.weave.domain.vo.Major
import com.studentcenter.weave.domain.vo.University
import com.studentcenter.weave.domain.vo.MajorName
import com.studentcenter.weave.domain.vo.UniversityName
import io.swagger.v3.oas.annotations.media.Schema

@Schema(
Expand All @@ -15,6 +15,6 @@ data class RegisterUserRequest(
val gender: Gender,
val birthYear: BirthYear,
val mbti: Mbti,
val university: University,
val major: Major,
val university: UniversityName,
val major: MajorName,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.studentcenter.weave.bootstrap.adapter.dto

import com.studentcenter.weave.domain.vo.University
import com.studentcenter.weave.domain.vo.UniversityName
import io.swagger.v3.oas.annotations.media.Schema


Expand All @@ -9,5 +9,5 @@ import io.swagger.v3.oas.annotations.media.Schema
description = "조회된 모든 대학교를 반환합니다",
)
data class UniversitiesResponse(
val universities: List<University>
val universities: List<UniversityName>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.studentcenter.weave.domain.entity

import com.studentcenter.weave.domain.vo.MajorName
import com.studentcenter.weave.support.common.uuid.UuidCreator
import java.time.LocalDateTime
import java.util.*

data class Major(
val id: UUID = UuidCreator.create(),
val univId:UUID,
val name: MajorName,
val createdAt: LocalDateTime = LocalDateTime.now(),
) {


companion object {
fun create(univId: UUID, name: MajorName): Major {
return Major(univId = univId, name = name)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.studentcenter.weave.domain.entity

import com.studentcenter.weave.domain.vo.UniversityName
import com.studentcenter.weave.support.common.uuid.UuidCreator
import java.time.LocalDateTime
import java.util.*

data class University(
val id: UUID = UuidCreator.create(),
val name: UniversityName,
val domainAddress: String,
val logoAddress: String,
val createdAt: LocalDateTime = LocalDateTime.now(),
val updatedAt: LocalDateTime = LocalDateTime.now(),
) {


companion object {
fun create(
name: UniversityName,
domainAddress: String,
logoAddress: String,
): University {
return University(
name = name,
domainAddress = domainAddress,
logoAddress = logoAddress,
)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.studentcenter.weave.domain.entity
import com.studentcenter.weave.domain.enum.Gender
import com.studentcenter.weave.domain.enum.Mbti
import com.studentcenter.weave.domain.vo.BirthYear
import com.studentcenter.weave.domain.vo.Major
import com.studentcenter.weave.domain.vo.MajorName
import com.studentcenter.weave.domain.vo.Nickname
import com.studentcenter.weave.domain.vo.University
import com.studentcenter.weave.domain.vo.UniversityName
import com.studentcenter.weave.support.common.uuid.UuidCreator
import com.studentcenter.weave.support.common.vo.Email
import com.studentcenter.weave.support.common.vo.Url
Expand All @@ -19,8 +19,8 @@ data class User(
val gender: Gender,
val mbti: Mbti,
val birthYear: BirthYear,
val university: University,
val major: Major,
val university: UniversityName,
val major: MajorName,
val avatar: Url? = null,
val registeredAt: LocalDateTime = LocalDateTime.now(),
val updatedAt: LocalDateTime = LocalDateTime.now(),
Expand All @@ -34,8 +34,8 @@ data class User(
gender: Gender,
mbti: Mbti,
birthYear: BirthYear,
university: University,
major: Major,
university: UniversityName,
major: MajorName,
avatar: Url? = null,
): User {
return User(
Expand Down
11 changes: 0 additions & 11 deletions domain/src/main/kotlin/com/studentcenter/weave/domain/vo/Major.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.studentcenter.weave.domain.vo

@JvmInline
value class MajorName(val value: String) {

init {
require(value.isNotBlank()) { "전공명은 공백일 수 없습니다." }
require(value.length <= 30) { "전공명은 30자 이하여야 합니다." }
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.studentcenter.weave.domain.vo

@JvmInline
value class UniversityName(val value: String) {

init {
require(value.isNotBlank()) { "대학교 이름은 공백일 수 없습니다." }
require(value.length <= 30) { "대학교 이름은 30자 이하여야 합니다." }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.studentcenter.weave.domain.entity
import com.studentcenter.weave.domain.vo.MajorName
import com.studentcenter.weave.support.common.uuid.UuidCreator
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.comparables.shouldBeLessThanOrEqualTo
import io.kotest.matchers.shouldBe
import java.time.LocalDateTime

class MajorTest : FunSpec({

test("대학교 생성") {
// arrange
val name = MajorName(value = "컴퓨터공학과")

// act
val major = Major.create(
univId = UuidCreator.create(),
name = name
)

// assert
major.name shouldBe name
major.createdAt shouldBeLessThanOrEqualTo LocalDateTime.now()
}

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.studentcenter.weave.domain.entity

import com.studentcenter.weave.domain.vo.UniversityName
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.comparables.shouldBeLessThanOrEqualTo
import io.kotest.matchers.shouldBe
import java.time.LocalDateTime

class UniversityTest : FunSpec({

test("대학교 생성") {
// arrange
val name = UniversityName("명지대학교")
val domainAddress = "mju.ac.kr"
val logoAddress = "/public/university/1/logo"

// act
val univ = University.create(
name = name,
domainAddress = domainAddress,
logoAddress = logoAddress,
)

// assert
univ.name shouldBe name
univ.domainAddress shouldBe domainAddress
univ.logoAddress shouldBe logoAddress
univ.createdAt shouldBeLessThanOrEqualTo LocalDateTime.now()
}

})
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.studentcenter.weave.domain.entity

import com.studentcenter.weave.domain.enum.SocialLoginProvider
import com.studentcenter.weave.domain.vo.Nickname
import com.studentcenter.weave.support.common.vo.Email
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package com.studentcenter.weave.domain.entity
import com.studentcenter.weave.domain.enum.Gender
import com.studentcenter.weave.domain.enum.Mbti
import com.studentcenter.weave.domain.vo.BirthYear
import com.studentcenter.weave.domain.vo.Major
import com.studentcenter.weave.domain.vo.MajorName
import com.studentcenter.weave.domain.vo.Nickname
import com.studentcenter.weave.domain.vo.University
import com.studentcenter.weave.domain.vo.UniversityName
import com.studentcenter.weave.support.common.vo.Email
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import java.time.Instant
import java.time.LocalDateTime

class UserTest : FunSpec({

Expand All @@ -20,8 +18,8 @@ class UserTest : FunSpec({
val email = Email("[email protected]")
val gender = Gender.MAN
val birthYear = BirthYear(1999)
val university = University("서울대학교")
val major = Major("컴퓨터 공학과")
val university = UniversityName("서울대학교")
val major = MajorName("컴퓨터 공학과")
val mbti = Mbti.ENFJ

// act
Expand All @@ -44,10 +42,4 @@ class UserTest : FunSpec({
user.major shouldBe major
}

test("test") {
println(Instant.now())
println(LocalDateTime.now())
}


})
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package com.studentcenter.weave.domain.vo
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

class MajorTest : FunSpec({
class MajorNameTest : FunSpec({

test("전공명은 공백일 수 없습니다.") {
runCatching { Major(" ") }.onFailure {
runCatching { MajorName(" ") }.onFailure {
it.message shouldBe "전공명은 공백일 수 없습니다."
}
}

test("전공명은 30자 이하여야 합니다.") {
runCatching { Major("a".repeat(31)) }.onFailure {
runCatching { MajorName("a".repeat(31)) }.onFailure {
it.message shouldBe "전공명은 30자 이하여야 합니다."
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package com.studentcenter.weave.domain.vo
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

class UniversityTest : FunSpec({
class UniversityNameTest : FunSpec({

test("대학교 이름은 공백일 수 없습니다.") {
runCatching { University(" ") }.onFailure {
runCatching { UniversityName(" ") }.onFailure {
it.message shouldBe "대학교 이름은 공백일 수 없습니다."
}
}

test("대학교 이름은 30자 이하여야 합니다.") {
runCatching { University("a".repeat(31)) }.onFailure {
runCatching { UniversityName("a".repeat(31)) }.onFailure {
it.message shouldBe "대학교 이름은 30자 이하여야 합니다."
}
}
Expand Down
Loading

0 comments on commit c69c4ad

Please sign in to comment.