Skip to content

Commit

Permalink
refacto: Expose dates as Instant in dto instead of OffsetDatetime
Browse files Browse the repository at this point in the history
  • Loading branch information
asolovieff committed Feb 20, 2024
1 parent 0cc208d commit bda42aa
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
12 changes: 6 additions & 6 deletions modules/app-server/rest/src/main/kotlin/rest/Serializers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.time.OffsetDateTime
import java.time.Instant
import java.util.*

object UUIDSerializer : KSerializer<UUID> {
Expand All @@ -20,14 +20,14 @@ object UUIDSerializer : KSerializer<UUID> {
}
}

object OffsetDateTimeSerializer : KSerializer<OffsetDateTime> {
override val descriptor = PrimitiveSerialDescriptor("OffsetDateTime", PrimitiveKind.STRING)
object InstantSerializer : KSerializer<Instant> {
override val descriptor = PrimitiveSerialDescriptor("Instant", PrimitiveKind.STRING)

override fun deserialize(decoder: Decoder): OffsetDateTime {
return OffsetDateTime.parse(decoder.decodeString())
override fun deserialize(decoder: Decoder): Instant {
return Instant.parse(decoder.decodeString())
}

override fun serialize(encoder: Encoder, value: OffsetDateTime) {
override fun serialize(encoder: Encoder, value: Instant) {
encoder.encodeString(value.toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package rest.v1.route.execution.batch.dto

import execution.batch.BatchExecution
import kotlinx.serialization.Serializable
import rest.OffsetDateTimeSerializer
import rest.InstantSerializer
import rest.UUIDSerializer
import rest.v1.route.execution.dto.StatusDtoV1
import rest.v1.route.execution.dto.toDtoV1
import java.time.OffsetDateTime
import java.time.Instant
import java.util.*

@Serializable
data class BatchExecutionDtoV1(
@Serializable(with = UUIDSerializer::class)
val id: UUID,
@Serializable(with = OffsetDateTimeSerializer::class)
val startDate: OffsetDateTime?,
@Serializable(with = OffsetDateTimeSerializer::class)
val endDate: OffsetDateTime?,
@Serializable(with = InstantSerializer::class)
val startDate: Instant?,
@Serializable(with = InstantSerializer::class)
val endDate: Instant?,
val durationInMs: Int?,
val origin: OriginDtoV1,
val status: StatusDtoV1,
Expand All @@ -25,8 +25,8 @@ data class BatchExecutionDtoV1(

fun BatchExecution.toDtoV1() = BatchExecutionDtoV1(
id = this.id,
startDate = this.startDate,
endDate = this.endDate,
startDate = this.startDate?.toInstant(),
endDate = this.endDate?.toInstant(),
durationInMs = this.durationInMs,
origin = this.origin.toDtoV1(),
status = this.status.toDtoV1(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package rest.v1.route.execution.batch.dto

import execution.batch.BatchExecutionListItem
import kotlinx.serialization.Serializable
import rest.OffsetDateTimeSerializer
import rest.InstantSerializer
import rest.UUIDSerializer
import rest.v1.route.environment.EnvironmentDtoV1
import rest.v1.route.environment.toDtoV1
Expand All @@ -12,17 +12,17 @@ import rest.v1.route.module.dto.ModuleDtoV1
import rest.v1.route.module.dto.toDtoV1
import rest.v1.route.project.dto.ProjectDtoV1
import rest.v1.route.project.dto.toDtoV1
import java.time.OffsetDateTime
import java.time.Instant
import java.util.*

@Serializable
data class BatchExecutionListItemDtoV1(
@Serializable(with = UUIDSerializer::class)
val id: UUID,
@Serializable(with = OffsetDateTimeSerializer::class)
val startDate: OffsetDateTime?,
@Serializable(with = OffsetDateTimeSerializer::class)
val endDate: OffsetDateTime?,
@Serializable(with = InstantSerializer::class)
val startDate: Instant?,
@Serializable(with = InstantSerializer::class)
val endDate: Instant?,
val durationInMs: Int?,
val origin: OriginDtoV1,
val status: StatusDtoV1,
Expand All @@ -34,8 +34,8 @@ data class BatchExecutionListItemDtoV1(

fun BatchExecutionListItem.toDtoV1() = BatchExecutionListItemDtoV1(
id = this.id,
startDate = this.startDate,
endDate = this.endDate,
startDate = this.startDate?.toInstant(),
endDate = this.endDate?.toInstant(),
durationInMs = this.durationInMs,
origin = this.origin.toDtoV1(),
status = this.status.toDtoV1(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package rest.v1.route.execution.script.dto

import kotlinx.serialization.Serializable
import rest.OffsetDateTimeSerializer
import rest.UUIDSerializer
import rest.v1.route.execution.dto.StatusDtoV1
import rest.v1.route.execution.dto.toDtoV1
import rest.v1.route.script.dto.ScriptDtoV1
import rest.v1.route.script.dto.toDtoV1
import execution.script.ScriptExecutionDetail
import java.time.OffsetDateTime
import rest.InstantSerializer
import java.time.Instant
import java.util.UUID

@Serializable
data class ScriptExecutionDetailDtoV1(
@Serializable(with = UUIDSerializer::class)
val id: UUID,
@Serializable(with = OffsetDateTimeSerializer::class)
val startDate: OffsetDateTime? = null,
@Serializable(with = OffsetDateTimeSerializer::class)
val endDate: OffsetDateTime? = null,
@Serializable(with = InstantSerializer::class)
val startDate: Instant? = null,
@Serializable(with = InstantSerializer::class)
val endDate: Instant? = null,
val durationInMs: Int? = null,
val executionOrderIndex: Int,
val output: String? = null,
Expand All @@ -28,8 +28,8 @@ data class ScriptExecutionDetailDtoV1(

fun ScriptExecutionDetail.toDtoV1() = ScriptExecutionDetailDtoV1(
id = this.id,
startDate = this.startDate,
endDate = this.endDate,
startDate = this.startDate?.toInstant(),
endDate = this.endDate?.toInstant(),
durationInMs = this.durationInMs,
executionOrderIndex = this.executionOrderIndex,
output = this.output,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package rest.v1.route.execution.script.dto

import kotlinx.serialization.Serializable
import rest.OffsetDateTimeSerializer
import rest.UUIDSerializer
import rest.v1.route.execution.dto.StatusDtoV1
import rest.v1.route.execution.dto.toDtoV1
import execution.script.ScriptExecution
import java.time.OffsetDateTime
import rest.InstantSerializer
import java.time.Instant
import java.util.UUID

@Serializable
data class ScriptExecutionDtoV1(
@Serializable(with = UUIDSerializer::class)
val id: UUID,
@Serializable(with = OffsetDateTimeSerializer::class)
val startDate: OffsetDateTime? = null,
@Serializable(with = OffsetDateTimeSerializer::class)
val endDate: OffsetDateTime? = null,
@Serializable(with = InstantSerializer::class)
val startDate: Instant? = null,
@Serializable(with = InstantSerializer::class)
val endDate: Instant? = null,
val durationInMs: Int? = null,
val executionOrderIndex: Int,
val output: String? = null,
Expand All @@ -25,8 +25,8 @@ data class ScriptExecutionDtoV1(

fun ScriptExecution.toDtoV1() = ScriptExecutionDtoV1(
id = this.id,
startDate = this.startDate,
endDate = this.endDate,
startDate = this.startDate?.toInstant(),
endDate = this.endDate?.toInstant(),
durationInMs = this.durationInMs,
executionOrderIndex = this.executionOrderIndex,
output = this.output,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package rest.v1.route.execution.script.dto

import kotlinx.serialization.Serializable
import rest.OffsetDateTimeSerializer
import rest.UUIDSerializer
import rest.v1.route.execution.dto.StatusDtoV1
import rest.v1.route.execution.dto.toDtoV1
import rest.v1.route.script.dto.ScriptListItemDtoV1
import rest.v1.route.script.dto.toDtoV1
import execution.script.ScriptExecutionListItem
import java.time.OffsetDateTime
import rest.InstantSerializer
import java.time.Instant
import java.util.UUID

@Serializable
data class ScriptExecutionListItemDtoV1(
@Serializable(with = UUIDSerializer::class)
val id: UUID,
@Serializable(with = OffsetDateTimeSerializer::class)
val startDate: OffsetDateTime? = null,
@Serializable(with = OffsetDateTimeSerializer::class)
val endDate: OffsetDateTime? = null,
@Serializable(with = InstantSerializer::class)
val startDate: Instant? = null,
@Serializable(with = InstantSerializer::class)
val endDate: Instant? = null,
val durationInMs: Int? = null,
val executionOrderIndex: Int,
val status: StatusDtoV1? = null,
Expand All @@ -27,8 +27,8 @@ data class ScriptExecutionListItemDtoV1(

fun ScriptExecutionListItem.toDtoV1() = ScriptExecutionListItemDtoV1(
id = this.id,
startDate = this.startDate,
endDate = this.endDate,
startDate = this.startDate?.toInstant(),
endDate = this.endDate?.toInstant(),
durationInMs = this.durationInMs,
executionOrderIndex = this.executionOrderIndex,
status = this.status?.toDtoV1(),
Expand Down

0 comments on commit bda42aa

Please sign in to comment.