Big refactoring #77

Merged
flecomte merged 166 commits from refactoring-component-and-immutable into master 2021-03-24 19:06:07 +01:00
19 changed files with 94 additions and 316 deletions
Showing only changes of commit 786b0bc949 - Show all commits

View File

@@ -1,12 +0,0 @@
package fr.dcproject.common.dto
import org.joda.time.DateTime
import fr.dcproject.common.entity.CreatedAt as EntityCreatedAt
interface CreatedAt {
val createdAt: DateTime
class Imp(parent: EntityCreatedAt) : CreatedAt {
override val createdAt: DateTime = parent.createdAt
}
}

View File

@@ -1,13 +0,0 @@
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
}
}

View File

@@ -1,14 +0,0 @@
package fr.dcproject.common.dto
import fr.dcproject.common.entity.Versionable as VersionableEntity
import java.util.UUID
interface Versionable {
val versionId: UUID
val versionNumber: Int
class Imp(parent: VersionableEntity) : Versionable {
override val versionNumber: Int = parent.versionNumber
override val versionId: UUID = parent.versionId
}
}

View File

@@ -1,4 +1,4 @@
package fr.dcproject.common.dto package fr.dcproject.common.response
import fr.dcproject.common.entity.EntityI import fr.dcproject.common.entity.EntityI
import fr.postgresjson.connexion.Paginated import fr.postgresjson.connexion.Paginated

View File

@@ -1,6 +1,6 @@
package fr.dcproject.component.article.routes 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.common.security.assert
import fr.dcproject.component.article.ArticleAccessControl import fr.dcproject.component.article.ArticleAccessControl
import fr.dcproject.component.article.database.ArticleForListing import fr.dcproject.component.article.database.ArticleForListing

View File

@@ -1,6 +1,5 @@
package fr.dcproject.component.article.routes package fr.dcproject.component.article.routes
import fr.dcproject.common.dto.toOutput
import fr.dcproject.common.response.toOutput import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.article.ArticleAccessControl import fr.dcproject.component.article.ArticleAccessControl

View File

@@ -1,6 +1,6 @@
package fr.dcproject.component.citizen.routes package fr.dcproject.component.citizen.routes
import fr.dcproject.common.dto.toOutput import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.citizen.CitizenAccessControl import fr.dcproject.component.citizen.CitizenAccessControl

View File

@@ -10,6 +10,7 @@ import fr.dcproject.component.comment.article.database.CommentArticleRepository
import fr.dcproject.component.comment.article.routes.CreateCommentArticle.PostArticleCommentRequest.Input import fr.dcproject.component.comment.article.routes.CreateCommentArticle.PostArticleCommentRequest.Input
import fr.dcproject.component.comment.generic.CommentAccessControl import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.generic.database.CommentForUpdate import fr.dcproject.component.comment.generic.database.CommentForUpdate
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call import io.ktor.application.call
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
import io.ktor.locations.KtorExperimentalLocationsAPI import io.ktor.locations.KtorExperimentalLocationsAPI
@@ -17,7 +18,6 @@ import io.ktor.locations.Location
import io.ktor.locations.post import io.ktor.locations.post
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -39,35 +39,10 @@ object CreateCommentArticle {
}.let { comment -> }.let { comment ->
ac.assert { canCreate(comment, citizenOrNull) } ac.assert { canCreate(comment, citizenOrNull) }
repo.comment(comment) repo.comment(comment)
call.respond( call.respond(
HttpStatusCode.Created, HttpStatusCode.Created,
object { comment.toOutput()
val id: UUID = comment.id
val content: String = comment.content
val childrenCount: Int = 0
val createdAt: DateTime = comment.createdAt
val updatedAt: DateTime = comment.createdAt
val parent: Any? = comment.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = comment.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = comment.createdBy.toOutput()
val votes: Any = object {
val up: Int = 0
val neutral: Int = 0
val down: Int = 0
val total: Int = 0
val score: Int = 0
}
}
) )
} }
} }

View File

