Performance improvements
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package be.vandewalleh.extensions
|
||||
|
||||
import be.vandewalleh.auth.UserDbIdPrincipal
|
||||
import be.vandewalleh.kodein
|
||||
import be.vandewalleh.services.FullNoteCreateDTO
|
||||
import be.vandewalleh.services.FullNotePatchDTO
|
||||
@@ -11,24 +12,17 @@ import io.ktor.request.*
|
||||
import io.ktor.response.*
|
||||
import org.kodein.di.generic.instance
|
||||
|
||||
val userService by kodein.instance<UserService>()
|
||||
|
||||
suspend fun ApplicationCall.respondStatus(status: HttpStatusCode) {
|
||||
respond(status, status.description)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the user email for the currently authenticated user
|
||||
*/
|
||||
fun ApplicationCall.userEmail() = principal<UserIdPrincipal>()!!.name
|
||||
|
||||
/**
|
||||
* @return the userId for the currently authenticated user
|
||||
*/
|
||||
fun ApplicationCall.userId() = userService.getUserId(userEmail())!!
|
||||
fun ApplicationCall.userId() = principal<UserDbIdPrincipal>()!!.id
|
||||
|
||||
class NoteCreate(val title: String, val tags: List<String>)
|
||||
|
||||
suspend fun ApplicationCall.receiveNoteCreate(): FullNoteCreateDTO = receive()
|
||||
|
||||
suspend fun ApplicationCall.receiveNotePatch(): FullNotePatchDTO = receive()
|
||||
suspend fun ApplicationCall.receiveNotePatch(): FullNotePatchDTO = receive()
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package be.vandewalleh.extensions
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
|
||||
fun <T> ioAsync(block: suspend CoroutineScope.() -> T): Deferred<T> {
|
||||
return CoroutineScope(Dispatchers.IO).async(block = block)
|
||||
}
|
||||
Reference in New Issue
Block a user