Skip to content

Commit a7a53da

Browse files
committed
infra: Date, Time Converter 추가
1 parent 2367fab commit a7a53da

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package co.yappuworld.global.persistence.converter
2+
3+
import jakarta.persistence.AttributeConverter
4+
import jakarta.persistence.Converter
5+
import java.time.LocalDate
6+
import java.time.format.DateTimeFormatter
7+
8+
@Converter(autoApply = true)
9+
class LocalDateStringConverter : AttributeConverter<LocalDate, String> {
10+
11+
private val formatter = DateTimeFormatter.ISO_LOCAL_DATE // yyyy-MM-dd
12+
13+
override fun convertToDatabaseColumn(attribute: LocalDate?): String? = attribute?.format(formatter)
14+
15+
override fun convertToEntityAttribute(dbData: String?): LocalDate? = dbData?.let { LocalDate.parse(it, formatter) }
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package co.yappuworld.global.persistence.converter
2+
3+
import jakarta.persistence.AttributeConverter
4+
import jakarta.persistence.Converter
5+
import java.time.LocalTime
6+
import java.time.format.DateTimeFormatter
7+
8+
@Converter(autoApply = true)
9+
class LocalTimeStringConverter : AttributeConverter<LocalTime, String> {
10+
11+
private val formatter = DateTimeFormatter.ofPattern("HH:mm:ss")
12+
13+
override fun convertToDatabaseColumn(attribute: LocalTime?): String? = attribute?.format(formatter)
14+
15+
override fun convertToEntityAttribute(dbData: String?): LocalTime? = dbData?.let { LocalTime.parse(it, formatter) }
16+
}

src/main/kotlin/co/yappuworld/schedule/infrastructure/entity/ScheduleEntity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ abstract class ScheduleEntity : BaseEntity() {
3838
abstract var address: String?
3939
abstract var latitude: Double?
4040
abstract var longitude: Double?
41-
4241
abstract val date: LocalDate
4342
abstract val endDate: LocalDate
44-
4543
abstract val time: LocalTime
4644
abstract val endTime: LocalTime
4745
abstract val isAllDay: Boolean

src/main/kotlin/co/yappuworld/schedule/infrastructure/entity/SessionEntity.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package co.yappuworld.schedule.infrastructure.entity
22

33
import co.yappuworld.global.exception.BusinessException
4+
import co.yappuworld.global.persistence.converter.LocalDateStringConverter
5+
import co.yappuworld.global.persistence.converter.LocalTimeStringConverter
46
import co.yappuworld.global.util.DatetimeUtils.korean
57
import co.yappuworld.schedule.domain.AttendancePolicy.ABSENT_AFTER_SESSION_START_HOURS
68
import co.yappuworld.schedule.domain.AttendancePolicy.CHECK_IN_AVAILABLE_BEFORE_SESSION_START_MINUTES
@@ -9,6 +11,7 @@ import co.yappuworld.schedule.domain.vo.AttendanceError
911
import co.yappuworld.schedule.domain.vo.AttendanceStatus
1012
import co.yappuworld.schedule.domain.vo.SessionType
1113
import jakarta.persistence.Column
14+
import jakarta.persistence.Convert
1215
import jakarta.persistence.DiscriminatorValue
1316
import jakarta.persistence.Entity
1417
import jakarta.persistence.EnumType
@@ -26,11 +29,17 @@ class SessionEntity(
2629
override var address: String? = null,
2730
override var latitude: Double? = null,
2831
override var longitude: Double? = null,
29-
@field:Column(name = "start_date")
32+
@field:Column(name = "START_DATE")
33+
@get:Convert(converter = LocalDateStringConverter::class)
3034
override var date: LocalDate,
35+
@field:Column(name = "END_DATE")
36+
@get:Convert(converter = LocalDateStringConverter::class)
3137
override var endDate: LocalDate,
32-
@field:Column(name = "start_time")
38+
@field:Column(name = "START_TIME")
39+
@get:Convert(converter = LocalTimeStringConverter::class)
3340
override var time: LocalTime,
41+
@field:Column(name = "END_TIME")
42+
@get:Convert(converter = LocalTimeStringConverter::class)
3443
override var endTime: LocalTime,
3544
override var isAllDay: Boolean,
3645
generation: Int,

0 commit comments

Comments
 (0)