#71 Use response object for route FindArticles
This commit is contained in:
13
src/main/kotlin/fr/dcproject/common/dto/CreatedBy.kt
Normal file
13
src/main/kotlin/fr/dcproject/common/dto/CreatedBy.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package fr.dcproject.common.dto
|
||||
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import java.util.UUID
|
||||
import fr.dcproject.common.entity.CreatedBy as EntityCreatedBy
|
||||
|
||||
interface CreatedBy {
|
||||
val createdBy: UUID
|
||||
|
||||
class Imp(parent: EntityCreatedBy<CitizenI>) : CreatedBy {
|
||||
override val createdBy: UUID = parent.createdBy.id
|
||||
}
|
||||
}
|
||||
16
src/main/kotlin/fr/dcproject/common/dto/Paginated.kt
Normal file
16
src/main/kotlin/fr/dcproject/common/dto/Paginated.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
package fr.dcproject.common.dto
|
||||
|
||||
import fr.dcproject.common.entity.EntityI
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
|
||||
fun <E : EntityI> Paginated<E>.toOutput(setup: (E) -> Any): Any {
|
||||
return object {
|
||||
val count = this@toOutput.count
|
||||
val currentPage = this@toOutput.count
|
||||
val limit = this@toOutput.limit
|
||||
val offset = this@toOutput.offset
|
||||
val total = this@toOutput.total
|
||||
val totalPages = this@toOutput.totalPages
|
||||
val result = this@toOutput.result.map { setup(it) }
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,8 @@ import fr.dcproject.common.entity.TargetI
|
||||
import fr.dcproject.common.entity.TargetRef
|
||||
import fr.dcproject.common.entity.Versionable
|
||||
import fr.dcproject.common.entity.VersionableId
|
||||
import fr.dcproject.component.citizen.database.CitizenCart
|
||||
import fr.dcproject.component.citizen.database.CitizenCartI
|
||||
import fr.dcproject.component.citizen.database.CitizenCreator
|
||||
import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.citizen.database.CitizenRef
|
||||
import fr.dcproject.component.opinion.entity.Opinionable
|
||||
@@ -78,7 +78,7 @@ class ArticleForUpdate(
|
||||
class ArticleForListing(
|
||||
id: UUID? = null,
|
||||
override val title: String,
|
||||
override val createdBy: CitizenCart,
|
||||
override val createdBy: CitizenCreator,
|
||||
override val workgroup: WorkgroupCart?,
|
||||
override val deletedAt: DateTime?,
|
||||
override val draft: Boolean
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.component.article.routes
|
||||
|
||||
import fr.dcproject.common.dto.toOutput
|
||||
import fr.dcproject.common.security.assert
|
||||
import fr.dcproject.component.article.ArticleAccessControl
|
||||
import fr.dcproject.component.article.database.ArticleForListing
|
||||
@@ -44,7 +45,33 @@ object FindArticles {
|
||||
get<ArticlesRequest> {
|
||||
repo.findArticles(it)
|
||||
.apply { ac.assert { canView(result, citizenOrNull) } }
|
||||
.let { call.respond(it) }
|
||||
.let {
|
||||
call.respond(
|
||||
it.toOutput {
|
||||
object {
|
||||
val id = it.id
|
||||
val title = it.title
|
||||
val createdBy = object {
|
||||
val id = it.createdBy.id
|
||||
val name = it.createdBy.name.let {
|
||||
object {
|
||||
val firstName = it.firstName
|
||||
val lastName = it.lastName
|
||||
}
|
||||
}
|
||||
val email = it.createdBy.email
|
||||
}
|
||||
val workgroup = it.workgroup?.let {
|
||||
object {
|
||||
val id = it.id
|
||||
val name = it.name
|
||||
}
|
||||
}
|
||||
val draft = it.draft
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user