From fc138790ea9f7fe11627ef151d6ee08d92ea409b Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Wed, 2 Oct 2019 01:28:43 +0200 Subject: [PATCH] Can get current Citizen --- src/main/kotlin/fr/dcproject/routes/Citizen.kt | 8 ++++++++ src/main/resources/openApi.yaml | 15 +++++++++++++++ src/test/resources/feature/citizen.feature | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/src/main/kotlin/fr/dcproject/routes/Citizen.kt b/src/main/kotlin/fr/dcproject/routes/Citizen.kt index 348ea7c..41f9049 100644 --- a/src/main/kotlin/fr/dcproject/routes/Citizen.kt +++ b/src/main/kotlin/fr/dcproject/routes/Citizen.kt @@ -1,5 +1,6 @@ package fr.dcproject.routes +import fr.dcproject.citizen import fr.dcproject.entity.Citizen import fr.dcproject.security.voter.CitizenVoter.Action.VIEW import fr.dcproject.security.voter.assertCan @@ -19,6 +20,7 @@ object CitizenPaths { val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit } @Location("/citizens/{citizen}") class CitizenRequest(val citizen: Citizen) + @Location("/citizens/current") class CurrentCitizenRequest @Location("/citizens/{citizen}/follows/articles") class CitizenFollowArticleRequest(val citizen: Citizen) @Location("/citizens/{citizen}/follows/constitutions") class CitizenFollowConstitutionRequest(val citizen: Citizen) } @@ -36,4 +38,10 @@ fun Route.citizen(repo: CitizenRepository) { call.respond(it.citizen) } + + get { + assertCan(VIEW, citizen) + + call.respond(citizen) + } } \ No newline at end of file diff --git a/src/main/resources/openApi.yaml b/src/main/resources/openApi.yaml index e4ee021..73d46dc 100644 --- a/src/main/resources/openApi.yaml +++ b/src/main/resources/openApi.yaml @@ -38,6 +38,21 @@ paths: example: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBdXRoZW50aWNhdGlvbiIsImlzcyI6ImRjLXByb2plY3QuZnIiLCJpZCI6ImQ1NDRhNmE4LWJhYjgtNDU2MC05NWIxLThhZjAyMDNkOTEwNCIsImV4cCI6MTU2NzA3Mzc0Mn0.0VTetv8fZFjVgpJ-bwJpidGNHJUOmgj8vuZcZXzwnLa7TtFwcXWvh3bDPYHqB66nmOfXyM57XnHDbmRwtipCag + /citizens/current: + get: + security: + - JWTAuth: [] + summary: Get Citizen + tags: + - citizen + operationId: getCurrentCitizen + responses: + 200: + description: The Citizen object + content: + application/json: + schema: + $ref: '#/components/schemas/CitizenResponse' /citizens/{citizen}: get: security: diff --git a/src/test/resources/feature/citizen.feature b/src/test/resources/feature/citizen.feature index 407c13e..e006407 100644 --- a/src/test/resources/feature/citizen.feature +++ b/src/test/resources/feature/citizen.feature @@ -11,3 +11,10 @@ Feature: citizens routes Then the response status code should be 200 And the response should contain object: | id | 6434f4f9-f570-f22a-c134-8668350651ff | + + Scenario: Can get connected citizen + Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd" + When I send a GET request to "/citizens/current" + Then the response status code should be 200 + And the response should contain object: + | id | 64b7b379-2298-43ec-b428-ba134930cabd |