Start migration of notesServices + controllers

This commit is contained in:
2020-04-25 17:24:43 +02:00
parent 573963b161
commit 52aae6773f
8 changed files with 130 additions and 106 deletions
@@ -1,6 +1,7 @@
package be.vandewalleh.extensions
import be.vandewalleh.kodein
import be.vandewalleh.services.FullNoteDTOPatch
import be.vandewalleh.services.UserService
import io.ktor.application.*
import io.ktor.auth.*
@@ -23,12 +24,8 @@ fun ApplicationCall.userId(): Int {
return userService.getUserId(email)!!
}
private class Tags(val tags: List<String>)
class NoteCreate(val title: String, val tags: List<String>)
suspend fun ApplicationCall.receiveTags(): List<String> {
return receive<Tags>().tags
}
suspend fun ApplicationCall.receiveNoteCreate(): NoteCreate = receive()
data class NotePatch(val tags: List<String>?, val title: String?)
suspend fun ApplicationCall.receiveNotePatch() = receive<NotePatch>()
suspend fun ApplicationCall.receiveNotePatch() : FullNoteDTOPatch = receive()
+3 -13
View File
@@ -1,22 +1,12 @@
package be.vandewalleh.extensions
import be.vandewalleh.kodein
import be.vandewalleh.services.NotesService
import be.vandewalleh.tables.Notes
import io.ktor.http.*
import org.kodein.di.generic.instance
private val notesService by kodein.instance<NotesService>()
import java.util.*
fun Parameters.noteTitle(): String {
return this["noteTitle"]!!
}
/**
* Method that returns a [Notes] ID from it's title and the currently logged in user.
* returns null if none found
*/
fun Parameters.noteId(userId: Int): Int? {
val title = noteTitle()
return notesService.getNoteIdFromUserIdAndTitle(userId, title)
fun Parameters.noteUuid(): UUID {
return UUID.fromString(this["noteUuid"])
}