Refactors Articles and Voter
- Move files into components (article) - Split articles routes - Refactoring for remove ktor-voter (ArticleVoter) - Remove mutability - Move DataConversion to separate file (Converter.kt) - Add Schemas for Articles routes - Fix SQL Query for Workgroup roles - rename container_name in docker-compose
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package fr.dcproject.routes
|
||||
|
||||
import fr.dcproject.citizen
|
||||
import fr.dcproject.entity.ArticleRef
|
||||
import fr.dcproject.component.article.ArticleRef
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.security.voter.FollowVoter.Action.CREATE
|
||||
import fr.dcproject.security.voter.FollowVoter.Action.DELETE
|
||||
import fr.dcproject.security.voter.FollowVoter.Action.VIEW
|
||||
import fr.dcproject.entity.FollowForUpdate
|
||||
import fr.dcproject.security.voter.FollowVoter.Action.*
|
||||
import fr.ktorVoter.assertCan
|
||||
import fr.ktorVoter.assertCanAll
|
||||
import io.ktor.application.*
|
||||
@@ -13,7 +12,6 @@ import io.ktor.http.*
|
||||
import io.ktor.locations.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
import fr.dcproject.entity.Follow as FollowEntity
|
||||
import fr.dcproject.repository.FollowArticle as FollowArticleRepository
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
@@ -28,14 +26,14 @@ object FollowArticlePaths {
|
||||
@KtorExperimentalLocationsAPI
|
||||
fun Route.followArticle(repo: FollowArticleRepository) {
|
||||
post<FollowArticlePaths.ArticleFollowRequest> {
|
||||
val follow = FollowEntity(target = it.article, createdBy = this.citizen)
|
||||
val follow = FollowForUpdate(target = it.article, createdBy = this.citizen)
|
||||
assertCan(CREATE, follow)
|
||||
repo.follow(follow)
|
||||
call.respond(HttpStatusCode.Created)
|
||||
}
|
||||
|
||||
delete<FollowArticlePaths.ArticleFollowRequest> {
|
||||
val follow = FollowEntity(target = it.article, createdBy = this.citizen)
|
||||
val follow = FollowForUpdate(target = it.article, createdBy = this.citizen)
|
||||
assertCan(DELETE, follow)
|
||||
repo.unfollow(follow)
|
||||
call.respond(HttpStatusCode.NoContent)
|
||||
|
||||
Reference in New Issue
Block a user