@@ -1,12 +1,12 @@
package fr.dcproject.component.comment.article.routes package fr.dcproject.component.comment.article.routes
import fr.dcproject.common.dto.toOutput
import fr.dcproject.common.response.toOutput import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.article.database.ArticleRef import fr.dcproject.component.article.database.ArticleRef
import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.comment.article.database.CommentArticleRepository import fr.dcproject.component.comment.article.database.CommentArticleRepository
import fr.dcproject.component.comment.generic.CommentAccessControl import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.toOutput
import fr.dcproject.routes.PaginatedRequest import fr.dcproject.routes.PaginatedRequest
import fr.dcproject.routes.PaginatedRequestI import fr.dcproject.routes.PaginatedRequestI
import io.ktor.application.call import io.ktor.application.call
@@ -16,7 +16,6 @@ import io.ktor.locations.Location
import io.ktor.locations.get import io.ktor.locations.get
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -42,35 +41,7 @@ object GetArticleComments {
call.respond( call.respond(
HttpStatusCode.OK, HttpStatusCode.OK,
comments.toOutput { comment -> comments.toOutput { comment ->
object { comment.toOutput()
val id: UUID = comment.id
val content: String = comment.content
val childrenCount: Int = comment.childrenCount ?: 0
val createdAt: DateTime = comment.createdAt
val updatedAt: DateTime = comment.updatedAt
val parent: Any? = comment.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = comment.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = comment.createdBy.toOutput()
val votes: Any = comment.votes.let { v ->
object {
val up: Int = v.up
val neutral: Int = v.neutral
val down: Int = v.down
val total: Int = v.total
val score: Int = v.score
}
}
}
} }
) )
} }

View File

@@ -1,12 +1,12 @@
package fr.dcproject.component.comment.article.routes package fr.dcproject.component.comment.article.routes
import fr.dcproject.common.dto.toOutput
import fr.dcproject.common.response.toOutput import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.citizen.database.CitizenRef import fr.dcproject.component.citizen.database.CitizenRef
import fr.dcproject.component.comment.article.database.CommentArticleRepository import fr.dcproject.component.comment.article.database.CommentArticleRepository
import fr.dcproject.component.comment.generic.CommentAccessControl import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call import io.ktor.application.call
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
import io.ktor.locations.KtorExperimentalLocationsAPI import io.ktor.locations.KtorExperimentalLocationsAPI
@@ -14,7 +14,6 @@ import io.ktor.locations.Location
import io.ktor.locations.get import io.ktor.locations.get
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -31,35 +30,7 @@ object GetCitizenArticleComments {
call.respond( call.respond(
HttpStatusCode.OK, HttpStatusCode.OK,
comments.toOutput { comment -> comments.toOutput { comment ->
object { comment.toOutput()
val id: UUID = comment.id
val content: String = comment.content
val childrenCount: Int = comment.childrenCount ?: 0
val createdAt: DateTime = comment.createdAt
val updatedAt: DateTime = comment.updatedAt
val parent: Any? = comment.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = comment.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = comment.createdBy.toOutput()
val votes: Any = comment.votes.let { v ->
object {
val up: Int = v.up
val neutral: Int = v.neutral
val down: Int = v.down
val total: Int = v.total
val score: Int = v.score
}
}
}
} }
) )
} }

View File

@@ -9,6 +9,7 @@ import fr.dcproject.component.comment.constitution.database.CommentConstitutionR
import fr.dcproject.component.comment.constitution.routes.CreateConstitutionComment.CreateConstitutionCommentRequest.Input import fr.dcproject.component.comment.constitution.routes.CreateConstitutionComment.CreateConstitutionCommentRequest.Input
import fr.dcproject.component.comment.generic.CommentAccessControl import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.generic.database.CommentForUpdate import fr.dcproject.component.comment.generic.database.CommentForUpdate
import fr.dcproject.component.comment.toOutput
import fr.dcproject.component.constitution.database.ConstitutionRef import fr.dcproject.component.constitution.database.ConstitutionRef
import io.ktor.application.call import io.ktor.application.call
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
@@ -17,7 +18,6 @@ import io.ktor.locations.Location
import io.ktor.locations.post import io.ktor.locations.post
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -42,33 +42,7 @@ object CreateConstitutionComment {
call.respond( call.respond(
HttpStatusCode.Created, HttpStatusCode.Created,
object { comment.toOutput()
val id: UUID = comment.id
val content: String = comment.content
val childrenCount: Int = 0
val createdAt: DateTime = comment.createdAt
val updatedAt: DateTime = comment.createdAt
val parent: Any? = comment.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = comment.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = comment.createdBy.toOutput()
val votes: Any = object {
val up: Int = 0
val neutral: Int = 0
val down: Int = 0
val total: Int = 0
val score: Int = 0
}
}
) )
} }
} }

View File

