diff --git a/src/main/kotlin/fr/dcproject/component/follow/database/FollowRepository.kt b/src/main/kotlin/fr/dcproject/component/follow/database/FollowRepository.kt index 32d6623..7db5aa0 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/database/FollowRepository.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/database/FollowRepository.kt @@ -59,7 +59,7 @@ sealed class FollowRepository(override var requ open fun findFollow( citizen: CitizenI, target: TargetRef - ): FollowForView? = + ): FollowForView? = requester .getFunction("find_follow") .selectOne( diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt index 56852ec..2b24f80 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt @@ -1,5 +1,6 @@ package fr.dcproject.component.follow.routes.article +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.article.database.ArticleRef import fr.dcproject.component.auth.citizen @@ -13,6 +14,7 @@ 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 @@ -26,7 +28,22 @@ object GetFollowArticle { get { repo.findFollow(citizen, it.article)?.let { follow -> ac.assert { canView(follow, citizenOrNull) } - call.respond(follow) + call.respond( + HttpStatusCode.OK, + follow.let { f -> + object { + val id: UUID = f.id + val createdBy: Any = f.createdBy.toOutput() + val target: Any = f.target.let { t -> + object { + val id: UUID = t.id + val reference: String = f.target.reference + } + } + val createdAt: DateTime = f.createdAt + } + } + ) } ?: call.respond(HttpStatusCode.NoContent) } } diff --git a/src/main/resources/openapi2.yaml b/src/main/resources/openapi2.yaml index d6f67b3..f0b0ead 100644 --- a/src/main/resources/openapi2.yaml +++ b/src/main/resources/openapi2.yaml @@ -729,6 +729,48 @@ paths: schema: $ref: '#/components/schemas/ConstitutionResponse' + /articles/{article}/follows: + parameters: + - $ref: '#/components/parameters/article' + get: + security: + - JWTAuth: [ ] + summary: Return Follow or nothing if you not follow + tags: + - follow + - article + responses: + 200: + description: Return your follow + content: + application/json: + schema: + $ref: '#/components/schemas/FollowResponse' + 404: + description: You not follow this article + post: + security: + - JWTAuth: [ ] + summary: Follow one article + tags: + - follow + - article + responses: + 201: + description: Return only http status 201 on success + delete: + security: + - JWTAuth: [ ] + summary: Unfollow one article + tags: + - follow + - article + responses: + 204: + description: Return only http status 204 on success + 401: + $ref: '#/components/responses/401' + components: parameters: page: @@ -1343,6 +1385,32 @@ components: type: string format: 'date-time' + FollowResponse: + additionalProperties: false + required: + - id + - createdBy + - createdAt + - target + properties: + id: + $ref: '#/components/schemas/UUID' + createdBy: + $ref: '#/components/schemas/CitizenCreator' + createdAt: + type: string + format: 'date-time' + target: + required: + - id + - reference + additionalProperties: false + properties: + id: + $ref: '#/components/schemas/UUID' + reference: + type: string + securitySchemes: JWTAuth: type: http