Implement note creation + update tests

This commit is contained in:
2020-04-21 16:19:01 +02:00
parent ecf292bccf
commit 3ab0e395b3
2 changed files with 25 additions and 3 deletions
+16 -1
View File
@@ -8,6 +8,7 @@ import me.liuwj.ktorm.dsl.*
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
/**
@@ -47,7 +48,20 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
.firstOrNull()
fun createNote(userId: Int, title: String, tags: List<String>) {
TODO()
db.useTransaction {
val noteId = db.insertAndGenerateKey(Notes) {
it.title to title
it.userId to userId
it.updatedAt to LocalDateTime.now()
}
tags.forEach { tagName ->
db.insert(Tags) {
it.name to tagName
it.noteId to noteId
}
}
}
}
fun getTagsAndChapters(noteId: Int): TagsChaptersDTO {
@@ -72,6 +86,7 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
if (title != null) {
db.update(Notes) {
it.title to title
it.updatedAt to LocalDateTime.now()
where { it.id eq noteId }
}
}