feature #14: Add routes for get follows of one citizen
This commit is contained in:
@@ -1,16 +1,37 @@
|
||||
package fr.dcproject.repository
|
||||
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import fr.postgresjson.connexion.Requester
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.repository.RepositoryI
|
||||
import java.util.*
|
||||
import kotlin.reflect.KClass
|
||||
import fr.dcproject.entity.Article as ArticleEntity
|
||||
import fr.dcproject.entity.Citizen as CitizenEntity
|
||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||
import fr.dcproject.entity.Follow as FollowEntity
|
||||
|
||||
open class Follow <T: EntityI<UUID>>(override var requester: Requester): RepositoryI<FollowEntity<T>> {
|
||||
open class Follow <T: UuidEntity>(override var requester: Requester): RepositoryI<FollowEntity<T>> {
|
||||
override val entityName = FollowEntity::class as KClass<FollowEntity<T>>
|
||||
open fun findByCitizenId(
|
||||
citizen: CitizenEntity,
|
||||
page: Int = 1,
|
||||
limit: Int = 50
|
||||
): Paginated<FollowEntity<T>> =
|
||||
findByCitizenId(citizen.id ?: error("The citizen must have an id"), page, limit)
|
||||
|
||||
open fun findByCitizenId(
|
||||
citizenId: UUID,
|
||||
page: Int = 1,
|
||||
limit: Int = 50
|
||||
): Paginated<FollowEntity<T>> {
|
||||
return requester.run {
|
||||
getFunction("find_follows_by_citizen")
|
||||
.select(page, limit,
|
||||
"citizen_id" to citizenId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun follow(follow: FollowEntity<T>) {
|
||||
val reference = follow.target::class.simpleName!!.toLowerCase()
|
||||
@@ -34,5 +55,33 @@ open class Follow <T: EntityI<UUID>>(override var requester: Requester): Reposit
|
||||
)
|
||||
}
|
||||
}
|
||||
class FollowArticleRepository(override var requester: Requester): Follow<ArticleEntity>(requester)
|
||||
class FollowConstitutionRepository(override var requester: Requester): Follow<ConstitutionEntity>(requester)
|
||||
|
||||
class FollowArticle (requester: Requester): Follow<ArticleEntity>(requester) {
|
||||
override fun findByCitizenId(
|
||||
citizenId: UUID,
|
||||
page: Int,
|
||||
limit: Int
|
||||
): Paginated<FollowEntity<ArticleEntity>> {
|
||||
return requester.run {
|
||||
getFunction("find_follows_article_by_citizen")
|
||||
.select(page, limit,
|
||||
"citizen_id" to citizenId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FollowConstitution (requester: Requester): Follow<ConstitutionEntity>(requester) {
|
||||
override fun findByCitizenId(
|
||||
citizenId: UUID,
|
||||
page: Int,
|
||||
limit: Int
|
||||
): Paginated<FollowEntity<ConstitutionEntity>> {
|
||||
return requester.run {
|
||||
getFunction("find_follows_constitution_by_citizen")
|
||||
.select(page, limit,
|
||||
"citizen_id" to citizenId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user