WIP
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package be.vandewalleh.extensions
|
||||
|
||||
import be.vandewalleh.kodein
|
||||
import be.vandewalleh.services.UserService
|
||||
import io.ktor.application.ApplicationCall
|
||||
import io.ktor.auth.UserIdPrincipal
|
||||
import io.ktor.auth.principal
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.request.receive
|
||||
import io.ktor.response.respond
|
||||
import org.kodein.di.generic.instance
|
||||
|
||||
val userService by kodein.instance<UserService>()
|
||||
|
||||
suspend fun ApplicationCall.respondStatus(status: HttpStatusCode) {
|
||||
respond(status, status.description)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userId for the currently authenticated user
|
||||
*/
|
||||
fun ApplicationCall.userId(): Int {
|
||||
val email = principal<UserIdPrincipal>()!!.name
|
||||
return userService.getUserId(email)!!
|
||||
}
|
||||
|
||||
private class Tags(val tags: List<String>)
|
||||
|
||||
suspend fun ApplicationCall.receiveTags(): List<String> {
|
||||
return receive<Tags>().tags
|
||||
}
|
||||
|
||||
data class NotePatch(val tags: List<String>?, val title: String?)
|
||||
|
||||
suspend fun ApplicationCall.receiveNotePatch() = receive<NotePatch>()
|
||||
@@ -0,0 +1,22 @@
|
||||
package be.vandewalleh.extensions
|
||||
|
||||
import be.vandewalleh.kodein
|
||||
import be.vandewalleh.services.NotesService
|
||||
import be.vandewalleh.tables.Notes
|
||||
import io.ktor.http.Parameters
|
||||
import org.kodein.di.generic.instance
|
||||
|
||||
val notesService by kodein.instance<NotesService>()
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user