Test openapi schema of /citizens
This commit is contained in:
@@ -35,7 +35,7 @@ class CitizenRepository(override var requester: Requester) : RepositoryI {
|
|||||||
sort: String? = null,
|
sort: String? = null,
|
||||||
direction: RepositoryI.Direction? = null,
|
direction: RepositoryI.Direction? = null,
|
||||||
search: String? = null
|
search: String? = null
|
||||||
): Paginated<CitizenCart> = requester
|
): Paginated<CitizenCreator> = requester
|
||||||
.getFunction("find_citizens")
|
.getFunction("find_citizens")
|
||||||
.select(
|
.select(
|
||||||
page,
|
page,
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package fr.dcproject.component.citizen.routes
|
package fr.dcproject.component.citizen.routes
|
||||||
|
|
||||||
|
import fr.dcproject.common.dto.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.CitizenAccessControl
|
import fr.dcproject.component.citizen.CitizenAccessControl
|
||||||
|
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||||
import fr.dcproject.component.citizen.database.CitizenRepository
|
import fr.dcproject.component.citizen.database.CitizenRepository
|
||||||
import fr.dcproject.routes.PaginatedRequest
|
import fr.dcproject.routes.PaginatedRequest
|
||||||
import fr.dcproject.routes.PaginatedRequestI
|
import fr.dcproject.routes.PaginatedRequestI
|
||||||
@@ -13,6 +15,7 @@ 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 java.util.UUID
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
object FindCitizens {
|
object FindCitizens {
|
||||||
@@ -29,7 +32,18 @@ object FindCitizens {
|
|||||||
get<CitizensRequest> {
|
get<CitizensRequest> {
|
||||||
val citizens = repo.find(it.page, it.limit, it.sort, it.direction, it.search)
|
val citizens = repo.find(it.page, it.limit, it.sort, it.direction, it.search)
|
||||||
ac.assert { canView(citizens.result, citizenOrNull) }
|
ac.assert { canView(citizens.result, citizenOrNull) }
|
||||||
call.respond(citizens)
|
call.respond(
|
||||||
|
citizens.toOutput { c: CitizenCreator ->
|
||||||
|
object {
|
||||||
|
val id: UUID = c.id
|
||||||
|
val name: Any = object {
|
||||||
|
val firstName: String = c.name.firstName
|
||||||
|
val lastName: String = c.name.lastName
|
||||||
|
}
|
||||||
|
val email: String = c.email
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -362,6 +362,62 @@ paths:
|
|||||||
404:
|
404:
|
||||||
description: no user with this email
|
description: no user with this email
|
||||||
|
|
||||||
|
/citizens:
|
||||||
|
get:
|
||||||
|
security:
|
||||||
|
- JWTAuth: []
|
||||||
|
summary: Get all citizens
|
||||||
|
tags:
|
||||||
|
- citizen
|
||||||
|
operationId: getCitizens
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/page'
|
||||||
|
- $ref: '#/components/parameters/limit'
|
||||||
|
- $ref: '#/components/parameters/sort'
|
||||||
|
- $ref: '#/components/parameters/direction'
|
||||||
|
- $ref: '#/components/parameters/search'
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: The Citizen objects
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/components/schemas/Paginated'
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
result:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- id
|
||||||
|
- name
|
||||||
|
- email
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
$ref: '#/components/schemas/UUID'
|
||||||
|
name:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- firstName
|
||||||
|
- lastName
|
||||||
|
properties:
|
||||||
|
firstName:
|
||||||
|
type: string
|
||||||
|
example:
|
||||||
|
john
|
||||||
|
lastName:
|
||||||
|
type: string
|
||||||
|
example:
|
||||||
|
Doe
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
format: email
|
||||||
|
example: my.email@dc-project.fr
|
||||||
|
401:
|
||||||
|
$ref: '#/components/responses/401'
|
||||||
|
|
||||||
components:
|
components:
|
||||||
parameters:
|
parameters:
|
||||||
page:
|
page:
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.TestInstance
|
|||||||
@Tags(Tag("integration"), Tag("citizen"))
|
@Tags(Tag("integration"), Tag("citizen"))
|
||||||
class `Citizen routes` : BaseTest() {
|
class `Citizen routes` : BaseTest() {
|
||||||
@Test
|
@Test
|
||||||
fun `I can get Citizens informations`() {
|
fun `I can get Citizens information`() {
|
||||||
withIntegrationApplication {
|
withIntegrationApplication {
|
||||||
`Given I have citizen`("Jean", "Perrin", id = "5267a5c6-af42-4a02-aa2b-6b71d2e43973")
|
`Given I have citizen`("Jean", "Perrin", id = "5267a5c6-af42-4a02-aa2b-6b71d2e43973")
|
||||||
`When I send a GET request`("/citizens") {
|
`When I send a GET request`("/citizens") {
|
||||||
|
|||||||
Reference in New Issue
Block a user