Skip to content

Commit

Permalink
merge: (#164) 휴무일 설계 (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 authored Dec 2, 2022
2 parents d51c408 + 6b0ed3a commit 0ad0a01
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package team.comit.simtong.domain.holiday.error

import team.comit.simtong.global.error.ErrorProperty

/**
*
* 휴무일에 관한 Error Code를 관리하는 HolidayErrorCode
*
* @author Chokyunghyeon
* @date 2022/12/02
* @version 1.0.0
**/
enum class HolidayErrorCode(
private val status: Int,
private val message: String
) : ErrorProperty {

;

override fun status(): Int = status

override fun message(): String = message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package team.comit.simtong.domain.holiday.model

import team.comit.simtong.global.annotation.Aggregate
import java.time.LocalDate
import java.util.UUID

/**
*
* 휴무일의 Root Aggregate를 담당하는 Holiday
*
* @author Chokyunghyeon
* @date 2022/12/02
* @version 1.0.0
**/
@Aggregate
data class Holiday(
val date: LocalDate,

val userId: UUID,

val type: HolidayType,

val spotId: UUID

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package team.comit.simtong.domain.holiday.model

/**
*
* 휴무일 유형를 관리하는 HolidayType
*
* @author Chokyunghyeon
* @date 2022/12/02
* @version 1.0.0
**/
enum class HolidayType {

/**
* 휴무일
*/
HOLIDAY,

/**
* 연차
*/
ANNUAL
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team.comit.simtong.persistence.holiday

import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository
import team.comit.simtong.persistence.holiday.entity.HolidayId
import team.comit.simtong.persistence.holiday.entity.HolidayJpaEntity

/**
*
* Spring Repository의 기능을 이용하는 HolidayJpaRepository
*
* @author Chokyunghyeon
* @date 2022/12/02
* @version 1.0.0
**/
@Repository
interface HolidayJpaRepository : CrudRepository<HolidayJpaEntity, HolidayId> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package team.comit.simtong.persistence.holiday

import org.springframework.stereotype.Component
import team.comit.simtong.persistence.holiday.mapper.HolidayMapper

/**
*
* 휴무일의 영속성을 관리하는 HolidayPersistenceAdapter
*
* @author Chokyunghyeon
* @date 2022/12/02
* @version 1.0.0
**/
@Component
class HolidayPersistenceAdapter(
private val holidayMapper: HolidayMapper,
private val holidayJpaRepository: HolidayJpaRepository
) {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package team.comit.simtong.persistence.holiday.entity

import java.io.Serializable
import java.time.LocalDate
import java.util.UUID
import javax.persistence.Column
import javax.persistence.Embeddable

/**
*
* 휴무일의 기본키를 구성하는 HolidayId
*
* @author Chokyunghyeon
* @date 2022/12/02
* @version 1.0.0
**/
@Embeddable
data class HolidayId(

@Column(nullable = false)
val date: LocalDate,

@Column(nullable = false)
val userId: UUID
) : Serializable
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package team.comit.simtong.persistence.holiday.entity

import team.comit.simtong.domain.holiday.model.HolidayType
import team.comit.simtong.persistence.spot.entity.SpotJpaEntity
import team.comit.simtong.persistence.user.entity.UserJpaEntity
import javax.persistence.EmbeddedId
import javax.persistence.Entity
import javax.persistence.EnumType
import javax.persistence.Enumerated
import javax.persistence.FetchType
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.MapsId
import javax.persistence.Table
import javax.validation.constraints.NotNull

/**
*
* 유저의 휴무일을 관리하는 HolidayJpaEntity
*
* @author Chokyunghyeon
* @date 2022/12/02
* @version 1.0.0
**/
@Entity
@Table(name = "tbl_holiday")
class HolidayJpaEntity(

@EmbeddedId
val id: HolidayId,

@field:NotNull
@Enumerated(EnumType.STRING)
val type: HolidayType,

@MapsId("userId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", columnDefinition = "BINARY(16)", nullable = false)
val user: UserJpaEntity,

@field:NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "spot_id", columnDefinition = "BINARY(16)", nullable = false)
val spot: SpotJpaEntity

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package team.comit.simtong.persistence.holiday.mapper

import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.Mappings
import org.springframework.beans.factory.annotation.Autowired
import team.comit.simtong.domain.holiday.model.Holiday
import team.comit.simtong.persistence.GenericMapper
import team.comit.simtong.persistence.holiday.entity.HolidayJpaEntity
import team.comit.simtong.persistence.spot.SpotJpaRepository
import team.comit.simtong.persistence.user.repository.UserJpaRepository

/**
*
* 휴무일 엔티티와 도메인 휴무일 변환을 담당하는 HolidayMapper
*
* @author Chokyunghyeon
* @date 2022/12/02
* @version 1.0.0
**/
@Mapper
abstract class HolidayMapper : GenericMapper<HolidayJpaEntity, Holiday> {

@Autowired
protected lateinit var userJpaRepository: UserJpaRepository

@Autowired
protected lateinit var spotJpaRepository: SpotJpaRepository

@Mappings(
Mapping(target = "userId", expression = "java(entity.getId().getUserId())"),
Mapping(target = "spotId", expression = "java(entity.getSpot().getId())"),
Mapping(target = "date", expression = "java(entity.getId().getDate())")
)
abstract override fun toDomain(entity: HolidayJpaEntity?): Holiday?

@Mappings(
Mapping(target = "user", expression = "java(userJpaRepository.findById(model.getUserId()).orElse(null))"),
Mapping(target = "spot", expression = "java(spotJpaRepository.findById(model.getSpotId()).orElse(null))"),
Mapping(target = "id", expression = "java(new HolidayId(model.getDate(), model.getUserId()))")
)
abstract override fun toEntity(model: Holiday): HolidayJpaEntity
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package team.comit.simtong.persistence.menu.repository

import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository
import team.comit.simtong.persistence.menu.entity.MenuId
import team.comit.simtong.persistence.menu.entity.MenuJpaEntity
import java.time.LocalDate

/**
*
Expand All @@ -14,5 +14,5 @@ import java.time.LocalDate
* @version 1.0.0
**/
@Repository
interface MenuJpaRepository : CrudRepository<MenuJpaEntity, LocalDate> {
interface MenuJpaRepository : CrudRepository<MenuJpaEntity, MenuId> {
}

0 comments on commit 0ad0a01

Please sign in to comment.