From 5979337bc33e842f2b1cefc228eb264f2399123d Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Sat, 6 Feb 2021 01:06:46 +0100 Subject: [PATCH] Remove last converter for Workgroup --- src/main/kotlin/application/Converters.kt | 24 ------------------- .../opinion/routes/GetOpinionChoices.kt | 1 - .../workgroup/routes/GetWorkgroup.kt | 9 ++++--- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/application/Converters.kt b/src/main/kotlin/application/Converters.kt index 84752dc..a88ba3b 100644 --- a/src/main/kotlin/application/Converters.kt +++ b/src/main/kotlin/application/Converters.kt @@ -1,11 +1,6 @@ package fr.dcproject.application -import fr.dcproject.component.citizen.CitizenBasic -import fr.dcproject.component.workgroup.Workgroup -import fr.dcproject.component.workgroup.WorkgroupRef -import fr.dcproject.component.workgroup.WorkgroupRepository import io.ktor.features.DataConversion -import io.ktor.features.NotFoundException import io.ktor.util.KtorExperimentalAPI import org.koin.core.context.GlobalContext import org.koin.core.parameter.ParametersDefinition @@ -33,23 +28,4 @@ val converters: ConverterDeclaration = { } } } - - // TODO remove converters of entities - - convert { - decode { values, _ -> - values.singleOrNull()?.let { - WorkgroupRef(UUID.fromString(it)) - } ?: throw NotFoundException("""UUID "$values" is not valid for Workgroup""") - } - } - - convert> { - decode { values, _ -> - val id = values.singleOrNull()?.let { UUID.fromString(it) } - ?: throw InternalError("Cannot convert $values to UUID") - get().findById(id) - ?: throw NotFoundException("Workgroup $values not found") - } - } } diff --git a/src/main/kotlin/component/opinion/routes/GetOpinionChoices.kt b/src/main/kotlin/component/opinion/routes/GetOpinionChoices.kt index 3d1bc9b..85134c3 100644 --- a/src/main/kotlin/component/opinion/routes/GetOpinionChoices.kt +++ b/src/main/kotlin/component/opinion/routes/GetOpinionChoices.kt @@ -4,7 +4,6 @@ import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.opinion.OpinionChoiceAccessControl import fr.dcproject.component.opinion.OpinionChoiceRepository import fr.dcproject.security.assert -import fr.dcproject.utils.toUUID import io.ktor.application.call import io.ktor.locations.KtorExperimentalLocationsAPI import io.ktor.locations.Location diff --git a/src/main/kotlin/component/workgroup/routes/GetWorkgroup.kt b/src/main/kotlin/component/workgroup/routes/GetWorkgroup.kt index 6d770b4..5a786b7 100644 --- a/src/main/kotlin/component/workgroup/routes/GetWorkgroup.kt +++ b/src/main/kotlin/component/workgroup/routes/GetWorkgroup.kt @@ -2,6 +2,7 @@ package fr.dcproject.component.workgroup.routes import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.workgroup.WorkgroupAccessControl +import fr.dcproject.component.workgroup.WorkgroupRef import fr.dcproject.component.workgroup.WorkgroupRepository import fr.dcproject.security.assert import io.ktor.application.call @@ -15,12 +16,14 @@ import java.util.UUID @KtorExperimentalLocationsAPI object GetWorkgroup { - @Location("/workgroups/{workgroupId}") - class WorkgroupRequest(val workgroupId: UUID) + @Location("/workgroups/{workgroup}") + class WorkgroupRequest(workgroup: UUID) { + val workgroup = WorkgroupRef(workgroup) + } fun Route.getWorkgroup(repo: WorkgroupRepository, ac: WorkgroupAccessControl) { get { - repo.findById(it.workgroupId)?.let { workgroup -> + repo.findById(it.workgroup.id)?.let { workgroup -> ac.assert { canView(workgroup, citizenOrNull) } call.respond(workgroup) } ?: call.respond(HttpStatusCode.NotFound)