Merge branch 'feature/all-tags' into feature/create-note

This commit is contained in:
Hubert Van De Walle 2020-04-23 00:23:45 +02:00
commit 74aeb711f0
3 changed files with 27 additions and 0 deletions

View File

@ -9,4 +9,5 @@ fun Routing.registerRoutes(kodein: Kodein) {
notes(kodein)
title(kodein)
chapters(kodein)
tags(kodein)
}

View File

@ -0,0 +1,20 @@
package be.vandewalleh.routing
import be.vandewalleh.extensions.userId
import be.vandewalleh.services.NotesService
import io.ktor.application.*
import io.ktor.auth.*
import io.ktor.response.*
import io.ktor.routing.*
import org.kodein.di.Kodein
import org.kodein.di.generic.instance
fun Routing.tags(kodein: Kodein) {
val notesService by kodein.instance<NotesService>()
authenticate {
get("/tags") {
call.respond(notesService.getTags(call.userId()))
}
}
}

View File

@ -111,6 +111,12 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
db.useTransaction {
db.delete(Notes) { it.id eq noteId }
}
fun getTags(userId: Int): List<String> = db.from(Tags)
.leftJoin(Notes, on = Tags.noteId eq Notes.id)
.select(Tags.name)
.where { Notes.userId eq userId }
.map { it[Tags.name]!! }
}
data class ChaptersDTO(val title: String, val content: String)