Test openapi schema of /constitutions/*

This commit is contained in:
2021-03-20 01:14:39 +01:00
parent c1a3590b2b
commit 4c1ab796e4
5 changed files with 347 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ import io.ktor.locations.Location
import io.ktor.locations.post
import io.ktor.response.respond
import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID
@KtorExperimentalLocationsAPI
@@ -110,6 +111,23 @@ object CreateConstitution {
val anonymous: Boolean = c.anonymous
val draft: Boolean = c.draft
val versionId: UUID = c.versionId
val createdAt: DateTime = c.createdAt
val createdBy: Any = c.createdBy.let { c ->
object {
val id: UUID = c.id
val name: Any = c.name.let { n ->
object {
val firstName: String = n.firstName
val lastName: String = n.lastName
}
}
val user: Any = c.user.let { u ->
object {
val username: String = u.username
}
}
}
}
}
)
}

View File

@@ -1,5 +1,6 @@
package fr.dcproject.component.constitution.routes
import fr.dcproject.common.dto.toOutput
import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.constitution.ConstitutionAccessControl
@@ -8,11 +9,14 @@ import fr.dcproject.routes.PaginatedRequest
import fr.dcproject.routes.PaginatedRequestI
import fr.postgresjson.repository.RepositoryI
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
import io.ktor.response.respond
import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID
@KtorExperimentalLocationsAPI
object FindConstitutions {
@@ -29,7 +33,33 @@ object FindConstitutions {
get<FindConstitutionsRequest> {
val constitutions = repo.find(it.page, it.limit, it.sort, it.direction, it.search)
ac.assert { canView(constitutions.result, citizenOrNull) }
call.respond(constitutions)
call.respond(
HttpStatusCode.OK,
constitutions.toOutput { c ->
object {
val id: UUID = c.id
val title: String = c.title
val versionId: UUID = c.versionId
val createdAt: DateTime = c.createdAt
val createdBy: Any = c.createdBy.let { c ->
object {
val id: UUID = c.id
val name: Any = c.name.let { n ->
object {
val firstName: String = n.firstName
val lastName: String = n.lastName
}
}
val user: Any = c.user.let { u ->
object {
val username: String = u.username
}
}
}
}
}
}
)
}
}
}

View File

@@ -7,11 +7,13 @@ import fr.dcproject.component.constitution.database.ConstitutionRef
import fr.dcproject.component.constitution.database.ConstitutionRepository
import io.ktor.application.call
import io.ktor.features.NotFoundException
import io.ktor.http.HttpStatusCode
import io.ktor.locations.KtorExperimentalLocationsAPI
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 java.util.UUID
@KtorExperimentalLocationsAPI
@@ -25,7 +27,68 @@ object GetConstitution {
get<GetConstitutionRequest> {
val constitution = constitutionRepo.findById(it.constitution.id) ?: throw NotFoundException("Unable to find constitution ${it.constitution.id}")
ac.assert { canView(constitution, citizenOrNull) }
call.respond(constitution)
call.respond(
HttpStatusCode.OK,
constitution.let { c ->
object {
val id: UUID = c.id
val title: String = c.title
val titles: List<Any> = c.titles.map { t ->
object {
val id: UUID = t.id
val name: String = t.name
val rank: Int = t.rank
val articles: List<Any> = t.articles.map { a ->
val id = a.id
val title = a.title
val createdBy = a.createdBy.let { cr ->
object {
val id: UUID = cr.id
val name: Any = cr.name.let { n ->
object {
val firstName: String = n.firstName
val lastName: String = n.lastName
}
}
val user: Any = cr.user.let { u ->
object {
val username: String = u.username
}
}
}
}
val workgroup: Any? = a.workgroup?.let { w ->
object {
val id = w.id
val name = w.name
}
}
}
}
}
val anonymous: Boolean = c.anonymous
val draft: Boolean = c.draft
val versionId: UUID = c.versionId
val createdAt: DateTime = c.createdAt
val createdBy: Any = c.createdBy.let { c ->
object {
val id: UUID = c.id
val name: Any = c.name.let { n ->
object {
val firstName: String = n.firstName
val lastName: String = n.lastName
}
}
val user: Any = c.user.let { u ->
object {
val username: String = u.username
}
}
}
}
}
}
)
}
}
}