diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt index 2b24f80..b2e2bed 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/article/GetFollowArticle.kt @@ -7,6 +7,7 @@ import fr.dcproject.component.auth.citizen import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.follow.FollowAccessControl import fr.dcproject.component.follow.database.FollowArticleRepository +import fr.dcproject.component.follow.routes.citizen.toOutput import io.ktor.application.call import io.ktor.http.HttpStatusCode import io.ktor.locations.KtorExperimentalLocationsAPI @@ -14,7 +15,6 @@ 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 @@ -30,19 +30,7 @@ object GetFollowArticle { ac.assert { canView(follow, citizenOrNull) } call.respond( HttpStatusCode.OK, - follow.let { f -> - object { - val id: UUID = f.id - val createdBy: Any = f.createdBy.toOutput() - val target: Any = f.target.let { t -> - object { - val id: UUID = t.id - val reference: String = f.target.reference - } - } - val createdAt: DateTime = f.createdAt - } - } + follow.toOutput() ) } ?: call.respond(HttpStatusCode.NoContent) } diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetFollowCitizen.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetFollowCitizen.kt index bd5d075..b41a18d 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetFollowCitizen.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/GetFollowCitizen.kt @@ -14,7 +14,6 @@ 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 @@ -30,19 +29,7 @@ object GetFollowCitizen { ac.assert { canView(follow, citizenOrNull) } call.respond( HttpStatusCode.OK, - follow.let { f -> - object { - val id: UUID = f.id - val createdBy: Any = f.createdBy.toOutput() - val target: Any = f.target.let { t -> - object { - val id: UUID = t.id - val reference: String = f.target.reference - } - } - val createdAt: DateTime = f.createdAt - } - } + follow.toOutput() ) } ?: call.respond(HttpStatusCode.NoContent) } diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/response.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/response.kt new file mode 100644 index 0000000..87e72f1 --- /dev/null +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/citizen/response.kt @@ -0,0 +1,20 @@ +package fr.dcproject.component.follow.routes.citizen + +import fr.dcproject.common.response.toOutput +import fr.dcproject.component.follow.database.FollowForView +import org.joda.time.DateTime +import java.util.UUID + +fun FollowForView<*>.toOutput(): Any = this.let { f -> + object { + val id: UUID = f.id + val createdBy: Any = f.createdBy.toOutput() + val target: Any = f.target.let { t -> + object { + val id: UUID = t.id + val reference: String = f.target.reference + } + } + val createdAt: DateTime = f.createdAt + } +} diff --git a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetFollowConstitution.kt b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetFollowConstitution.kt index a2d7568..3908e5d 100644 --- a/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetFollowConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/follow/routes/constitution/GetFollowConstitution.kt @@ -7,6 +7,7 @@ import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.constitution.database.ConstitutionRef import fr.dcproject.component.follow.FollowAccessControl import fr.dcproject.component.follow.database.FollowConstitutionRepository +import fr.dcproject.component.follow.routes.citizen.toOutput import io.ktor.application.call import io.ktor.http.HttpStatusCode import io.ktor.locations.KtorExperimentalLocationsAPI @@ -14,7 +15,6 @@ 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 @@ -30,19 +30,7 @@ object GetFollowConstitution { ac.assert { canView(follow, citizenOrNull) } call.respond( HttpStatusCode.OK, - follow.let { f -> - object { - val id: UUID = f.id - val createdBy: Any = f.createdBy.toOutput() - val target: Any = f.target.let { t -> - object { - val id: UUID = t.id - val reference: String = f.target.reference - } - } - val createdAt: DateTime = f.createdAt - } - } + follow.toOutput() ) } ?: call.respond(HttpStatusCode.NotFound) }