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

Commit

Permalink
[WEAV-164] 외부 인프라 레이어 value class 사용하지 않도록 수정 (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW authored Feb 4, 2024
1 parent 6fd9a7f commit 0392b72
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class CustomExceptionHandler {
)
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(IllegalArgumentException::class)
fun handleIllegalArgumentException(exception: IllegalArgumentException): ErrorResponse {
return ErrorResponse(
exceptionCode = ApiExceptionType.INVALID_PARAMETER.code,
message = exception.message!!,
)
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(DateTimeException::class)
fun handleDateTimeException(exception: DateTimeException): ErrorResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import com.studentcenter.weave.bootstrap.university.dto.UniversityResponse
import com.studentcenter.weave.bootstrap.university.dto.MajorsResponse
import com.studentcenter.weave.bootstrap.university.dto.UniversitiesResponse
import com.studentcenter.weave.bootstrap.common.exception.ApiExceptionType
import com.studentcenter.weave.domain.university.vo.MajorName
import com.studentcenter.weave.domain.university.vo.UniversityName
import com.studentcenter.weave.support.common.exception.CustomException
import com.studentcenter.weave.support.common.uuid.UuidCreator
import org.springframework.web.bind.annotation.PathVariable
Expand Down Expand Up @@ -48,11 +46,11 @@ class UnivRestController : UnivApi {

companion object {
private val KU_ID = UuidCreator.create()
private val KU = UniversityResponse(KU_ID, UniversityName("건국대학교"), "konkuk.ac.kr", "public/university/$KU_ID/logo")
private val KU = UniversityResponse(KU_ID, "건국대학교", "konkuk.ac.kr", "public/university/$KU_ID/logo")
private val DKU_ID = UuidCreator.create()
private val DKU = UniversityResponse(DKU_ID, UniversityName("단국대학교"), "dankook.ac.kr", "public/university/$DKU_ID/logo")
private val DKU = UniversityResponse(DKU_ID, "단국대학교", "dankook.ac.kr", "public/university/$DKU_ID/logo")
private val MJU_ID = UuidCreator.create()
private val MJU = UniversityResponse(MJU_ID, UniversityName("명지대학교"), "mju.ac.kr", "public/university/$MJU_ID/logo")
private val MJU = UniversityResponse(MJU_ID, "명지대학교", "mju.ac.kr", "public/university/$MJU_ID/logo")
private val KU_MAJORS = listOf(
"화장품공학과",
"국제무역학과",
Expand Down Expand Up @@ -116,7 +114,7 @@ class UnivRestController : UnivApi {
"건축학부",
"미디어커뮤니케이션학과",
"체육교육과",
).map { MajorsResponse.MajorDto(UuidCreator.create(), MajorName(it)) }
).map { MajorsResponse.MajorDto(UuidCreator.create(), it) }
private val DKU_MAJORS = listOf(
"국제스포츠학부 태권도전공",
"생명자원학부 식량생명공학전공",
Expand Down Expand Up @@ -273,7 +271,7 @@ class UnivRestController : UnivApi {
"의과대학",
"무역학과",
"치의학과",
).map { MajorsResponse.MajorDto(UuidCreator.create(), MajorName(it)) }
).map { MajorsResponse.MajorDto(UuidCreator.create(), it) }
private val MJU_MAJORS = listOf(
"융합전공학부(인문)",
"전공자유학부",
Expand Down Expand Up @@ -379,6 +377,6 @@ class UnivRestController : UnivApi {
"인문대학",
"교양학과",
"만화애니콘텐츠학과",
).map { MajorsResponse.MajorDto(UuidCreator.create(), MajorName(it)) }
).map { MajorsResponse.MajorDto(UuidCreator.create(), it) }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.studentcenter.weave.bootstrap.university.dto

import com.studentcenter.weave.domain.university.entity.Major
import com.studentcenter.weave.domain.university.vo.MajorName
import io.swagger.v3.oas.annotations.media.Schema
import java.util.*

Expand All @@ -14,11 +13,11 @@ data class MajorsResponse(
val majors: List<MajorDto>
) {

data class MajorDto(val id: UUID, val name: MajorName)
data class MajorDto(val id: UUID, val name: String)

companion object {
fun from(domains: List<Major>): MajorsResponse {
return MajorsResponse(domains.map { MajorDto(it.id, it.name) })
return MajorsResponse(domains.map { MajorDto(it.id, it.name.value) })
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.studentcenter.weave.bootstrap.university.dto

import com.studentcenter.weave.domain.university.entity.University
import com.studentcenter.weave.domain.university.vo.UniversityName
import io.swagger.v3.oas.annotations.media.Schema
import java.util.*

Expand All @@ -13,16 +12,18 @@ import java.util.*
data class UniversitiesResponse(
val universities: List<UniversityDto>
) {

data class UniversityDto(
val id: UUID,
val name: UniversityName,
val name: String,
val domainAddress: String,
val logoAddress: String,
)

companion object {

fun from(domains: List<University>) = UniversitiesResponse(
domains.map { UniversityDto(it.id, it.name, it.domainAddress, it.logoAddress) }
domains.map { UniversityDto(it.id, it.name.value, it.domainAddress, it.logoAddress) }
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.studentcenter.weave.bootstrap.university.dto

import com.studentcenter.weave.domain.university.entity.University
import com.studentcenter.weave.domain.university.vo.UniversityName
import io.swagger.v3.oas.annotations.media.Schema
import java.util.UUID
import java.util.*


@Schema(
Expand All @@ -12,15 +11,16 @@ import java.util.UUID
)
data class UniversityResponse(
val id: UUID,
val name: UniversityName,
val name: String,
val domainAddress: String,
val logoAddress: String,
) {

companion object {

fun from(domain: University) = UniversityResponse(
id = domain.id,
name = domain.name,
name = domain.name.value,
domainAddress = domain.domainAddress,
logoAddress = domain.logoAddress,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import com.studentcenter.weave.bootstrap.user.api.UserApi
import com.studentcenter.weave.bootstrap.user.dto.UserGetMyProfileResponse
import com.studentcenter.weave.bootstrap.user.dto.UserRegisterRequest
import com.studentcenter.weave.bootstrap.user.dto.UserRegisterResponse
import com.studentcenter.weave.domain.university.vo.MajorName
import com.studentcenter.weave.domain.user.vo.BirthYear
import com.studentcenter.weave.domain.user.vo.Mbti
import com.studentcenter.weave.domain.user.vo.Nickname
import com.studentcenter.weave.support.common.uuid.UuidCreator
import com.studentcenter.weave.support.common.vo.Url
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RestController
Expand All @@ -33,8 +30,8 @@ class UserRestController(
email = registerTokenClaim.email,
socialLoginProvider = registerTokenClaim.socialLoginProvider,
gender = request.gender,
mbti = request.mbti,
birthYear = request.birthYear,
mbti = Mbti(request.mbti),
birthYear = BirthYear(request.birthYear),
universityId = request.universityId,
majorId = request.majorId,
)
Expand All @@ -58,11 +55,11 @@ class UserRestController(
override fun getMyProfile(): UserGetMyProfileResponse {
return UserGetMyProfileResponse(
id = UuidCreator.create(),
nickname = Nickname("test"),
birthYear = BirthYear(1999),
majorName = MajorName("컴퓨터 공학과"),
avatar = Url("https://test.com"),
mbti = Mbti("INFP"),
nickname = "test",
birthYear = 1999,
majorName = "컴퓨터 공학과",
avatar = "https://test.com",
mbti = "INFP",
animalType = null,
height = null,
isUniversityEmailVerified = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.studentcenter.weave.bootstrap.user.dto

import com.studentcenter.weave.domain.user.enums.AnimalType
import com.studentcenter.weave.domain.user.vo.BirthYear
import com.studentcenter.weave.domain.university.vo.MajorName
import com.studentcenter.weave.domain.user.vo.Mbti
import com.studentcenter.weave.domain.user.vo.Nickname
import com.studentcenter.weave.support.common.vo.Url
import io.swagger.v3.oas.annotations.media.Schema
import java.util.*

Expand All @@ -14,15 +9,15 @@ data class UserGetMyProfileResponse(
@Schema(description = "유저 아이디")
val id: UUID,
@Schema(description = "닉네임")
val nickname: Nickname,
val nickname: String,
@Schema(description = "생년")
val birthYear: BirthYear,
val birthYear: Int,
@Schema(description = "전공명")
val majorName: MajorName,
val majorName: String,
@Schema(description = "프로필 이미지")
val avatar: Url?,
val avatar: String?,
@Schema(description = "MBTI")
val mbti: Mbti,
val mbti: String,
@Schema(description = "닮은 동물")
val animalType: AnimalType?,
@Schema(description = "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.studentcenter.weave.bootstrap.user.dto

import com.studentcenter.weave.domain.user.enums.Gender
import com.studentcenter.weave.domain.user.vo.Mbti
import com.studentcenter.weave.domain.user.vo.BirthYear
import io.swagger.v3.oas.annotations.media.Schema
import java.util.*

Expand All @@ -12,8 +10,8 @@ import java.util.*
)
data class UserRegisterRequest(
val gender: Gender,
val birthYear: BirthYear,
val mbti: Mbti,
val birthYear: Int,
val mbti: String,
val universityId: UUID,
val majorId: UUID,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.studentcenter.weave.domain.user.vo
import java.time.Year

@JvmInline
value class BirthYear(val year: Int) {
value class BirthYear(val value: Int) {

init {
require(year in 1900..Year.now().value) {
require(value in 1900..Year.now().value) {
"생년월일은 1900년 이후, 현재 년도 이전이어야 합니다"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.studentcenter.weave.domain.user.vo

@JvmInline
value class Height(val height: Int) {
value class Height(val value: Int) {

init {
require(height in 1..300) {
require(value in 1..300) {
"키는 1cm 이상 300cm 이하여야 합니다."
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.studentcenter.weave.infrastructure.persistence.university.entity

import com.studentcenter.weave.domain.university.vo.MajorName
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
Expand All @@ -13,9 +12,10 @@ import java.util.*
class MajorJpaEntity(
id: UUID,
univId: UUID,
name: MajorName,
name: String,
createdAt: LocalDateTime,
) {

@Id
var id: UUID = id
private set
Expand All @@ -25,7 +25,7 @@ class MajorJpaEntity(
private set

@Column(nullable = false)
var name: MajorName = name
var name: String = name
private set

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.studentcenter.weave.infrastructure.persistence.university.entity

import com.studentcenter.weave.domain.university.vo.UniversityName
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
Expand All @@ -12,18 +11,19 @@ import java.util.*
@Table(name = "university")
class UniversityJpaEntity(
id: UUID,
name: UniversityName,
name: String,
domainAddress: String,
logoAddress: String,
createdAt: LocalDateTime,
updatedAt: LocalDateTime,
) {

@Id
var id: UUID = id
private set

@Column(unique = true, nullable = false)
var name: UniversityName = name
var name: String = name
private set

@Column(nullable = false, columnDefinition = "varchar(255)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.studentcenter.weave.infrastructure.persistence.user.entity

import com.studentcenter.weave.domain.user.entity.DeletedUserInfo
import com.studentcenter.weave.domain.user.enums.SocialLoginProvider
import com.studentcenter.weave.support.common.vo.Email
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
Expand All @@ -14,21 +13,21 @@ import java.util.*

@Entity
@Table(name = "deleted_user_info")
class DeletedUserInfoJpaEntity (
class DeletedUserInfoJpaEntity(
id: UUID,
email: Email,
email: String,
socialLoginProvider: SocialLoginProvider,
reason: String? = null,
registeredAt: LocalDateTime,
deletedAt: LocalDateTime
){
) {

@Id
var id: UUID = id
private set

@Column(nullable = false)
var email: Email = email
var email: String = email
private set

@Column(nullable = false, columnDefinition = "varchar(255)")
Expand All @@ -49,10 +48,11 @@ class DeletedUserInfoJpaEntity (
private set

companion object {

fun DeletedUserInfo.toJpaEntity(): DeletedUserInfoJpaEntity {
return DeletedUserInfoJpaEntity(
id = id,
email = email,
email = email.value,
socialLoginProvider = socialLoginProvider,
reason = reason,
registeredAt = registeredAt,
Expand Down
Loading

0 comments on commit 0392b72

Please sign in to comment.