Big refactoring #77
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
70
src/main/kotlin/fr/dcproject/component/comment/response.kt
Normal file
70
src/main/kotlin/fr/dcproject/component/comment/response.kt
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user