#60 Can follow citizen #96
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user