feature #8: create Vote Constitution route
This commit is contained in:
@@ -161,6 +161,7 @@ fun Application.module(env: Env = PROD) {
|
|||||||
commentArticle(get())
|
commentArticle(get())
|
||||||
commentConstitution(get())
|
commentConstitution(get())
|
||||||
voteArticle(get())
|
voteArticle(get())
|
||||||
|
voteConstitution(get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
41
src/main/kotlin/fr/dcproject/routes/VoteConstitution.kt
Normal file
41
src/main/kotlin/fr/dcproject/routes/VoteConstitution.kt
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package fr.dcproject.routes
|
||||||
|
|
||||||
|
import fr.dcproject.citizen
|
||||||
|
import fr.dcproject.entity.Citizen
|
||||||
|
import fr.dcproject.routes.VoteConstitutionPaths.ConstitutionVoteRequest.Content
|
||||||
|
import fr.dcproject.security.voter.VoteVoter.Action.CREATE
|
||||||
|
import fr.dcproject.security.voter.assertCan
|
||||||
|
import io.ktor.application.call
|
||||||
|
import io.ktor.http.HttpStatusCode
|
||||||
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
|
import io.ktor.locations.Location
|
||||||
|
import io.ktor.locations.put
|
||||||
|
import io.ktor.request.receive
|
||||||
|
import io.ktor.response.respond
|
||||||
|
import io.ktor.routing.Route
|
||||||
|
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||||
|
import fr.dcproject.entity.Vote as VoteEntity
|
||||||
|
import fr.dcproject.repository.VoteConstitution as VoteConstitutionRepository
|
||||||
|
|
||||||
|
@KtorExperimentalLocationsAPI
|
||||||
|
object VoteConstitutionPaths {
|
||||||
|
@Location("/constitutions/{constitution}/vote") class ConstitutionVoteRequest(val constitution: ConstitutionEntity) {
|
||||||
|
data class Content(var note: Int)
|
||||||
|
}
|
||||||
|
@Location("/citizens/{citizen}/votes/constitutions") class CitizenVoteConstitutionRequest(val citizen: Citizen)
|
||||||
|
}
|
||||||
|
|
||||||
|
@KtorExperimentalLocationsAPI
|
||||||
|
fun Route.voteConstitution(repo: VoteConstitutionRepository) {
|
||||||
|
put<VoteConstitutionPaths.ConstitutionVoteRequest> {
|
||||||
|
val content = call.receive<Content>()
|
||||||
|
val vote = VoteEntity(
|
||||||
|
target = it.constitution,
|
||||||
|
note = content.note,
|
||||||
|
createdBy = this.citizen
|
||||||
|
)
|
||||||
|
assertCan(CREATE, vote)
|
||||||
|
repo.vote(vote)
|
||||||
|
call.respond(HttpStatusCode.Created)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -403,6 +403,30 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
201:
|
201:
|
||||||
description: Return only http status 201 on success
|
description: Return only http status 201 on success
|
||||||
|
/constitutions/{constitution}/vote:
|
||||||
|
parameters:
|
||||||
|
- name: constitution
|
||||||
|
in: path
|
||||||
|
description: The ID of constitution
|
||||||
|
example: e74be8e4-6823-47c4-bd1b-789725b2fa8e
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
put:
|
||||||
|
security:
|
||||||
|
- JWTAuth: []
|
||||||
|
summary: Vote for one constitution
|
||||||
|
tags:
|
||||||
|
- vote
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/VoteRequest'
|
||||||
|
responses:
|
||||||
|
201:
|
||||||
|
description: Return only http status 201 on success
|
||||||
|
|
||||||
components:
|
components:
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ Feature: vote Article
|
|||||||
"""
|
"""
|
||||||
Then the response status code should be 201
|
Then the response status code should be 201
|
||||||
|
|
||||||
Scenario: Vote article
|
Scenario: Vote constitution
|
||||||
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
Given I am authenticated as John Doe with id "64b7b379-2298-43ec-b428-ba134930cabd"
|
||||||
When I send a PUT request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/vote" with body:
|
When I send a PUT request to "/constitutions/64b1f265-bfb3-332b-eef9-d00f63a3beaa/vote" with body:
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
"note": -1
|
"note": -1
|
||||||
|
|||||||
Reference in New Issue
Block a user