feature #9: Add security for route "create article"

This commit is contained in:
2019-08-23 00:03:53 +02:00
parent 5542eede27
commit 21b6a525fd
3 changed files with 36 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ package fr.dcproject.repository
import fr.postgresjson.connexion.Requester
import fr.postgresjson.repository.RepositoryI
import io.ktor.auth.UserPasswordCredential
import java.util.*
import fr.dcproject.entity.User as UserEntity
class User(override var requester: Requester) : RepositoryI<UserEntity> {
@@ -16,4 +17,16 @@ class User(override var requester: Requester) : RepositoryI<UserEntity> {
"plain_password" to credentials.password
)
}
fun findById(id: UUID): UserEntity {
return requester
.getFunction("find_user_by_id")
.selectOne(
"id" to id
) ?: throw UserNotFound(id)
}
class UserNotFound(override val message: String?, override val cause: Throwable?): Throwable(message, cause) {
constructor(id: UUID): this("No User with ID $id", null)
}
}