Test openapi schema of route /votes/*
This commit is contained in:
@@ -16,8 +16,8 @@ class VoteForView<T : TargetI>(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
override val createdBy: CitizenCreator,
|
||||
override val target: T,
|
||||
var note: Int,
|
||||
var anonymous: Boolean = true
|
||||
val note: Int,
|
||||
val anonymous: Boolean = true
|
||||
) : ExtraI<T, CitizenCreatorI>,
|
||||
VoteRef(id),
|
||||
CreatedAt by CreatedAt.Imp(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.vote.routes
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.common.utils.toUUID
|
||||
import fr.dcproject.component.auth.citizenOrNull
|
||||
@@ -7,6 +8,7 @@ import fr.dcproject.component.citizen.database.CitizenRef
|
||||
import fr.dcproject.component.vote.VoteAccessControl
|
||||
import fr.dcproject.component.vote.database.VoteRepository
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.locations.Location
|
||||
import io.ktor.locations.get
|
||||
@@ -28,7 +30,10 @@ object GetCitizenVotes {
|
||||
if (votes.isNotEmpty()) {
|
||||
ac.assert { canView(votes, citizenOrNull) }
|
||||
}
|
||||
call.respond(votes)
|
||||
call.respond(
|
||||
HttpStatusCode.OK,
|
||||
votes.map { it.toOutput() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.vote.routes
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.component.auth.citizenOrNull
|
||||
import fr.dcproject.component.citizen.database.CitizenRef
|
||||
@@ -8,6 +9,7 @@ import fr.dcproject.component.vote.database.VoteArticleRepository
|
||||
import fr.dcproject.routes.PaginatedRequest
|
||||
import fr.dcproject.routes.PaginatedRequestI
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.locations.Location
|
||||
import io.ktor.locations.get
|
||||
@@ -32,7 +34,10 @@ object GetCitizenVotesOnArticle {
|
||||
val votes = repo.findByCitizen(it.citizen, it.page, it.limit)
|
||||
ac.assert { canView(votes.result, citizenOrNull) }
|
||||
|
||||
call.respond(votes)
|
||||
call.respond(
|
||||
HttpStatusCode.OK,
|
||||
votes.toOutput { it.toOutput() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,10 @@ object PutVoteOnArticle {
|
||||
)
|
||||
ac.assert { canCreate(vote, citizenOrNull) }
|
||||
val votes = repo.vote(vote)
|
||||
call.respond(HttpStatusCode.Created, votes)
|
||||
call.respond(
|
||||
HttpStatusCode.Created,
|
||||
votes.toOutput()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,10 @@ object PutVoteOnComment {
|
||||
)
|
||||
ac.assert { canCreate(vote, citizenOrNull) }
|
||||
val votes = voteCommentRepo.vote(vote)
|
||||
call.respond(HttpStatusCode.Created, votes)
|
||||
call.respond(
|
||||
HttpStatusCode.Created,
|
||||
votes.toOutput()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import fr.dcproject.component.constitution.database.ConstitutionRepository
|
||||
import fr.dcproject.component.vote.VoteAccessControl
|
||||
import fr.dcproject.component.vote.database.VoteConstitutionRepository
|
||||
import fr.dcproject.component.vote.database.VoteForUpdate
|
||||
import fr.dcproject.component.vote.routes.VoteConstitution.ConstitutionVoteRequest.Input
|
||||
import fr.dcproject.component.vote.routes.PutVoteOnConstitution.ConstitutionVoteRequest.Input
|
||||
import io.ktor.application.call
|
||||
import io.ktor.features.NotFoundException
|
||||
import io.ktor.http.HttpStatusCode
|
||||
@@ -21,7 +21,7 @@ import io.ktor.routing.Route
|
||||
import java.util.UUID
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
object VoteConstitution {
|
||||
object PutVoteOnConstitution {
|
||||
@Location("/constitutions/{constitution}/vote")
|
||||
class ConstitutionVoteRequest(constitution: UUID) {
|
||||
val constitution = ConstitutionRef(constitution)
|
||||
@@ -4,7 +4,7 @@ import fr.dcproject.component.vote.routes.GetCitizenVotes.getCitizenVote
|
||||
import fr.dcproject.component.vote.routes.GetCitizenVotesOnArticle.getCitizenVotesOnArticle
|
||||
import fr.dcproject.component.vote.routes.PutVoteOnArticle.putVoteOnArticle
|
||||
import fr.dcproject.component.vote.routes.PutVoteOnComment.putVoteOnComment
|
||||
import fr.dcproject.component.vote.routes.VoteConstitution.voteConstitution
|
||||
import fr.dcproject.component.vote.routes.PutVoteOnConstitution.voteConstitution
|
||||
import io.ktor.auth.authenticate
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.routing.Routing
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package fr.dcproject.component.vote.routes
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.component.vote.database.VoteForView
|
||||
import fr.dcproject.component.vote.entity.VoteAggregation
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
|
||||
fun VoteForView<*>.toOutput(): Any = this.let { v ->
|
||||
object {
|
||||
val id: UUID = v.id
|
||||
val note: Int = v.note
|
||||
val createdAt: DateTime = v.createdAt
|
||||
val createdBy: Any = v.createdBy.toOutput()
|
||||
val target: Any = object {
|
||||
val id: UUID = v.target.id
|
||||
val reference: String = v.target.reference
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun VoteAggregation.toOutput(): Any = this.let { v ->
|
||||
object {
|
||||
val up: Int = v.up
|
||||
val neutral: Int = v.neutral
|
||||
val down: Int = v.down
|
||||
val total: Int = v.total
|
||||
val score: Int = v.score
|
||||
val updatedAt: DateTime = v.updatedAt
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user