create comment.toOutput()

This commit is contained in:
2021-03-20 01:57:10 +01:00
parent 8aa809c37e
commit 786b0bc949
19 changed files with 94 additions and 316 deletions

View File

@@ -1,6 +1,6 @@
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

View File

@@ -1,6 +1,5 @@
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

View File

@@ -1,6 +1,6 @@
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.component.auth.citizenOrNull
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.generic.CommentAccessControl
import fr.dcproject.component.comment.generic.database.CommentForUpdate
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.locations.KtorExperimentalLocationsAPI
@@ -17,7 +18,6 @@ import io.ktor.locations.Location
import io.ktor.locations.post
import io.ktor.response.respond
import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID
@KtorExperimentalLocationsAPI
@@ -39,35 +39,10 @@ object CreateCommentArticle {
}.let { comment ->
ac.assert { canCreate(comment, citizenOrNull) }
repo.comment(comment)
call.respond(
HttpStatusCode.Created,
object {
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
}
}
comment.toOutput()
)
}
}

View File

@@ -1,12 +1,12 @@
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
import fr.dcproject.component.comment.article.database.CommentArticleRepository
import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.toOutput
import fr.dcproject.routes.PaginatedRequest
import fr.dcproject.routes.PaginatedRequestI
import io.ktor.application.call
@@ -16,7 +16,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
@@ -42,35 +41,7 @@ object GetArticleComments {
call.respond(
HttpStatusCode.OK,
comments.toOutput { comment ->
object {
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
}
}
}
comment.toOutput()
}
)
}

View File

@@ -1,12 +1,12 @@
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
import fr.dcproject.component.comment.article.database.CommentArticleRepository
import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.locations.KtorExperimentalLocationsAPI
@@ -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
@@ -31,35 +30,7 @@ object GetCitizenArticleComments {
call.respond(
HttpStatusCode.OK,
comments.toOutput { comment ->
object {
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
}
}
}
comment.toOutput()
}
)
}

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.generic.CommentAccessControl
import fr.dcproject.component.comment.generic.database.CommentForUpdate
import fr.dcproject.component.comment.toOutput
import fr.dcproject.component.constitution.database.ConstitutionRef
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
@@ -17,7 +18,6 @@ import io.ktor.locations.Location
import io.ktor.locations.post
import io.ktor.response.respond
import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID
@KtorExperimentalLocationsAPI
@@ -42,33 +42,7 @@ object CreateConstitutionComment {
call.respond(
HttpStatusCode.Created,
object {
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
}
}
comment.toOutput()
)
}
}

View File

@@ -1,12 +1,12 @@
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
import fr.dcproject.component.comment.constitution.database.CommentConstitutionRepository
import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.locations.KtorExperimentalLocationsAPI
@@ -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
@@ -31,35 +30,7 @@ object GetCitizenCommentConstitution {
call.respond(
HttpStatusCode.OK,
comments.toOutput { comment ->
object {
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
}
}
}
comment.toOutput()
}
)
}

View File

@@ -1,11 +1,11 @@
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
import fr.dcproject.component.comment.generic.CommentAccessControl
import fr.dcproject.component.comment.toOutput
import fr.dcproject.component.constitution.database.ConstitutionRef
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
@@ -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
@@ -31,35 +30,7 @@ object GetConstitutionComment {
call.respond(
HttpStatusCode.OK,
comments.toOutput { comment ->
object {
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
}
}
}
comment.toOutput()
}
)
}

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.CommentRef
import fr.dcproject.component.comment.generic.database.CommentRepository
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call
import io.ktor.features.NotFoundException
import io.ktor.http.HttpStatusCode
@@ -38,7 +39,7 @@ object CreateCommentChildren {
ac.assert { canCreate(newComment, citizenOrNull) }
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.database.CommentRef
import fr.dcproject.component.comment.generic.database.CommentRepository
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call
import io.ktor.features.NotFoundException
import io.ktor.http.HttpStatusCode
@@ -15,7 +16,6 @@ import io.ktor.locations.Location
import io.ktor.locations.put
import io.ktor.response.respond
import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.UUID
@KtorExperimentalLocationsAPI
@@ -36,35 +36,7 @@ object EditComment {
call.respond(
HttpStatusCode.OK,
object {
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
}
}
}
comment.toOutput()
)
}
}

View File

@@ -1,11 +1,11 @@
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
import fr.dcproject.component.comment.generic.database.CommentRepository
import fr.dcproject.component.comment.toOutput
import fr.dcproject.routes.PaginatedRequest
import fr.dcproject.routes.PaginatedRequestI
import io.ktor.application.call
@@ -15,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
@@ -42,35 +41,7 @@ object GetCommentChildren {
call.respond(
HttpStatusCode.OK,
comments.toOutput { comment ->
object {
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
}
}
}
comment.toOutput()
}
)
}

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.database.CommentRef
import fr.dcproject.component.comment.generic.database.CommentRepository
import fr.dcproject.component.comment.toOutput
import io.ktor.application.call
import io.ktor.features.NotFoundException
import io.ktor.http.HttpStatusCode
@@ -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
@@ -31,35 +31,7 @@ object GetOneComment {
call.respond(
HttpStatusCode.OK,
object {
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
}
}
}
comment.toOutput()
)
}
}

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
import fr.dcproject.common.dto.toOutput
import fr.dcproject.common.response.toOutput
import fr.dcproject.common.security.assert
import fr.dcproject.component.auth.citizenOrNull