Merge branch 'feature/all-tags' into feature/create-note
This commit is contained in:
commit
74aeb711f0
@ -9,4 +9,5 @@ fun Routing.registerRoutes(kodein: Kodein) {
|
|||||||
notes(kodein)
|
notes(kodein)
|
||||||
title(kodein)
|
title(kodein)
|
||||||
chapters(kodein)
|
chapters(kodein)
|
||||||
|
tags(kodein)
|
||||||
}
|
}
|
||||||
20
api/src/routing/TagController.kt
Normal file
20
api/src/routing/TagController.kt
Normal 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()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -111,6 +111,12 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
|
|||||||
db.useTransaction {
|
db.useTransaction {
|
||||||
db.delete(Notes) { it.id eq noteId }
|
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)
|
data class ChaptersDTO(val title: String, val content: String)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user