@@ -1,12 +1,12 @@
package fr.dcproject.component.comment.constitution.routes package fr.dcproject.component.comment.constitution.routes
import fr.dcproject.common.dto.toOutput
import fr.dcproject.common.response.toOutput import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.citizen.database.CitizenRef import fr.dcproject.component.citizen.database.CitizenRef
import fr.dcproject.component.comment.constitution.database.CommentConstitutionRepository import fr.dcproject.component.comment.constitution.database.CommentConstitutionRepository
import fr.dcproject.component.comment.generic.CommentAccessControl import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call import io.ktor.application.call
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
import io.ktor.locations.KtorExperimentalLocationsAPI import io.ktor.locations.KtorExperimentalLocationsAPI
@@ -14,7 +14,6 @@ import io.ktor.locations.Location
import io.ktor.locations.get import io.ktor.locations.get
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -31,35 +30,7 @@ object GetCitizenCommentConstitution {
call.respond( call.respond(
HttpStatusCode.OK, HttpStatusCode.OK,
comments.toOutput { comment -> comments.toOutput { comment ->
object { comment.toOutput()
val id: UUID = comment.id
val content: String = comment.content
val childrenCount: Int = comment.childrenCount ?: 0
val createdAt: DateTime = comment.createdAt
val updatedAt: DateTime = comment.updatedAt
val parent: Any? = comment.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = comment.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = comment.createdBy.toOutput()
val votes: Any = comment.votes.let { v ->
object {
val up: Int = v.up
val neutral: Int = v.neutral
val down: Int = v.down
val total: Int = v.total
val score: Int = v.score
}
}
}
} }
) )
} }

View File

@@ -1,11 +1,11 @@
package fr.dcproject.component.comment.constitution.routes package fr.dcproject.component.comment.constitution.routes
import fr.dcproject.common.dto.toOutput
import fr.dcproject.common.response.toOutput import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.comment.constitution.database.CommentConstitutionRepository import fr.dcproject.component.comment.constitution.database.CommentConstitutionRepository
import fr.dcproject.component.comment.generic.CommentAccessControl import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.toOutput
import fr.dcproject.component.constitution.database.ConstitutionRef import fr.dcproject.component.constitution.database.ConstitutionRef
import io.ktor.application.call import io.ktor.application.call
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
@@ -14,7 +14,6 @@ import io.ktor.locations.Location
import io.ktor.locations.get import io.ktor.locations.get
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -31,35 +30,7 @@ object GetConstitutionComment {
call.respond( call.respond(
HttpStatusCode.OK, HttpStatusCode.OK,
comments.toOutput { comment -> comments.toOutput { comment ->
object { comment.toOutput()
val id: UUID = comment.id
val content: String = comment.content
val childrenCount: Int = comment.childrenCount ?: 0
val createdAt: DateTime = comment.createdAt
val updatedAt: DateTime = comment.updatedAt
val parent: Any? = comment.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = comment.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = comment.createdBy.toOutput()
val votes: Any = comment.votes.let { v ->
object {
val up: Int = v.up
val neutral: Int = v.neutral
val down: Int = v.down
val total: Int = v.total
val score: Int = v.score
}
}
}
} }
) )
} }

View File

@@ -8,6 +8,7 @@ import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.generic.database.CommentForUpdate import fr.dcproject.component.comment.generic.database.CommentForUpdate
import fr.dcproject.component.comment.generic.database.CommentRef import fr.dcproject.component.comment.generic.database.CommentRef
import fr.dcproject.component.comment.generic.database.CommentRepository import fr.dcproject.component.comment.generic.database.CommentRepository
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call import io.ktor.application.call
import io.ktor.features.NotFoundException import io.ktor.features.NotFoundException
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
@@ -38,7 +39,7 @@ object CreateCommentChildren {
ac.assert { canCreate(newComment, citizenOrNull) } ac.assert { canCreate(newComment, citizenOrNull) }
repo.comment(newComment) repo.comment(newComment)
call.respond(HttpStatusCode.Created, newComment) call.respond(HttpStatusCode.Created, newComment.toOutput())
} }
} }
} }

View File

@@ -7,6 +7,7 @@ import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.comment.generic.CommentAccessControl import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.generic.database.CommentRef import fr.dcproject.component.comment.generic.database.CommentRef
import fr.dcproject.component.comment.generic.database.CommentRepository import fr.dcproject.component.comment.generic.database.CommentRepository
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call import io.ktor.application.call
import io.ktor.features.NotFoundException import io.ktor.features.NotFoundException
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
@@ -15,7 +16,6 @@ import io.ktor.locations.Location
import io.ktor.locations.put import io.ktor.locations.put
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -36,35 +36,7 @@ object EditComment {
call.respond( call.respond(
HttpStatusCode.OK, HttpStatusCode.OK,
object { comment.toOutput()
val id: UUID = comment.id
val content: String = comment.content
val childrenCount: Int = comment.childrenCount ?: 0
val createdAt: DateTime = comment.createdAt
val updatedAt: DateTime = comment.updatedAt
val parent: Any? = comment.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = comment.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = comment.createdBy.toOutput()
val votes: Any = comment.votes.let { v ->
object {
val up: Int = v.up
val neutral: Int = v.neutral
val down: Int = v.down
val total: Int = v.total
val score: Int = v.score
}
}
}
) )
} }
} }

View File

