Refactoring of CommentVoter

This commit is contained in:
2021-01-14 23:38:59 +01:00
parent caadc2a969
commit 7c106f7cf8
13 changed files with 169 additions and 192 deletions

View File

@@ -1,8 +1,9 @@
package fr.dcproject.component.comment.generic.routes
import fr.dcproject.citizenOrNull
import fr.dcproject.component.comment.generic.CommentRepository
import fr.dcproject.component.comment.generic.CommentVoter
import fr.ktorVoter.assertCanAll
import fr.dcproject.voter.assert
import io.ktor.application.*
import io.ktor.http.*
import io.ktor.locations.*
@@ -25,7 +26,7 @@ class CommentChildrenRequest(
@KtorExperimentalAPI
@KtorExperimentalLocationsAPI
fun Route.getChildrenComments(repo: CommentRepository) {
fun Route.getChildrenComments(repo: CommentRepository, voter: CommentVoter) {
get<CommentChildrenRequest> {
val comments =
repo.findByParent(
@@ -34,7 +35,7 @@ fun Route.getChildrenComments(repo: CommentRepository) {
it.limit
)
assertCanAll(CommentVoter.Action.VIEW, comments.result)
voter.assert { canView(comments.result, citizenOrNull) }
call.respond(HttpStatusCode.OK, comments)
}