Формат времени в UTC
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
package space.nstart.pcp.slots_service.configuration
|
||||
|
||||
import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.core.convert.converter.Converter
|
||||
import org.springframework.format.FormatterRegistry
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||
import space.nstart.pcp.pcp_types_lib.utils.UtcDateTimes
|
||||
import tools.jackson.core.JsonGenerator
|
||||
import tools.jackson.core.JsonParser
|
||||
import tools.jackson.databind.DeserializationContext
|
||||
import tools.jackson.databind.SerializationContext
|
||||
import tools.jackson.databind.deser.std.StdDeserializer
|
||||
import tools.jackson.databind.module.SimpleModule
|
||||
import tools.jackson.databind.ser.std.StdSerializer
|
||||
import java.time.Clock
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Configuration
|
||||
class UtcTimeConfiguration : WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
fun clock(): Clock = Clock.systemUTC()
|
||||
|
||||
@Bean
|
||||
fun slotsUtcLocalDateTimeCustomizer(): JsonMapperBuilderCustomizer = JsonMapperBuilderCustomizer { builder ->
|
||||
builder.addModule(
|
||||
SimpleModule("slots-service-utc-local-date-time")
|
||||
.addSerializer(LocalDateTime::class.java, UtcLocalDateTimeSerializer())
|
||||
.addDeserializer(LocalDateTime::class.java, UtcLocalDateTimeDeserializer())
|
||||
)
|
||||
}
|
||||
|
||||
override fun addFormatters(registry: FormatterRegistry) {
|
||||
registry.addConverter(UtcLocalDateTimeQueryParamConverter())
|
||||
}
|
||||
}
|
||||
|
||||
private class UtcLocalDateTimeQueryParamConverter : Converter<String, LocalDateTime> {
|
||||
override fun convert(source: String): LocalDateTime = UtcDateTimes.parse(source)
|
||||
}
|
||||
|
||||
private class UtcLocalDateTimeSerializer : StdSerializer<LocalDateTime>(LocalDateTime::class.java) {
|
||||
override fun serialize(value: LocalDateTime, gen: JsonGenerator, ctxt: SerializationContext) {
|
||||
gen.writeString(UtcDateTimes.format(value))
|
||||
}
|
||||
}
|
||||
|
||||
private class UtcLocalDateTimeDeserializer : StdDeserializer<LocalDateTime>(LocalDateTime::class.java) {
|
||||
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): LocalDateTime {
|
||||
val value = p.valueAsString ?: throw IllegalArgumentException("Expected ISO-8601 UTC date-time string")
|
||||
return UtcDateTimes.parse(value)
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
package space.nstart.pcp.slots_service.controller
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.format.annotation.DateTimeFormat
|
||||
import org.springframework.web.bind.annotation.DeleteMapping
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
@@ -32,8 +31,8 @@ class BookingController {
|
||||
|
||||
@GetMapping("/search")
|
||||
fun search(
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) timeStart: LocalDateTime?,
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) timeStop: LocalDateTime?,
|
||||
@RequestParam(required = false) timeStart: LocalDateTime?,
|
||||
@RequestParam(required = false) timeStop: LocalDateTime?,
|
||||
@RequestParam(required = false) requestId: String?,
|
||||
@RequestParam(required = false) satelliteIds: List<Long>?
|
||||
) = slotService.searchBookedSlots(
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ import jakarta.persistence.Column
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.Id
|
||||
import jakarta.persistence.Table
|
||||
import space.nstart.pcp.pcp_types_lib.utils.UtcDateTimes
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Entity
|
||||
@@ -13,7 +14,7 @@ class SatelliteIcEntity(
|
||||
@Column(name = "satellite_id", nullable = false)
|
||||
val satelliteId: Long = 0,
|
||||
@Column(name = "orb_time", nullable = false)
|
||||
val orbTime: LocalDateTime = LocalDateTime.now(),
|
||||
val orbTime: LocalDateTime = UtcDateTimes.now(),
|
||||
@Column(name = "orb_revolution", nullable = false)
|
||||
val orbRevolution: Long = 0,
|
||||
@Column(nullable = false)
|
||||
|
||||
+3
-2
@@ -9,6 +9,7 @@ import space.nstart.pcp.pcp_types_lib.dto.requests.slots.SlotDTO
|
||||
import space.nstart.pcp.pcp_types_lib.dto.requests.slots.SlotHolderDTO
|
||||
import space.nstart.pcp.pcp_types_lib.utils.wkt.WKTParser
|
||||
import space.nstart.pcp.slots_service.model.Mar
|
||||
import space.nstart.pcp.pcp_types_lib.utils.UtcDateTimes
|
||||
import java.time.LocalDateTime
|
||||
|
||||
|
||||
@@ -27,9 +28,9 @@ class SlotEntity(
|
||||
@Column(nullable = false)
|
||||
val coveringType : Int = 0,
|
||||
@Column(nullable = false)
|
||||
var tn : LocalDateTime = LocalDateTime.now(),
|
||||
var tn : LocalDateTime = UtcDateTimes.now(),
|
||||
@Column(nullable = false)
|
||||
var tk : LocalDateTime = LocalDateTime.now(),
|
||||
var tk : LocalDateTime = UtcDateTimes.now(),
|
||||
val roll : Double = 0.0,
|
||||
@Column(name = "contour_wkt", columnDefinition = "TEXT", nullable = false)
|
||||
val contour : String = "",
|
||||
|
||||
@@ -2,12 +2,13 @@ package space.nstart.pcp.slots_service.model
|
||||
|
||||
import org.locationtech.jts.geom.Geometry
|
||||
import space.nstart.pcp.pcp_types_lib.dto.ballistics.RevolutionSign
|
||||
import space.nstart.pcp.pcp_types_lib.utils.UtcDateTimes
|
||||
import java.time.LocalDateTime
|
||||
|
||||
class Mar (
|
||||
val sat : Long = 0,
|
||||
val tn : LocalDateTime = LocalDateTime.now(),
|
||||
val tk : LocalDateTime = LocalDateTime.now(),
|
||||
val tn : LocalDateTime = UtcDateTimes.now(),
|
||||
val tk : LocalDateTime = UtcDateTimes.now(),
|
||||
val roll : Double = 0.0,
|
||||
val contour : String = "",
|
||||
var poly : Geometry? = null,
|
||||
|
||||
Reference in New Issue
Block a user