Add jackson datetime module
This commit is contained in:
parent
6688b35a9b
commit
bef1391c90
@ -134,6 +134,11 @@
|
|||||||
<artifactId>ktorm-jackson</artifactId>
|
<artifactId>ktorm-jackson</artifactId>
|
||||||
<version>${ktorm_version}</version>
|
<version>${ktorm_version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
<version>2.10.4</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.hekeki</groupId>
|
<groupId>com.github.hekeki</groupId>
|
||||||
<artifactId>huckleberry</artifactId>
|
<artifactId>huckleberry</artifactId>
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package be.vandewalleh.features
|
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.application.*
|
||||||
import io.ktor.features.*
|
import io.ktor.features.*
|
||||||
import io.ktor.jackson.*
|
import io.ktor.jackson.*
|
||||||
@ -9,6 +12,9 @@ fun Application.contentNegotiationFeature() {
|
|||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
jackson {
|
jackson {
|
||||||
registerModule(KtormModule())
|
registerModule(KtormModule())
|
||||||
|
registerModule(JavaTimeModule())
|
||||||
|
disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT)
|
||||||
|
dateFormat = StdDateFormat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,14 +4,13 @@ import be.vandewalleh.extensions.ioAsync
|
|||||||
import be.vandewalleh.tables.Chapters
|
import be.vandewalleh.tables.Chapters
|
||||||
import be.vandewalleh.tables.Notes
|
import be.vandewalleh.tables.Notes
|
||||||
import be.vandewalleh.tables.Tags
|
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.dsl.*
|
||||||
import me.liuwj.ktorm.entity.*
|
import me.liuwj.ktorm.entity.*
|
||||||
import org.kodein.di.Kodein
|
import org.kodein.di.Kodein
|
||||||
import org.kodein.di.KodeinAware
|
import org.kodein.di.KodeinAware
|
||||||
import org.kodein.di.generic.instance
|
import org.kodein.di.generic.instance
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +42,7 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
|
|||||||
.map { it.name }
|
.map { it.name }
|
||||||
.toList()
|
.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? {
|
suspend fun getNote(userId: Int, noteUuid: UUID): FullNoteDTO? {
|
||||||
val deferredNote = ioAsync {
|
val deferredNote = ioAsync {
|
||||||
db.sequenceOf(Notes, withReferences = false)
|
db.sequenceOf(Notes, withReferences = false)
|
||||||
@ -120,13 +117,12 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
|
|||||||
|
|
||||||
val note = deferredNote.await() ?: return null
|
val note = deferredNote.await() ?: return null
|
||||||
|
|
||||||
val updatedAtFormatted = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(note.updatedAt)
|
|
||||||
val tags = deferredTags.await()
|
val tags = deferredTags.await()
|
||||||
val chapters = deferredChapters.await()
|
val chapters = deferredChapters.await()
|
||||||
return FullNoteDTO(
|
return FullNoteDTO(
|
||||||
uuid = noteUuid,
|
uuid = noteUuid,
|
||||||
title = note.title,
|
title = note.title,
|
||||||
updatedAt = updatedAtFormatted,
|
updatedAt = note.updatedAt,
|
||||||
tags = tags,
|
tags = tags,
|
||||||
chapters = chapters
|
chapters = chapters
|
||||||
)
|
)
|
||||||
@ -182,7 +178,7 @@ data class ChapterDTO(
|
|||||||
data class FullNoteDTO(
|
data class FullNoteDTO(
|
||||||
val uuid: UUID,
|
val uuid: UUID,
|
||||||
val title: String,
|
val title: String,
|
||||||
val updatedAt: String,
|
val updatedAt: LocalDateTime,
|
||||||
val tags: List<String>,
|
val tags: List<String>,
|
||||||
val chapters: List<ChapterDTO>
|
val chapters: List<ChapterDTO>
|
||||||
)
|
)
|
||||||
@ -196,7 +192,7 @@ data class FullNoteCreateDTO(
|
|||||||
data class FullNotePatchDTO(
|
data class FullNotePatchDTO(
|
||||||
val uuid: UUID? = null,
|
val uuid: UUID? = null,
|
||||||
val title: String? = null,
|
val title: String? = null,
|
||||||
val updatedAt: String? = null,
|
val updatedAt: LocalDateTime? = null,
|
||||||
val tags: List<String>? = null,
|
val tags: List<String>? = null,
|
||||||
val chapters: List<ChapterDTO>? = null
|
val chapters: List<ChapterDTO>? = null
|
||||||
)
|
)
|
||||||
@ -205,5 +201,5 @@ data class BasicNoteDTO(
|
|||||||
val uuid: UUID,
|
val uuid: UUID,
|
||||||
val title: String,
|
val title: String,
|
||||||
val tags: List<String>,
|
val tags: List<String>,
|
||||||
val updatedAt: String
|
val updatedAt: LocalDateTime
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user