Test openapi schema of GET /constitutions/{constitution}/follows
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.follow.routes.constitution
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.component.auth.citizen
|
||||
import fr.dcproject.component.auth.citizenOrNull
|
||||
@@ -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 GetFollowConstitution {
|
||||
get<ConstitutionFollowRequest> {
|
||||
repo.findFollow(citizen, it.constitution)?.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.NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package fr.dcproject.component.follow.routes.constitution
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.component.auth.citizenOrNull
|
||||
import fr.dcproject.component.citizen.database.CitizenRef
|
||||
import fr.dcproject.component.follow.FollowAccessControl
|
||||
import fr.dcproject.component.follow.database.FollowConstitutionRepository
|
||||
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,22 @@ object GetMyFollowsConstitution {
|
||||
get<CitizenFollowConstitutionRequest> {
|
||||
val follows = repo.findByCitizen(it.citizen)
|
||||
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
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,6 +796,75 @@ paths:
|
||||
items:
|
||||
$ref: '#/components/schemas/FollowResponse'
|
||||
|
||||
/constitutions/{constitution}/follows:
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/constitution'
|
||||
get:
|
||||
security:
|
||||
- JWTAuth: [ ]
|
||||
summary: Return Follow or nothing if you not follow
|
||||
tags:
|
||||
- follow
|
||||
- constitution
|
||||
responses:
|
||||
200:
|
||||
description: Return your follow
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/FollowResponse'
|
||||
404:
|
||||
description: You not follow this constitution
|
||||
post:
|
||||
security:
|
||||
- JWTAuth: [ ]
|
||||
summary: Follow one constitution
|
||||
tags:
|
||||
- follow
|
||||
- constitution
|
||||
responses:
|
||||
201:
|
||||
description: Return only http status 201 on success
|
||||
401:
|
||||
$ref: '#/components/responses/401'
|
||||
delete:
|
||||
security:
|
||||
- JWTAuth: [ ]
|
||||
summary: Unfollow one constitution
|
||||
tags:
|
||||
- follow
|
||||
- constitution
|
||||
responses:
|
||||
204:
|
||||
description: Return only http status 204 on success
|
||||
401:
|
||||
$ref: '#/components/responses/401'
|
||||
/citizens/{citizen}/follows/constitutions:
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/citizen'
|
||||
get:
|
||||
security:
|
||||
- JWTAuth: [ ]
|
||||
summary: Return Follow or nothing if you not follow
|
||||
tags:
|
||||
- follow
|
||||
- constitution
|
||||
- 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:
|
||||
parameters:
|
||||
page:
|
||||
|
||||
@@ -37,7 +37,7 @@ class `Follow constitutions routes` : BaseTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `I can get follow constitution`() {
|
||||
fun `I can get my follow constitution`() {
|
||||
withIntegrationApplication {
|
||||
`Given I have constitution`(id = "7f642078-8e74-47fc-9712-0c37531674a0")
|
||||
`Given I have citizen`("André-Marie", "Ampère", id = "877b45b0-302d-487d-8944-6d03ccdbd0f8") {
|
||||
|
||||
Reference in New Issue
Block a user