diff --git a/src/main/kotlin/fr/dcproject/component/citizen/routes/GetCurrentCitizen.kt b/src/main/kotlin/fr/dcproject/component/citizen/routes/GetCurrentCitizen.kt index db61b65..c6a5fc5 100644 --- a/src/main/kotlin/fr/dcproject/component/citizen/routes/GetCurrentCitizen.kt +++ b/src/main/kotlin/fr/dcproject/component/citizen/routes/GetCurrentCitizen.kt @@ -11,6 +11,9 @@ 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 object GetCurrentCitizen { @@ -24,7 +27,25 @@ object GetCurrentCitizen { call.respond(HttpStatusCode.Unauthorized) } else { ac.assert { canView(currentUser, citizenOrNull) } - call.respond(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 + } + } + ) } } } diff --git a/src/main/resources/openapi2.yaml b/src/main/resources/openapi2.yaml index b5fede6..6f2d692 100644 --- a/src/main/resources/openapi2.yaml +++ b/src/main/resources/openapi2.yaml @@ -418,6 +418,66 @@ paths: 401: $ref: '#/components/responses/401' + /citizens/current: + get: + security: + - JWTAuth: [] + summary: Get Citizen + tags: + - citizen + operationId: getCurrentCitizen + responses: + 200: + description: The Citizen object + 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 + components: parameters: page: diff --git a/src/test/kotlin/integration/Citizen routes.kt b/src/test/kotlin/integration/Citizen routes.kt index 1764ca3..9e268fa 100644 --- a/src/test/kotlin/integration/Citizen routes.kt +++ b/src/test/kotlin/integration/Citizen routes.kt @@ -35,7 +35,7 @@ class `Citizen routes` : BaseTest() { } @Test - fun `I can get specific Citizen informations`() { + fun `I can get specific Citizen information`() { withIntegrationApplication { `Given I have citizen`("Linus", "Pauling", id = "47a05c0f-7329-46c3-a7d0-325db37e9114") `When I send a GET request`("/citizens/47a05c0f-7329-46c3-a7d0-325db37e9114") { @@ -48,7 +48,7 @@ class `Citizen routes` : BaseTest() { } @Test - fun `I can get my citizen informations when I was connected`() { + fun `I can get my citizen information when I was connected`() { withIntegrationApplication { `Given I have citizen`("Henri", "Becquerel", id = "47356809-c8ef-4649-8b99-1c5cb9886d38") `When I send a GET request`("/citizens/current") { @@ -77,7 +77,7 @@ class `Citizen routes` : BaseTest() { } @Test - fun `I cannot change my password if request is bad formated`() { + fun `I cannot change my password if request is bad formatted`() { withIntegrationApplication { `Given I have citizen`("Louis", "Breguet", id = "6cf2a19d-d15d-4ee5-b2a9-907afd26b525") `When I send a PUT request`("/citizens/6cf2a19d-d15d-4ee5-b2a9-907afd26b525/password/change", Validate.RESPONSE_BODY) {