Big refactoring #77
@@ -13,6 +13,12 @@ class ArticleRepository(override var requester: Requester) : RepositoryI {
|
|||||||
return function.selectOne("id" to id)
|
return function.selectOne("id" to id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findVersionsById(page: Int = 1, limit: Int = 50, id: UUID): Paginated<ArticleForView> {
|
||||||
|
return requester
|
||||||
|
.getFunction("find_articles_versions_by_id")
|
||||||
|
.select(page, limit, "id" to id)
|
||||||
|
}
|
||||||
|
|
||||||
fun findVersionsByVersionId(page: Int = 1, limit: Int = 50, versionId: UUID): Paginated<ArticleForView> {
|
fun findVersionsByVersionId(page: Int = 1, limit: Int = 50, versionId: UUID): Paginated<ArticleForView> {
|
||||||
return requester
|
return requester
|
||||||
.getFunction("find_articles_versions_by_version_id")
|
.getFunction("find_articles_versions_by_version_id")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package fr.dcproject.component.article.routes
|
package fr.dcproject.component.article.routes
|
||||||
|
|
||||||
import fr.dcproject.component.article.ArticleAccessControl
|
import fr.dcproject.component.article.ArticleAccessControl
|
||||||
import fr.dcproject.component.article.ArticleForView
|
import fr.dcproject.component.article.ArticleRef
|
||||||
import fr.dcproject.component.article.ArticleRepository
|
import fr.dcproject.component.article.ArticleRepository
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.security.assert
|
import fr.dcproject.security.assert
|
||||||
@@ -12,12 +12,13 @@ import io.ktor.locations.Location
|
|||||||
import io.ktor.locations.get
|
import io.ktor.locations.get
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
object FindArticleVersions {
|
object FindArticleVersions {
|
||||||
@Location("/articles/{article}/versions")
|
@Location("/articles/{article}/versions")
|
||||||
class ArticleVersionsRequest(
|
class ArticleVersionsRequest(
|
||||||
val article: ArticleForView,
|
article: UUID,
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
limit: Int = 50,
|
limit: Int = 50,
|
||||||
val sort: String? = null,
|
val sort: String? = null,
|
||||||
@@ -26,15 +27,16 @@ object FindArticleVersions {
|
|||||||
) {
|
) {
|
||||||
val page: Int = if (page < 1) 1 else page
|
val page: Int = if (page < 1) 1 else page
|
||||||
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
|
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
|
||||||
|
val article = ArticleRef(article)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ArticleRepository.findVersions(request: ArticleVersionsRequest) =
|
private fun ArticleRepository.findVersions(request: ArticleVersionsRequest) =
|
||||||
findVersionsByVersionId(request.page, request.limit, request.article.versionId)
|
findVersionsById(request.page, request.limit, request.article.id)
|
||||||
|
|
||||||
fun Route.findArticleVersions(repo: ArticleRepository, ac: ArticleAccessControl) {
|
fun Route.findArticleVersions(repo: ArticleRepository, ac: ArticleAccessControl) {
|
||||||
get<ArticleVersionsRequest> {
|
get<ArticleVersionsRequest> {
|
||||||
repo.findVersions(it)
|
repo.findVersions(it)
|
||||||
.apply { ac.assert { canView(it.article, citizenOrNull) } }
|
.apply { ac.assert { canView(result, citizenOrNull) } }
|
||||||
.let { call.respond(it) }
|
.let { call.respond(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user