diff --git a/src/main/kotlin/fr/dcproject/repository/Comment.kt b/src/main/kotlin/fr/dcproject/repository/Comment.kt index d4ef39a..0cb39e6 100644 --- a/src/main/kotlin/fr/dcproject/repository/Comment.kt +++ b/src/main/kotlin/fr/dcproject/repository/Comment.kt @@ -11,28 +11,20 @@ import fr.dcproject.entity.Citizen as CitizenEntity import fr.dcproject.entity.Comment as CommentEntity import fr.dcproject.entity.Constitution as ConstitutionEntity -open class Comment (override var requester: Requester): RepositoryI> { +abstract class Comment (override var requester: Requester): RepositoryI> { override val entityName = CommentEntity::class as KClass> - open fun findByCitizen( + open fun findById(id: UUID): CommentEntity? { + return requester + .getFunction("find_comment_by_id") + .selectOne(mapOf("id" to id)) + } + + abstract fun findByCitizen( citizen: CitizenEntity, page: Int = 1, limit: Int = 50 - ): Paginated> = - findByCitizen(citizen.id ?: error("The citizen must have an id"), page, limit) - - open fun findByCitizen( - citizenId: UUID, - page: Int = 1, - limit: Int = 50 - ): Paginated> { - return requester.run { - getFunction("find_comments_by_citizen") - .select(page, limit, - "created_by_id" to citizenId - ) - } - } + ): Paginated> open fun findByParent( parent: CommentEntity, @@ -101,23 +93,32 @@ open class Comment (override var requester: Requester): Repositor } class CommentGeneric (requester: Requester): Comment(requester) { - fun findById(id: UUID): CommentEntity? { - return requester - .getFunction("find_comment_by_id") - .selectOne(mapOf("id" to id)) + override fun findByCitizen( + citizen: CitizenEntity, + page: Int, + limit: Int + ): Paginated> { + return requester.run { + getFunction("find_comments_by_citizen") + .select(page, limit, + "created_by_id" to citizen.id + ) + } } } class CommentArticle (requester: Requester): Comment(requester) { override fun findByCitizen( - citizenId: UUID, + citizen: CitizenEntity, page: Int, limit: Int ): Paginated> { + val reference = ArticleEntity::class.simpleName!!.toLowerCase() return requester.run { - getFunction("find_comments_article_by_citizen") + getFunction("find_comments_by_citizen") .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(requester) { class CommentConstitution (requester: Requester): Comment(requester) { override fun findByCitizen( - citizenId: UUID, + citizen: CitizenEntity, page: Int, limit: Int ): Paginated> { + val reference = ConstitutionEntity::class.simpleName!!.toLowerCase() return requester.run { - getFunction("find_comments_constitution_by_citizen") + getFunction("find_comments_by_citizen") .select(page, limit, - "created_by_id" to citizenId + "created_by_id" to citizen.id, + "reference" to reference ) } } diff --git a/src/test/resources/feature/comment.feature b/src/test/resources/feature/comment.feature index ab47dfd..907aeca 100644 --- a/src/test/resources/feature/comment.feature +++ b/src/test/resources/feature/comment.feature @@ -10,7 +10,7 @@ Feature: comment Article and Constitution """ 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" 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"