Add jackson datetime module

This commit is contained in:
Hubert Van De Walle 2020-06-15 22:40:16 +02:00
parent 6688b35a9b
commit bef1391c90
3 changed files with 17 additions and 10 deletions

View File

@ -134,6 +134,11 @@
<artifactId>ktorm-jackson</artifactId>
<version>${ktorm_version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.10.4</version>
</dependency>
<dependency>
<groupId>com.github.hekeki</groupId>
<artifactId>huckleberry</artifactId>

View File

@ -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()
}
}
}

View File

@ -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<String>,
val chapters: List<ChapterDTO>
)
@ -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<String>? = null,
val chapters: List<ChapterDTO>? = null
)
@ -205,5 +201,5 @@ data class BasicNoteDTO(
val uuid: UUID,
val title: String,
val tags: List<String>,
val updatedAt: String
val updatedAt: LocalDateTime
)