Fix get all commet of article
This commit is contained in:
@@ -98,6 +98,13 @@ fun Application.module(env: Env = PROD) {
|
|||||||
} ?: throw NotFoundException("Comment $values not found")
|
} ?: throw NotFoundException("Comment $values not found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
convert<ConstitutionRef> {
|
||||||
|
decode { values, _ ->
|
||||||
|
values.singleOrNull()?.let {
|
||||||
|
ConstitutionRef(UUID.fromString(it))
|
||||||
|
} ?: throw NotFoundException("Constitution $values not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
convert<Constitution> {
|
convert<Constitution> {
|
||||||
decode { values, _ ->
|
decode { values, _ ->
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package fr.dcproject.repository
|
package fr.dcproject.repository
|
||||||
|
|
||||||
import fr.dcproject.entity.ArticleRef
|
import fr.dcproject.entity.ArticleRef
|
||||||
|
import fr.dcproject.entity.ConstitutionRef
|
||||||
import fr.dcproject.entity.TargetI
|
import fr.dcproject.entity.TargetI
|
||||||
import fr.dcproject.entity.TargetRef
|
import fr.dcproject.entity.TargetRef
|
||||||
import fr.postgresjson.connexion.Paginated
|
import fr.postgresjson.connexion.Paginated
|
||||||
@@ -10,7 +11,6 @@ import fr.postgresjson.repository.RepositoryI
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import fr.dcproject.entity.Citizen as CitizenEntity
|
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
|
|
||||||
|
|
||||||
abstract class Comment<T : TargetI>(override var requester: Requester) : RepositoryI {
|
abstract class Comment<T : TargetI>(override var requester: Requester) : RepositoryI {
|
||||||
abstract fun findById(id: UUID): CommentEntity<T>?
|
abstract fun findById(id: UUID): CommentEntity<T>?
|
||||||
@@ -127,10 +127,24 @@ class CommentArticle(requester: Requester) : Comment<ArticleRef>(requester) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun findByTarget(
|
||||||
|
target: UuidEntityI,
|
||||||
|
page: Int,
|
||||||
|
limit: Int
|
||||||
|
): Paginated<CommentEntity<ArticleRef>> {
|
||||||
|
return requester.run {
|
||||||
|
getFunction("find_comments_by_target")
|
||||||
|
.select(
|
||||||
|
page, limit,
|
||||||
|
"target_id" to target.id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommentConstitution(requester: Requester) : Comment<ConstitutionEntity>(requester) {
|
class CommentConstitution(requester: Requester) : Comment<ConstitutionRef>(requester) {
|
||||||
override fun findById(id: UUID): CommentEntity<ConstitutionEntity>? {
|
override fun findById(id: UUID): CommentEntity<ConstitutionRef>? {
|
||||||
return requester
|
return requester
|
||||||
.getFunction("find_comment_by_id")
|
.getFunction("find_comment_by_id")
|
||||||
.selectOne(mapOf("id" to id))
|
.selectOne(mapOf("id" to id))
|
||||||
@@ -140,13 +154,27 @@ class CommentConstitution(requester: Requester) : Comment<ConstitutionEntity>(re
|
|||||||
citizen: CitizenEntity,
|
citizen: CitizenEntity,
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int
|
limit: Int
|
||||||
): Paginated<CommentEntity<ConstitutionEntity>> {
|
): Paginated<CommentEntity<ConstitutionRef>> {
|
||||||
return requester.run {
|
return requester.run {
|
||||||
getFunction("find_comments_by_citizen")
|
getFunction("find_comments_by_citizen")
|
||||||
.select(
|
.select(
|
||||||
page, limit,
|
page, limit,
|
||||||
"created_by_id" to citizen.id,
|
"created_by_id" to citizen.id,
|
||||||
"reference" to TargetI.getReference(ConstitutionEntity::class)
|
"reference" to TargetI.getReference(ConstitutionRef::class)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun findByTarget(
|
||||||
|
target: UuidEntityI,
|
||||||
|
page: Int,
|
||||||
|
limit: Int
|
||||||
|
): Paginated<CommentEntity<ConstitutionRef>> {
|
||||||
|
return requester.run {
|
||||||
|
getFunction("find_comments_by_target")
|
||||||
|
.select(
|
||||||
|
page, limit,
|
||||||
|
"target_id" to target.id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package fr.dcproject.routes
|
|||||||
|
|
||||||
import fr.dcproject.citizen
|
import fr.dcproject.citizen
|
||||||
import fr.dcproject.entity.Citizen
|
import fr.dcproject.entity.Citizen
|
||||||
|
import fr.dcproject.entity.ConstitutionRef
|
||||||
import fr.dcproject.security.voter.CommentVoter.Action.CREATE
|
import fr.dcproject.security.voter.CommentVoter.Action.CREATE
|
||||||
import fr.dcproject.security.voter.CommentVoter.Action.VIEW
|
import fr.dcproject.security.voter.CommentVoter.Action.VIEW
|
||||||
import fr.dcproject.security.voter.assertCan
|
import fr.dcproject.security.voter.assertCan
|
||||||
@@ -15,13 +16,12 @@ import io.ktor.request.receiveText
|
|||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import fr.dcproject.entity.Comment as CommentEntity
|
import fr.dcproject.entity.Comment as CommentEntity
|
||||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
|
||||||
import fr.dcproject.repository.CommentConstitution as CommentConstitutionRepository
|
import fr.dcproject.repository.CommentConstitution as CommentConstitutionRepository
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
object CommentConstitutionPaths {
|
object CommentConstitutionPaths {
|
||||||
@Location("/constitutions/{constitution}/comments")
|
@Location("/constitutions/{constitution}/comments")
|
||||||
class ConstitutionCommentRequest(val constitution: ConstitutionEntity)
|
class ConstitutionCommentRequest(val constitution: ConstitutionRef)
|
||||||
|
|
||||||
@Location("/citizens/{citizen}/comments/constitutions")
|
@Location("/citizens/{citizen}/comments/constitutions")
|
||||||
class CitizenCommentConstitutionRequest(val citizen: Citizen)
|
class CitizenCommentConstitutionRequest(val citizen: Citizen)
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ Feature: comment Article
|
|||||||
"""
|
"""
|
||||||
Then the response status code should be 201
|
Then the response status code should be 201
|
||||||
|
|
||||||
|
Scenario: Can get all comment on article
|
||||||
|
Given I am authenticated as 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 "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/comments"
|
||||||
|
Then the response status code should be 200
|
||||||
|
|
||||||
Scenario: Can get comments on articles of the current citizen
|
Scenario: Can get comments on articles of the current citizen
|
||||||
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user