Migration done for the backend

This commit is contained in:
2020-04-25 18:17:34 +02:00
parent 52aae6773f
commit 69ede50a59
6 changed files with 65 additions and 37 deletions
+2 -11
View File
@@ -1,8 +1,6 @@
package be.vandewalleh.routing
import be.vandewalleh.extensions.noteTitle
import be.vandewalleh.extensions.receiveNoteCreate
import be.vandewalleh.extensions.respondStatus
import be.vandewalleh.extensions.userId
import be.vandewalleh.services.NotesService
import io.ktor.application.*
@@ -25,16 +23,9 @@ fun Routing.notes(kodein: Kodein) {
post("/notes") {
val userId = call.userId()
val noteUuid = call.parameters.noteTitle()
val note = call.receiveNoteCreate()
val exists = notesService.noteExistsWithTitle(userId, note.title)
if (exists) {
return@post call.respondStatus(HttpStatusCode.Conflict)
}
notesService.createNote(userId, note.title, note.tags)
call.respondStatus(HttpStatusCode.Created)
val uuid = notesService.createNote(userId, note)
call.respond(HttpStatusCode.Created, mapOf("uuid" to uuid))
}
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ fun Routing.title(kodein: Kodein) {
val noteUuid = call.parameters.noteUuid()
val exists = notesService.noteExists(userId, noteUuid)
if (exists) return@get call.respondStatus(HttpStatusCode.NotFound)
if (!exists) return@get call.respondStatus(HttpStatusCode.NotFound)
val response = notesService.getNote(noteUuid)
call.respond(response)