Skip to content

Commit

Permalink
Merge pull request #15 from Workout-Study/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
12OneTwo12 authored Aug 13, 2024
2 parents ca2c595 + c725ff3 commit 41d3ba4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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
)
private val createdAtInstant: Instant
) {
val createdAt: String = DateParseUtils.instantToString(createdAtInstant)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.fitmate.batchservice.dto.penalty

import com.fitmate.batchservice.utils.DateParseUtils
import java.time.Instant

data class FitPenaltyDetailResponse(
val fitPenaltyId: Long,
val fitGroupId: Long,
val userId: Int,
val amount: Int,
val createdAt: Instant
)
private val createdAtInstant: Instant
) {
val createdAt: String = DateParseUtils.instantToString(createdAtInstant)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,7 +46,7 @@ class FitCertificationForRead private constructor(
fitCertificationDetail.fitCertificationId,
fitCertificationDetail.fitGroupId,
fitCertificationDetail.userId,
fitCertificationDetail.voteEndDate,
fitCertificationDetail.voteEndDateInstant,
fitCertificationDetail.certificationStatus,
fitCertificationDetail.state,
eventPublisher
Expand Down
49 changes: 49 additions & 0 deletions src/main/kotlin/com/fitmate/batchservice/utils/DateParseUtils.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 41d3ba4

Please sign in to comment.