fix "CommentRepository.findByCitizen"
This commit is contained in:
@@ -11,28 +11,20 @@ import fr.dcproject.entity.Citizen as CitizenEntity
|
|||||||
import fr.dcproject.entity.Comment as CommentEntity
|
import fr.dcproject.entity.Comment as CommentEntity
|
||||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||||
|
|
||||||
open class Comment <T: UuidEntity>(override var requester: Requester): RepositoryI<CommentEntity<T>> {
|
abstract class Comment <T: UuidEntity>(override var requester: Requester): RepositoryI<CommentEntity<T>> {
|
||||||
override val entityName = CommentEntity::class as KClass<CommentEntity<T>>
|
override val entityName = CommentEntity::class as KClass<CommentEntity<T>>
|
||||||
|
|
||||||
open fun findByCitizen(
|
open fun findById(id: UUID): CommentEntity<ArticleEntity>? {
|
||||||
|
return requester
|
||||||
|
.getFunction("find_comment_by_id")
|
||||||
|
.selectOne(mapOf("id" to id))
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun findByCitizen(
|
||||||
citizen: CitizenEntity,
|
citizen: CitizenEntity,
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
limit: Int = 50
|
limit: Int = 50
|
||||||
): Paginated<CommentEntity<T>> =
|
): Paginated<CommentEntity<T>>
|
||||||
findByCitizen(citizen.id ?: error("The citizen must have an id"), page, limit)
|
|
||||||
|
|
||||||
open fun findByCitizen(
|
|
||||||
citizenId: UUID,
|
|
||||||
page: Int = 1,
|
|
||||||
limit: Int = 50
|
|
||||||
): Paginated<CommentEntity<T>> {
|
|
||||||
return requester.run {
|
|
||||||
getFunction("find_comments_by_citizen")
|
|
||||||
.select(page, limit,
|
|
||||||
"created_by_id" to citizenId
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun findByParent(
|
open fun findByParent(
|
||||||
parent: CommentEntity<T>,
|
parent: CommentEntity<T>,
|
||||||
@@ -101,23 +93,32 @@ open class Comment <T: UuidEntity>(override var requester: Requester): Repositor
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CommentGeneric (requester: Requester): Comment<UuidEntity>(requester) {
|
class CommentGeneric (requester: Requester): Comment<UuidEntity>(requester) {
|
||||||
fun findById(id: UUID): CommentEntity<ArticleEntity>? {
|
override fun findByCitizen(
|
||||||
return requester
|
citizen: CitizenEntity,
|
||||||
.getFunction("find_comment_by_id")
|
page: Int,
|
||||||
.selectOne(mapOf("id" to id))
|
limit: Int
|
||||||
|
): Paginated<CommentEntity<UuidEntity>> {
|
||||||
|
return requester.run {
|
||||||
|
getFunction("find_comments_by_citizen")
|
||||||
|
.select(page, limit,
|
||||||
|
"created_by_id" to citizen.id
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommentArticle (requester: Requester): Comment<ArticleEntity>(requester) {
|
class CommentArticle (requester: Requester): Comment<ArticleEntity>(requester) {
|
||||||
override fun findByCitizen(
|
override fun findByCitizen(
|
||||||
citizenId: UUID,
|
citizen: CitizenEntity,
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int
|
limit: Int
|
||||||
): Paginated<CommentEntity<ArticleEntity>> {
|
): Paginated<CommentEntity<ArticleEntity>> {
|
||||||
|
val reference = ArticleEntity::class.simpleName!!.toLowerCase()
|
||||||
return requester.run {
|
return requester.run {
|
||||||
getFunction("find_comments_article_by_citizen")
|
getFunction("find_comments_by_citizen")
|
||||||
.select(page, limit,
|
.select(page, limit,
|
||||||
"created_by_id" to citizenId
|
"created_by_id" to citizen.id,
|
||||||
|
"reference" to reference
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,14 +126,16 @@ class CommentArticle (requester: Requester): Comment<ArticleEntity>(requester) {
|
|||||||
|
|
||||||
class CommentConstitution (requester: Requester): Comment<ConstitutionEntity>(requester) {
|
class CommentConstitution (requester: Requester): Comment<ConstitutionEntity>(requester) {
|
||||||
override fun findByCitizen(
|
override fun findByCitizen(
|
||||||
citizenId: UUID,
|
citizen: CitizenEntity,
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int
|
limit: Int
|
||||||
): Paginated<CommentEntity<ConstitutionEntity>> {
|
): Paginated<CommentEntity<ConstitutionEntity>> {
|
||||||
|
val reference = ConstitutionEntity::class.simpleName!!.toLowerCase()
|
||||||
return requester.run {
|
return requester.run {
|
||||||
getFunction("find_comments_constitution_by_citizen")
|
getFunction("find_comments_by_citizen")
|
||||||
.select(page, limit,
|
.select(page, limit,
|
||||||
"created_by_id" to citizenId
|
"created_by_id" to citizen.id,
|
||||||
|
"reference" to reference
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Feature: comment Article and Constitution
|
|||||||
"""
|
"""
|
||||||
Then the response status code should be 201
|
Then the response status code should be 201
|
||||||
|
|
||||||
Scenario: The route for get comments of articles must response a 200 and return objects
|
Scenario: The route for get comments of articles for the current citizen must response a 200 and return objects
|
||||||
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
Given I have citizen John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||||
And I have article with id "9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b"
|
And I have article with id "9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b"
|
||||||
When I send a GET request to "/citizens/64b7b379-2298-43ec-b428-ba134930cabd/comments/articles"
|
When I send a GET request to "/citizens/64b7b379-2298-43ec-b428-ba134930cabd/comments/articles"
|
||||||
|
|||||||
Reference in New Issue
Block a user