Implement note creation + update tests
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user