From bef1391c90e704e95d71655bd7a7292648b4458c Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Mon, 15 Jun 2020 22:40:16 +0200 Subject: [PATCH] Add jackson datetime module --- api/pom.xml | 5 +++++ api/src/features/ContentNegotiationFeature.kt | 6 ++++++ api/src/services/NotesService.kt | 16 ++++++---------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 3df2ab1..c4cb038 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -134,6 +134,11 @@ ktorm-jackson ${ktorm_version} + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.10.4 + com.github.hekeki huckleberry diff --git a/api/src/features/ContentNegotiationFeature.kt b/api/src/features/ContentNegotiationFeature.kt index fe892c5..85fcbcb 100644 --- a/api/src/features/ContentNegotiationFeature.kt +++ b/api/src/features/ContentNegotiationFeature.kt @@ -1,5 +1,8 @@ package be.vandewalleh.features +import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.util.StdDateFormat +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import io.ktor.application.* import io.ktor.features.* import io.ktor.jackson.* @@ -9,6 +12,9 @@ fun Application.contentNegotiationFeature() { install(ContentNegotiation) { jackson { registerModule(KtormModule()) + registerModule(JavaTimeModule()) + disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT) + dateFormat = StdDateFormat() } } } diff --git a/api/src/services/NotesService.kt b/api/src/services/NotesService.kt index 113c3c8..cd87a59 100644 --- a/api/src/services/NotesService.kt +++ b/api/src/services/NotesService.kt @@ -4,14 +4,13 @@ import be.vandewalleh.extensions.ioAsync import be.vandewalleh.tables.Chapters import be.vandewalleh.tables.Notes import be.vandewalleh.tables.Tags -import me.liuwj.ktorm.database.Database +import me.liuwj.ktorm.database.* import me.liuwj.ktorm.dsl.* import me.liuwj.ktorm.entity.* import org.kodein.di.Kodein import org.kodein.di.KodeinAware import org.kodein.di.generic.instance import java.time.LocalDateTime -import java.time.format.DateTimeFormatter import java.util.* /** @@ -43,7 +42,7 @@ class NotesService(override val kodein: Kodein) : KodeinAware { .map { it.name } .toList() - BasicNoteDTO(note.uuid, note.title, noteTags, DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(note.updatedAt)) + BasicNoteDTO(note.uuid, note.title, noteTags, note.updatedAt) } } @@ -91,8 +90,6 @@ class NotesService(override val kodein: Kodein) : KodeinAware { } - - suspend fun getNote(userId: Int, noteUuid: UUID): FullNoteDTO? { val deferredNote = ioAsync { db.sequenceOf(Notes, withReferences = false) @@ -120,13 +117,12 @@ class NotesService(override val kodein: Kodein) : KodeinAware { val note = deferredNote.await() ?: return null - val updatedAtFormatted = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(note.updatedAt) val tags = deferredTags.await() val chapters = deferredChapters.await() return FullNoteDTO( uuid = noteUuid, title = note.title, - updatedAt = updatedAtFormatted, + updatedAt = note.updatedAt, tags = tags, chapters = chapters ) @@ -182,7 +178,7 @@ data class ChapterDTO( data class FullNoteDTO( val uuid: UUID, val title: String, - val updatedAt: String, + val updatedAt: LocalDateTime, val tags: List, val chapters: List ) @@ -196,7 +192,7 @@ data class FullNoteCreateDTO( data class FullNotePatchDTO( val uuid: UUID? = null, val title: String? = null, - val updatedAt: String? = null, + val updatedAt: LocalDateTime? = null, val tags: List? = null, val chapters: List? = null ) @@ -205,5 +201,5 @@ data class BasicNoteDTO( val uuid: UUID, val title: String, val tags: List, - val updatedAt: String + val updatedAt: LocalDateTime )