Improve Follow repository to split IN/OUT type
This commit is contained in:
@@ -142,6 +142,14 @@ fun Application.module(env: Env = PROD) {
|
||||
}
|
||||
}
|
||||
|
||||
convert<CitizenRef> {
|
||||
decode { values, _ ->
|
||||
values.singleOrNull()?.let {
|
||||
CitizenRef(UUID.fromString(it))
|
||||
} ?: throw NotFoundException("Citizen $values not found")
|
||||
}
|
||||
}
|
||||
|
||||
convert<OpinionChoice> {
|
||||
decode { values, _ ->
|
||||
val id = values.singleOrNull()?.let { UUID.fromString(it) }
|
||||
|
||||
@@ -12,19 +12,19 @@ import fr.dcproject.entity.Article as ArticleEntity
|
||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||
import fr.dcproject.entity.Follow as FollowEntity
|
||||
|
||||
open class Follow<T : TargetRef>(override var requester: Requester) : RepositoryI {
|
||||
open class Follow<IN : TargetRef, OUT : TargetRef>(override var requester: Requester) : RepositoryI {
|
||||
open fun findByCitizen(
|
||||
citizen: CitizenI,
|
||||
page: Int = 1,
|
||||
limit: Int = 50
|
||||
): Paginated<FollowEntity<T>> =
|
||||
): Paginated<FollowEntity<OUT>> =
|
||||
findByCitizen(citizen.id, page, limit)
|
||||
|
||||
open fun findByCitizen(
|
||||
citizenId: UUID,
|
||||
page: Int = 1,
|
||||
limit: Int = 50
|
||||
): Paginated<FollowEntity<T>> {
|
||||
): Paginated<FollowEntity<OUT>> {
|
||||
return requester
|
||||
.getFunction("find_follows_by_citizen")
|
||||
.select(
|
||||
@@ -33,7 +33,7 @@ open class Follow<T : TargetRef>(override var requester: Requester) : Repository
|
||||
)
|
||||
}
|
||||
|
||||
fun follow(follow: FollowEntity<T>) {
|
||||
fun follow(follow: FollowEntity<IN>) {
|
||||
requester
|
||||
.getFunction("follow")
|
||||
.sendQuery(
|
||||
@@ -43,7 +43,7 @@ open class Follow<T : TargetRef>(override var requester: Requester) : Repository
|
||||
)
|
||||
}
|
||||
|
||||
fun unfollow(follow: FollowEntity<T>) {
|
||||
fun unfollow(follow: FollowEntity<IN>) {
|
||||
requester
|
||||
.getFunction("unfollow")
|
||||
.sendQuery(
|
||||
@@ -56,7 +56,7 @@ open class Follow<T : TargetRef>(override var requester: Requester) : Repository
|
||||
open fun findFollow(
|
||||
citizen: CitizenI,
|
||||
target: UuidEntity
|
||||
): FollowEntity<T>? =
|
||||
): FollowEntity<OUT>? =
|
||||
requester
|
||||
.getFunction("find_follow")
|
||||
.selectOne(
|
||||
@@ -65,7 +65,7 @@ open class Follow<T : TargetRef>(override var requester: Requester) : Repository
|
||||
)
|
||||
}
|
||||
|
||||
class FollowArticle(requester: Requester) : Follow<ArticleEntity>(requester) {
|
||||
class FollowArticle(requester: Requester) : Follow<ArticleRef, ArticleEntity>(requester) {
|
||||
override fun findByCitizen(
|
||||
citizenId: UUID,
|
||||
page: Int,
|
||||
@@ -107,7 +107,7 @@ class FollowArticle(requester: Requester) : Follow<ArticleEntity>(requester) {
|
||||
}
|
||||
}
|
||||
|
||||
class FollowConstitution(requester: Requester) : Follow<ConstitutionEntity>(requester) {
|
||||
class FollowConstitution(requester: Requester) : Follow<ConstitutionRef, ConstitutionEntity>(requester) {
|
||||
override fun findByCitizen(
|
||||
citizenId: UUID,
|
||||
page: Int,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fr.dcproject.routes
|
||||
|
||||
import fr.dcproject.citizen
|
||||
import fr.dcproject.entity.ArticleRef
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.security.voter.FollowVoter.Action.*
|
||||
import fr.dcproject.security.voter.assertCan
|
||||
@@ -9,14 +10,13 @@ import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.locations.*
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.Route
|
||||
import fr.dcproject.entity.Article as ArticleEntity
|
||||
import fr.dcproject.entity.Follow as FollowEntity
|
||||
import fr.dcproject.repository.FollowArticle as FollowArticleRepository
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
object FollowArticlePaths {
|
||||
@Location("/articles/{article}/follows")
|
||||
class ArticleFollowRequest(val article: ArticleEntity)
|
||||
class ArticleFollowRequest(val article: ArticleRef)
|
||||
|
||||
@Location("/citizens/{citizen}/follows/articles")
|
||||
class CitizenFollowArticleRequest(val citizen: Citizen)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package fr.dcproject.routes
|
||||
|
||||
import fr.dcproject.citizen
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.entity.CitizenRef
|
||||
import fr.dcproject.entity.ConstitutionRef
|
||||
import fr.dcproject.security.voter.FollowVoter.Action.*
|
||||
import fr.dcproject.security.voter.assertCan
|
||||
import io.ktor.application.call
|
||||
@@ -9,17 +10,16 @@ import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.locations.*
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.Route
|
||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||
import fr.dcproject.entity.Follow as FollowEntity
|
||||
import fr.dcproject.repository.FollowConstitution as FollowConstitutionRepository
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
object FollowConstitutionPaths {
|
||||
@Location("/constitutions/{constitution}/follow")
|
||||
class ConstitutionFollowRequest(val constitution: ConstitutionEntity)
|
||||
class ConstitutionFollowRequest(val constitution: ConstitutionRef)
|
||||
|
||||
@Location("/citizens/{citizen}/follows/constitutions")
|
||||
class CitizenFollowConstitutionRequest(val citizen: Citizen)
|
||||
class CitizenFollowConstitutionRequest(val citizen: CitizenRef)
|
||||
}
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.dcproject.routes
|
||||
|
||||
import fr.dcproject.citizen
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.entity.CitizenRef
|
||||
import fr.dcproject.entity.OpinionArticle
|
||||
import fr.dcproject.entity.OpinionChoiceRef
|
||||
import fr.dcproject.entity.request.RequestBuilder
|
||||
@@ -36,7 +37,7 @@ object OpinionArticlePaths {
|
||||
*/
|
||||
@Location("/citizens/{citizen}/opinions/articles")
|
||||
class CitizenOpinionArticleRequest(
|
||||
val citizen: CitizenEntity,
|
||||
val citizen: CitizenRef,
|
||||
page: Int = 1,
|
||||
limit: Int = 50
|
||||
) : PaginatedRequestI by PaginatedRequest(page, limit)
|
||||
|
||||
Reference in New Issue
Block a user