Test openapi schema of route /workgroup/*
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.workgroup.routes
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.common.utils.receiveOrBadRequest
|
||||
import fr.dcproject.component.auth.citizen
|
||||
@@ -44,8 +45,11 @@ object CreateWorkgroup {
|
||||
}.let { workgroup ->
|
||||
ac.assert { canCreate(workgroup, citizenOrNull) }
|
||||
repo.upsert(workgroup)
|
||||
}.let {
|
||||
call.respond(HttpStatusCode.Created, it)
|
||||
}.let { w ->
|
||||
call.respond(
|
||||
HttpStatusCode.Created,
|
||||
w.toOutput()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ object EditWorkgroup {
|
||||
).let { workgroup ->
|
||||
ac.assert { canUpdate(workgroup, citizenOrNull) }
|
||||
repo.upsert(workgroup)
|
||||
call.respond(HttpStatusCode.OK, it)
|
||||
}.let {
|
||||
call.respond(HttpStatusCode.OK, it.toOutput())
|
||||
}
|
||||
}
|
||||
} ?: call.respond(HttpStatusCode.NotFound)
|
||||
|
||||
@@ -25,7 +25,10 @@ object GetWorkgroup {
|
||||
get<WorkgroupRequest> {
|
||||
repo.findById(it.workgroup.id)?.let { workgroup ->
|
||||
ac.assert { canView(workgroup, citizenOrNull) }
|
||||
call.respond(workgroup)
|
||||
call.respond(
|
||||
HttpStatusCode.OK,
|
||||
workgroup.toOutput()
|
||||
)
|
||||
} ?: call.respond(HttpStatusCode.NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.workgroup.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.workgroup.WorkgroupAccessControl
|
||||
import fr.dcproject.component.workgroup.database.WorkgroupRepository
|
||||
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
|
||||
@@ -43,7 +45,10 @@ object GetWorkgroups {
|
||||
WorkgroupRepository.Filter(createdById = it.createdBy, members = it.members)
|
||||
)
|
||||
ac.assert { canView(workgroups.result, citizenOrNull) }
|
||||
call.respond(workgroups)
|
||||
call.respond(
|
||||
HttpStatusCode.OK,
|
||||
workgroups.toOutput { it.toOutputListing() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package fr.dcproject.component.workgroup.routes
|
||||
|
||||
import fr.dcproject.common.response.toOutput
|
||||
import fr.dcproject.component.workgroup.database.WorkgroupForView
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
|
||||
fun WorkgroupForView<*>.toOutput(): Any = this.let { w ->
|
||||
object {
|
||||
val id: UUID = w.id
|
||||
val name: String = w.name
|
||||
val description: String = w.description
|
||||
val logo: String? = w.logo
|
||||
val anonymous: Boolean = w.anonymous
|
||||
val createdAt: DateTime = w.createdAt
|
||||
val createdBy: Any = w.createdBy.toOutput()
|
||||
val members: Any = w.members.map { m ->
|
||||
object {
|
||||
val citizen: Any = object {
|
||||
val id: UUID = m.citizen.id
|
||||
val name: Any = m.citizen.name.let { n ->
|
||||
object {
|
||||
val firstName: String = n.firstName
|
||||
val lastName: String = n.lastName
|
||||
}
|
||||
}
|
||||
}
|
||||
val roles: List<String> = m.roles.map { it.toString() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun WorkgroupForView<*>.toOutputListing(): Any = this.let { w ->
|
||||
object {
|
||||
val id: UUID = w.id
|
||||
val name: String = w.name
|
||||
val description: String = w.description
|
||||
val logo: String? = w.logo
|
||||
val createdAt: DateTime = w.createdAt
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user