diff --git a/src/main/kotlin/fr/dcproject/common/response/createdBy.kt b/src/main/kotlin/fr/dcproject/common/response/createdBy.kt new file mode 100644 index 0000000..9a1f3b0 --- /dev/null +++ b/src/main/kotlin/fr/dcproject/common/response/createdBy.kt @@ -0,0 +1,21 @@ +package fr.dcproject.common.response + +import fr.dcproject.component.citizen.database.CitizenCreatorI +import java.util.UUID + +fun CitizenCreatorI.toOutput(): Any = this.let { c -> + object { + val id: UUID = c.id + val name: Any = c.name.let { n -> + object { + val firstName: String = n.firstName + val lastName: String = n.lastName + } + } + val user: Any = c.user.let { u -> + object { + val username: String = u.username + } + } + } +} diff --git a/src/main/kotlin/fr/dcproject/component/article/routes/FindArticles.kt b/src/main/kotlin/fr/dcproject/component/article/routes/FindArticles.kt index cd0a1b9..8ada3c1 100644 --- a/src/main/kotlin/fr/dcproject/component/article/routes/FindArticles.kt +++ b/src/main/kotlin/fr/dcproject/component/article/routes/FindArticles.kt @@ -1,6 +1,7 @@ package fr.dcproject.component.article.routes import fr.dcproject.common.dto.toOutput +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.article.ArticleAccessControl import fr.dcproject.component.article.database.ArticleForListing @@ -16,7 +17,6 @@ import io.ktor.locations.Location import io.ktor.locations.get import io.ktor.response.respond import io.ktor.routing.Route -import java.util.UUID @KtorExperimentalLocationsAPI object FindArticles { @@ -52,22 +52,7 @@ object FindArticles { object { val id = it.id val title = it.title - val createdBy: Any = it.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = it.createdBy.toOutput() val workgroup = it.workgroup?.let { object { val id = it.id diff --git a/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt b/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt index 38f54a5..aabed2a 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt @@ -1,5 +1,6 @@ package fr.dcproject.component.comment.article.routes +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.common.utils.receiveOrBadRequest import fr.dcproject.component.article.database.ArticleRef @@ -58,22 +59,7 @@ object CreateCommentArticle { val reference: String = t.reference } } - val createdBy: Any = comment.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = comment.createdBy.toOutput() val votes: Any = object { val up: Int = 0 val neutral: Int = 0 diff --git a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt index caacbb8..952ccbe 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt @@ -1,6 +1,7 @@ package fr.dcproject.component.comment.article.routes import fr.dcproject.common.dto.toOutput +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.article.database.ArticleRef import fr.dcproject.component.auth.citizenOrNull @@ -59,22 +60,7 @@ object GetArticleComments { val reference: String = t.reference } } - val createdBy: Any = comment.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = comment.createdBy.toOutput() val votes: Any = comment.votes.let { v -> object { val up: Int = v.up diff --git a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt index 7439a1f..4c92845 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetCitizenArticleComments.kt @@ -1,6 +1,7 @@ package fr.dcproject.component.comment.article.routes import fr.dcproject.common.dto.toOutput +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.citizen.database.CitizenRef @@ -48,22 +49,7 @@ object GetCitizenArticleComments { val reference: String = t.reference } } - val createdBy: Any = comment.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = comment.createdBy.toOutput() val votes: Any = comment.votes.let { v -> object { val up: Int = v.up diff --git a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/CreateConstitutionComment.kt b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/CreateConstitutionComment.kt index 485d1ea..93d4d66 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/CreateConstitutionComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/CreateConstitutionComment.kt @@ -1,5 +1,6 @@ package fr.dcproject.component.comment.constitution.routes +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.common.utils.receiveOrBadRequest import fr.dcproject.component.auth.citizen @@ -59,22 +60,7 @@ object CreateConstitutionComment { val reference: String = t.reference } } - val createdBy: Any = comment.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = comment.createdBy.toOutput() val votes: Any = object { val up: Int = 0 val neutral: Int = 0 diff --git a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetCitizenCommentConstitution.kt b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetCitizenCommentConstitution.kt index 88690a0..b6d74ab 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetCitizenCommentConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetCitizenCommentConstitution.kt @@ -1,6 +1,7 @@ package fr.dcproject.component.comment.constitution.routes import fr.dcproject.common.dto.toOutput +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.citizen.database.CitizenRef @@ -48,22 +49,7 @@ object GetCitizenCommentConstitution { val reference: String = t.reference } } - val createdBy: Any = comment.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = comment.createdBy.toOutput() val votes: Any = comment.votes.let { v -> object { val up: Int = v.up diff --git a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetConstitutionComment.kt b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetConstitutionComment.kt index e5685e4..e92d3e8 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetConstitutionComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/constitution/routes/GetConstitutionComment.kt @@ -1,6 +1,7 @@ package fr.dcproject.component.comment.constitution.routes import fr.dcproject.common.dto.toOutput +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.comment.constitution.database.CommentConstitutionRepository @@ -48,22 +49,7 @@ object GetConstitutionComment { val reference: String = t.reference } } - val createdBy: Any = comment.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = comment.createdBy.toOutput() val votes: Any = comment.votes.let { v -> object { val up: Int = v.up diff --git a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/EditComment.kt b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/EditComment.kt index 2f2dc15..cd5b180 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/EditComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/EditComment.kt @@ -1,5 +1,6 @@ package fr.dcproject.component.comment.generic.routes +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.common.utils.receiveOrBadRequest import fr.dcproject.component.auth.citizenOrNull @@ -53,22 +54,7 @@ object EditComment { val reference: String = t.reference } } - val createdBy: Any = comment.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = comment.createdBy.toOutput() val votes: Any = comment.votes.let { v -> object { val up: Int = v.up diff --git a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetCommentChildren.kt b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetCommentChildren.kt index 7ee12c4..2f654f5 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetCommentChildren.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetCommentChildren.kt @@ -1,6 +1,7 @@ package fr.dcproject.component.comment.generic.routes import fr.dcproject.common.dto.toOutput +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.comment.generic.CommentAccessControl @@ -59,22 +60,7 @@ object GetCommentChildren { val reference: String = t.reference } } - val createdBy: Any = comment.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = comment.createdBy.toOutput() val votes: Any = comment.votes.let { v -> object { val up: Int = v.up diff --git a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt index 2fc5260..a1b664c 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt @@ -1,5 +1,6 @@ package fr.dcproject.component.comment.generic.routes +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.comment.generic.CommentAccessControl @@ -48,22 +49,7 @@ object GetOneComment { val reference: String = t.reference } } - val createdBy: Any = comment.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = comment.createdBy.toOutput() val votes: Any = comment.votes.let { v -> object { val up: Int = v.up diff --git a/src/main/kotlin/fr/dcproject/component/constitution/routes/CreateConstitution.kt b/src/main/kotlin/fr/dcproject/component/constitution/routes/CreateConstitution.kt index f0e4a43..6e4a7fb 100644 --- a/src/main/kotlin/fr/dcproject/component/constitution/routes/CreateConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/constitution/routes/CreateConstitution.kt @@ -1,5 +1,6 @@ package fr.dcproject.component.constitution.routes +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.common.utils.receiveOrBadRequest import fr.dcproject.component.article.database.ArticleRef @@ -83,22 +84,7 @@ object CreateConstitution { val articles: List = t.articles.map { a -> val id = a.id val title = a.title - val createdBy = a.createdBy.let { cr -> - object { - val id: UUID = cr.id - val name: Any = cr.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = cr.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy = a.createdBy.toOutput() val workgroup: Any? = a.workgroup?.let { w -> object { val id = w.id @@ -112,22 +98,7 @@ object CreateConstitution { val draft: Boolean = c.draft val versionId: UUID = c.versionId val createdAt: DateTime = c.createdAt - val createdBy: Any = c.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = c.createdBy.toOutput() } ) } diff --git a/src/main/kotlin/fr/dcproject/component/constitution/routes/FindConstitutions.kt b/src/main/kotlin/fr/dcproject/component/constitution/routes/FindConstitutions.kt index a19651a..8cfa782 100644 --- a/src/main/kotlin/fr/dcproject/component/constitution/routes/FindConstitutions.kt +++ b/src/main/kotlin/fr/dcproject/component/constitution/routes/FindConstitutions.kt @@ -1,6 +1,7 @@ package fr.dcproject.component.constitution.routes import fr.dcproject.common.dto.toOutput +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.constitution.ConstitutionAccessControl @@ -41,22 +42,7 @@ object FindConstitutions { val title: String = c.title val versionId: UUID = c.versionId val createdAt: DateTime = c.createdAt - val createdBy: Any = c.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = c.createdBy.toOutput() } } ) diff --git a/src/main/kotlin/fr/dcproject/component/constitution/routes/GetConstitution.kt b/src/main/kotlin/fr/dcproject/component/constitution/routes/GetConstitution.kt index 4da8944..64ea816 100644 --- a/src/main/kotlin/fr/dcproject/component/constitution/routes/GetConstitution.kt +++ b/src/main/kotlin/fr/dcproject/component/constitution/routes/GetConstitution.kt @@ -1,5 +1,6 @@ package fr.dcproject.component.constitution.routes +import fr.dcproject.common.response.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.constitution.ConstitutionAccessControl @@ -41,22 +42,7 @@ object GetConstitution { val articles: List = t.articles.map { a -> val id = a.id val title = a.title - val createdBy = a.createdBy.let { cr -> - object { - val id: UUID = cr.id - val name: Any = cr.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = cr.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy = a.createdBy.toOutput() val workgroup: Any? = a.workgroup?.let { w -> object { val id = w.id @@ -70,22 +56,7 @@ object GetConstitution { val draft: Boolean = c.draft val versionId: UUID = c.versionId val createdAt: DateTime = c.createdAt - val createdBy: Any = c.createdBy.let { c -> - object { - val id: UUID = c.id - val name: Any = c.name.let { n -> - object { - val firstName: String = n.firstName - val lastName: String = n.lastName - } - } - val user: Any = c.user.let { u -> - object { - val username: String = u.username - } - } - } - } + val createdBy: Any = c.createdBy.toOutput() } } )