Performance improvements

This commit is contained in:
2020-06-14 15:31:36 +02:00
parent 8a9e878d5f
commit f40349ea98
9 changed files with 85 additions and 57 deletions
@@ -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()
+8
View File
@@ -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)
}