@@ -1,11 +1,11 @@
package fr.dcproject.component.comment.generic.routes package fr.dcproject.component.comment.generic.routes
import fr.dcproject.common.dto.toOutput
import fr.dcproject.common.response.toOutput import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.comment.generic.CommentAccessControl import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.generic.database.CommentRepository import fr.dcproject.component.comment.generic.database.CommentRepository
import fr.dcproject.component.comment.toOutput
import fr.dcproject.routes.PaginatedRequest import fr.dcproject.routes.PaginatedRequest
import fr.dcproject.routes.PaginatedRequestI import fr.dcproject.routes.PaginatedRequestI
import io.ktor.application.call import io.ktor.application.call
@@ -15,7 +15,6 @@ import io.ktor.locations.Location
import io.ktor.locations.get import io.ktor.locations.get
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -42,35 +41,7 @@ object GetCommentChildren {
call.respond( call.respond(
HttpStatusCode.OK, HttpStatusCode.OK,
comments.toOutput { comment -> comments.toOutput { comment ->
object { comment.toOutput()
val id: UUID = comment.id
val content: String = comment.content
val childrenCount: Int = comment.childrenCount ?: 0
val createdAt: DateTime = comment.createdAt
val updatedAt: DateTime = comment.updatedAt
val parent: Any? = comment.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = comment.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = comment.createdBy.toOutput()
val votes: Any = comment.votes.let { v ->
object {
val up: Int = v.up
val neutral: Int = v.neutral
val down: Int = v.down
val total: Int = v.total
val score: Int = v.score
}
}
}
} }
) )
} }

View File

@@ -6,6 +6,7 @@ import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.comment.generic.CommentAccessControl import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.generic.database.CommentRef import fr.dcproject.component.comment.generic.database.CommentRef
import fr.dcproject.component.comment.generic.database.CommentRepository import fr.dcproject.component.comment.generic.database.CommentRepository
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call import io.ktor.application.call
import io.ktor.features.NotFoundException import io.ktor.features.NotFoundException
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
@@ -14,7 +15,6 @@ import io.ktor.locations.Location
import io.ktor.locations.get import io.ktor.locations.get
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID import java.util.UUID
@KtorExperimentalLocationsAPI @KtorExperimentalLocationsAPI
@@ -31,35 +31,7 @@ object GetOneComment {
call.respond( call.respond(
HttpStatusCode.OK, HttpStatusCode.OK,
object { comment.toOutput()
val id: UUID = comment.id
val content: String = comment.content
val childrenCount: Int = comment.childrenCount ?: 0
val createdAt: DateTime = comment.createdAt
val updatedAt: DateTime = comment.updatedAt
val parent: Any? = comment.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = comment.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = comment.createdBy.toOutput()
val votes: Any = comment.votes.let { v ->
object {
val up: Int = v.up
val neutral: Int = v.neutral
val down: Int = v.down
val total: Int = v.total
val score: Int = v.score
}
}
}
) )
} }
} }

View File

@@ -0,0 +1,70 @@
package fr.dcproject.component.comment
import fr.dcproject.common.response.toOutput
import fr.dcproject.component.citizen.database.CitizenCreatorI
import fr.dcproject.component.comment.generic.database.CommentForUpdate
import fr.dcproject.component.comment.generic.database.CommentForView
import org.joda.time.DateTime
import java.util.UUID
fun CommentForView<*, *>.toOutput(): Any = this.let { c ->
object {
val id: UUID = c.id
val content: String = c.content
val childrenCount: Int = c.childrenCount ?: 0
val createdAt: DateTime = c.createdAt
val updatedAt: DateTime = c.updatedAt
val parent: Any? = c.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = c.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = c.createdBy.toOutput()
val votes: Any = c.votes.let { v ->
object {
val up: Int = v.up
val neutral: Int = v.neutral
val down: Int = v.down
val total: Int = v.total
val score: Int = v.score
}
}
}
}
fun <C : CitizenCreatorI> CommentForUpdate<*, C>.toOutput(): Any = this.let { c ->
object {
val id: UUID = c.id
val content: String = c.content
val childrenCount: Int = 0
val createdAt: DateTime = c.createdAt
val updatedAt: DateTime = c.createdAt
val parent: Any? = c.parent?.let { p ->
object {
val id: UUID = p.id
val reference: String = p.reference
}
}
val target: Any = c.target.let { t ->
object {
val id: UUID = t.id
val reference: String = t.reference
}
}
val createdBy: Any = c.createdBy.toOutput()
val votes: Any = object {
val up: Int = 0
val neutral: Int = 0
val down: Int = 0
val total: Int = 0
val score: Int = 0
}
}
}

View File

@@ -1,6 +1,5 @@
package fr.dcproject.component.constitution.routes package fr.dcproject.component.constitution.routes
import fr.dcproject.common.dto.toOutput
import fr.dcproject.common.response.toOutput import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.auth.citizenOrNull