Big refactoring #77
@@ -1,16 +1,19 @@
|
|||||||
package fr.dcproject.component.follow.routes.article
|
package fr.dcproject.component.follow.routes.article
|
||||||
|
|
||||||
|
import fr.dcproject.common.response.toOutput
|
||||||
import fr.dcproject.common.security.assert
|
import fr.dcproject.common.security.assert
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.database.CitizenRef
|
import fr.dcproject.component.citizen.database.CitizenRef
|
||||||
import fr.dcproject.component.follow.FollowAccessControl
|
import fr.dcproject.component.follow.FollowAccessControl
|
||||||
import fr.dcproject.component.follow.database.FollowArticleRepository
|
import fr.dcproject.component.follow.database.FollowArticleRepository
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
|
import io.ktor.http.HttpStatusCode
|
||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.get
|
import io.ktor.locations.get
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
|
import org.joda.time.DateTime
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
@@ -24,7 +27,22 @@ object GetMyFollowsArticle {
|
|||||||
get<CitizenFollowArticleRequest> {
|
get<CitizenFollowArticleRequest> {
|
||||||
val follows = repo.findByCitizen(it.citizen)
|
val follows = repo.findByCitizen(it.citizen)
|
||||||
ac.assert { canView(follows.result, citizenOrNull) }
|
ac.assert { canView(follows.result, citizenOrNull) }
|
||||||
call.respond(follows)
|
call.respond(
|
||||||
|
HttpStatusCode.OK,
|
||||||
|
follows.toOutput { 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -770,6 +770,31 @@ paths:
|
|||||||
description: Return only http status 204 on success
|
description: Return only http status 204 on success
|
||||||
401:
|
401:
|
||||||
$ref: '#/components/responses/401'
|
$ref: '#/components/responses/401'
|
||||||
|
/citizens/{citizen}/follows/articles:
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/citizen'
|
||||||
|
get:
|
||||||
|
security:
|
||||||
|
- JWTAuth: [ ]
|
||||||
|
summary: Return Follow or nothing if you not follow
|
||||||
|
tags:
|
||||||
|
- follow
|
||||||
|
- article
|
||||||
|
- citizen
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Return your follows
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/components/schemas/Paginated'
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
result:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/FollowResponse'
|
||||||
|
|
||||||
components:
|
components:
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class `Follow articles routes` : BaseTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `I can get follow article`() {
|
fun `I can get my follow article`() {
|
||||||
withIntegrationApplication {
|
withIntegrationApplication {
|
||||||
`Given I have article`(id = "d743619a-1f6b-4d20-a2d6-8e81f0e6a4c8")
|
`Given I have article`(id = "d743619a-1f6b-4d20-a2d6-8e81f0e6a4c8")
|
||||||
`Given I have citizen`("Johannes", "Kepler", id = "e4592d53-3660-4264-8353-ebdbf5d9c41c") {
|
`Given I have citizen`("Johannes", "Kepler", id = "e4592d53-3660-4264-8353-ebdbf5d9c41c") {
|
||||||
|
|||||||
Reference in New Issue
Block a user