diff --git a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt index eb33539..ba81b28 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt @@ -1,16 +1,19 @@ package fr.dcproject.component.comment.article.routes +import fr.dcproject.common.dto.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.citizen.database.CitizenRef import fr.dcproject.component.comment.article.database.CommentArticleRepository import fr.dcproject.component.comment.generic.CommentAccessControl import io.ktor.application.call +import io.ktor.http.HttpStatusCode import io.ktor.locations.KtorExperimentalLocationsAPI import io.ktor.locations.Location import io.ktor.locations.get import io.ktor.response.respond import io.ktor.routing.Route +import org.joda.time.DateTime import java.util.UUID @KtorExperimentalLocationsAPI @@ -24,7 +27,54 @@ object GetCitizenArticleComments { get { repo.findByCitizen(it.citizen).let { comments -> ac.assert { canView(comments.result, citizenOrNull) } - call.respond(comments) + call.respond( + HttpStatusCode.OK, + comments.toOutput { comment -> + object { + val id: UUID = comment.id + val content: String = comment.content + val childrenCount: Int = comment.childrenCount ?: 0 + val createdAt: DateTime = comment.createdAt + val parent: Any? = comment.parent?.let { p -> + object { + val id: UUID = p.id + val reference: String = p.reference + } + } + val target: Any = comment.target.let { t -> + object { + val id: UUID = t.id + val reference: String = t.reference + } + } + val createdBy: Any = comment.createdBy.let { c -> + object { + val id: UUID = c.id + val name: Any = c.name.let { n -> + object { + val firstName: String = n.firstName + val lastName: String = n.lastName + } + } + val user: Any = c.user.let { u -> + object { + val username: String = u.username + } + } + } + } + val votes: Any = comment.votes.let { v -> + object { + val up: Int = v.up + val neutral: Int = v.neutral + val down: Int = v.down + val total: Int = v.total + val score: Int = v.score + } + } + } + } + ) } } } diff --git a/src/main/resources/openapi2.yaml b/src/main/resources/openapi2.yaml index 384d000..c325996 100644 --- a/src/main/resources/openapi2.yaml +++ b/src/main/resources/openapi2.yaml @@ -573,6 +573,33 @@ paths: $ref: '#/components/schemas/CommentResponse' 401: $ref: '#/components/responses/401' + /citizens/{citizen}/comments/articles: + parameters: + - $ref: '#/components/parameters/citizen' + get: + security: + - JWTAuth: [] + summary: all article comments for one citizen + tags: + - comment + - article + - citizen + responses: + 200: + description: Comments + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Paginated' + - type: object + properties: + result: + type: array + items: + $ref: '#/components/schemas/CommentResponse' + 401: + $ref: '#/components/responses/401' components: parameters: