Big refactoring #77
@@ -1,6 +1,7 @@
|
||||
package fr.dcproject.component.citizen.routes
|
||||
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.component.auth.citizen
|
||||
import fr.dcproject.component.auth.citizenOrNull
|
||||
import fr.dcproject.component.citizen.CitizenAccessControl
|
||||
import fr.dcproject.component.citizen.database.CitizenRef
|
||||
@@ -12,6 +13,8 @@ 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 org.joda.time.format.ISODateTimeFormat
|
||||
import java.util.UUID
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
@@ -26,7 +29,25 @@ object GetOneCitizen {
|
||||
val citizen = citizenRepository.findById(it.citizen.id) ?: throw NotFoundException("Citizen not found ${it.citizen.id}")
|
||||
ac.assert { canView(citizen, citizenOrNull) }
|
||||
|
||||
call.respond(it.citizen)
|
||||
call.respond(
|
||||
object {
|
||||
val id: UUID = citizen.id
|
||||
val name: Any = citizen.name.let { n ->
|
||||
object {
|
||||
val firstName: String = n.firstName
|
||||
val lastName: String = n.lastName
|
||||
}
|
||||
}
|
||||
val email: String = citizen.email
|
||||
val birthday: String = citizen.birthday.run {
|
||||
toString(ISODateTimeFormat.date())
|
||||
}
|
||||
val createdAt: DateTime = citizen.createdAt
|
||||
val user: Any = object {
|
||||
val username: String = citizen.user.username
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,32 +389,7 @@ paths:
|
||||
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
|
||||
$ref: '#/components/schemas/CitizenListResponse'
|
||||
401:
|
||||
$ref: '#/components/responses/401'
|
||||
|
||||
@@ -432,52 +407,29 @@ paths:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- email
|
||||
- createdAt
|
||||
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
|
||||
birthday:
|
||||
type: string
|
||||
format: 'date'
|
||||
example: '1984-12-25'
|
||||
createdAt:
|
||||
type: string
|
||||
format: 'date-time'
|
||||
user:
|
||||
type: object
|
||||
required:
|
||||
- username
|
||||
properties:
|
||||
id:
|
||||
$ref: '#/components/schemas/UUID'
|
||||
username:
|
||||
type: string
|
||||
example:
|
||||
john-doe
|
||||
$ref: '#/components/schemas/CitizenResponse'
|
||||
|
||||
/citizens/{citizen}:
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/citizen'
|
||||
get:
|
||||
security:
|
||||
- JWTAuth: []
|
||||
summary: Get Citizen
|
||||
tags:
|
||||
- citizen
|
||||
operationId: getCitizen
|
||||
responses:
|
||||
200:
|
||||
description: The Citizen object
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CitizenResponse'
|
||||
404:
|
||||
description: Citizen not found
|
||||
401:
|
||||
$ref: '#/components/responses/401'
|
||||
components:
|
||||
parameters:
|
||||
page:
|
||||
@@ -560,6 +512,16 @@ components:
|
||||
type: string
|
||||
format: uuid
|
||||
|
||||
citizen:
|
||||
name: citizen
|
||||
in: path
|
||||
description: ID of citizen
|
||||
example: 6434f4f9-f570-f22a-c134-8668350651ff
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
|
||||
responses:
|
||||
401:
|
||||
description: Unautorized
|
||||
@@ -723,6 +685,81 @@ components:
|
||||
score:
|
||||
type: integer
|
||||
|
||||
CitizenListResponse:
|
||||
additionalProperties: false
|
||||
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
|
||||
CitizenResponse:
|
||||
additionalProperties: false
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- email
|
||||
- createdAt
|
||||
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
|
||||
birthday:
|
||||
type: string
|
||||
format: 'date'
|
||||
example: '1984-12-25'
|
||||
createdAt:
|
||||
type: string
|
||||
format: 'date-time'
|
||||
user:
|
||||
type: object
|
||||
required:
|
||||
- username
|
||||
properties:
|
||||
id:
|
||||
$ref: '#/components/schemas/UUID'
|
||||
username:
|
||||
type: string
|
||||
example:
|
||||
john-doe
|
||||
securitySchemes:
|
||||
JWTAuth:
|
||||
type: http
|
||||
|
||||
Reference in New Issue
Block a user