Move Workgroup to a component
This commit is contained in:
26
src/main/kotlin/component/workgroup/routes/GetWorkgroup.kt
Normal file
26
src/main/kotlin/component/workgroup/routes/GetWorkgroup.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package fr.dcproject.component.workgroup.routes
|
||||
|
||||
import fr.dcproject.component.workgroup.WorkgroupRepository
|
||||
import fr.dcproject.security.voter.WorkgroupVoter
|
||||
import fr.ktorVoter.assertCan
|
||||
import io.ktor.application.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.locations.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
import java.util.*
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
object GetWorkgroup {
|
||||
@Location("/workgroups/{workgroupId}")
|
||||
class WorkgroupRequest(val workgroupId: UUID)
|
||||
|
||||
fun Route.getWorkgroup(repo: WorkgroupRepository) {
|
||||
get<WorkgroupRequest> {
|
||||
repo.findById(it.workgroupId)?.let { workgroup ->
|
||||
assertCan(WorkgroupVoter.Action.VIEW, workgroup)
|
||||
call.respond(workgroup)
|
||||
} ?: call.respond(HttpStatusCode.NotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user