diff --git a/src/main/kotlin/com/fitmate/batchservice/dto/certification/FitCertificationDetailResponseDto.kt b/src/main/kotlin/com/fitmate/batchservice/dto/certification/FitCertificationDetailResponseDto.kt index 8895d0d..d82433e 100644 --- a/src/main/kotlin/com/fitmate/batchservice/dto/certification/FitCertificationDetailResponseDto.kt +++ b/src/main/kotlin/com/fitmate/batchservice/dto/certification/FitCertificationDetailResponseDto.kt @@ -1,6 +1,7 @@ package com.fitmate.batchservice.dto.certification import com.fitmate.batchservice.persistence.entity.CertificationStatus +import com.fitmate.batchservice.utils.DateParseUtils import java.time.Instant data class FitCertificationDetailResponseDto( @@ -9,6 +10,8 @@ data class FitCertificationDetailResponseDto( val userId: Int, val certificationStatus: CertificationStatus, val state: Boolean, - val createdAt: Instant, - val voteEndDate: Instant -) + val createdAt: String, + val voteEndDate: String +) { + val voteEndDateInstant: Instant = DateParseUtils.stringToInstant(voteEndDate) +} diff --git a/src/main/kotlin/com/fitmate/batchservice/dto/certification/FitCertificationResultResponse.kt b/src/main/kotlin/com/fitmate/batchservice/dto/certification/FitCertificationResultResponse.kt index 6ccb2d2..6b54010 100644 --- a/src/main/kotlin/com/fitmate/batchservice/dto/certification/FitCertificationResultResponse.kt +++ b/src/main/kotlin/com/fitmate/batchservice/dto/certification/FitCertificationResultResponse.kt @@ -1,10 +1,13 @@ package com.fitmate.batchservice.dto.certification import com.fitmate.batchservice.persistence.entity.CertificationStatus +import com.fitmate.batchservice.utils.DateParseUtils import java.time.Instant data class FitCertificationResultResponse( val fitCertificationId: Long, val certificationStatus: CertificationStatus, - val createdAt: Instant -) \ No newline at end of file + private val createdAtInstant: Instant +) { + val createdAt: String = DateParseUtils.instantToString(createdAtInstant) +} \ No newline at end of file diff --git a/src/main/kotlin/com/fitmate/batchservice/dto/penalty/FitPenaltyDetailResponse.kt b/src/main/kotlin/com/fitmate/batchservice/dto/penalty/FitPenaltyDetailResponse.kt index d2196b0..709c5cd 100644 --- a/src/main/kotlin/com/fitmate/batchservice/dto/penalty/FitPenaltyDetailResponse.kt +++ b/src/main/kotlin/com/fitmate/batchservice/dto/penalty/FitPenaltyDetailResponse.kt @@ -1,5 +1,6 @@ package com.fitmate.batchservice.dto.penalty +import com.fitmate.batchservice.utils.DateParseUtils import java.time.Instant data class FitPenaltyDetailResponse( @@ -7,5 +8,7 @@ data class FitPenaltyDetailResponse( val fitGroupId: Long, val userId: Int, val amount: Int, - val createdAt: Instant -) + private val createdAtInstant: Instant +) { + val createdAt: String = DateParseUtils.instantToString(createdAtInstant) +} diff --git a/src/main/kotlin/com/fitmate/batchservice/persistence/entity/FitCertificationForRead.kt b/src/main/kotlin/com/fitmate/batchservice/persistence/entity/FitCertificationForRead.kt index 8ee4f29..24cb608 100644 --- a/src/main/kotlin/com/fitmate/batchservice/persistence/entity/FitCertificationForRead.kt +++ b/src/main/kotlin/com/fitmate/batchservice/persistence/entity/FitCertificationForRead.kt @@ -28,7 +28,7 @@ class FitCertificationForRead private constructor( eventPublisher: String ) { this.fitCertificationId = fitCertificationDetail.fitCertificationId - this.certificationEndDate = fitCertificationDetail.voteEndDate + this.certificationEndDate = fitCertificationDetail.voteEndDateInstant this.certificationStatus = fitCertificationDetail.certificationStatus this.fitGroupId = fitCertificationDetail.fitGroupId this.userId = fitCertificationDetail.userId @@ -46,7 +46,7 @@ class FitCertificationForRead private constructor( fitCertificationDetail.fitCertificationId, fitCertificationDetail.fitGroupId, fitCertificationDetail.userId, - fitCertificationDetail.voteEndDate, + fitCertificationDetail.voteEndDateInstant, fitCertificationDetail.certificationStatus, fitCertificationDetail.state, eventPublisher diff --git a/src/main/kotlin/com/fitmate/batchservice/utils/DateParseUtils.kt b/src/main/kotlin/com/fitmate/batchservice/utils/DateParseUtils.kt new file mode 100644 index 0000000..b0e0a0d --- /dev/null +++ b/src/main/kotlin/com/fitmate/batchservice/utils/DateParseUtils.kt @@ -0,0 +1,49 @@ +package com.fitmate.batchservice.utils + +import com.fitmate.batchservice.exception.NotExpectResultException +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import java.time.DateTimeException +import java.time.Instant +import java.time.OffsetDateTime +import java.time.ZoneId +import java.time.format.DateTimeFormatter + +class DateParseUtils { + + companion object { + val logger: Logger = LoggerFactory.getLogger(DateParseUtils::class.java) + + const val DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss.SSSSSSXXX" + + fun instantToString(instant: Instant?): String { + instant ?: return "" + + val zonedDateTime = instant.atZone(ZoneId.systemDefault()) + + val formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT) + + val formattedDate = zonedDateTime.format(formatter) + + return formattedDate + } + + fun stringToInstant(stringInstantDate: String): Instant { + val formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT) + + var result: Instant? = null + + try { + val offsetDateTime = OffsetDateTime.parse(stringInstantDate, formatter) + + result = offsetDateTime.toInstant() + } catch (e: DateTimeException) { + logger.error("string to instant parse exception ", e) + } + + if (result == null) throw NotExpectResultException("string to instant parse result null") + + return result + } + } +} \ No newline at end of file