Big refactoring #77
@@ -43,6 +43,7 @@ object CreateCommentArticle {
|
||||
object {
|
||||
val id: UUID = comment.id
|
||||
val content: String = comment.content
|
||||
val childrenCount: Int = 0
|
||||
val createdAt: DateTime = comment.createdAt
|
||||
val parent: Any? = comment.parent?.let { p ->
|
||||
object {
|
||||
|
||||
@@ -44,6 +44,7 @@ object GetArticleComments {
|
||||
object {
|
||||
val id: UUID = comment.id
|
||||
val content: String = comment.content
|
||||
val childrenCount: Int = comment.childrenCount ?: 0
|
||||
val createdAt: DateTime = comment.createdAt
|
||||
val parent: Any? = comment.parent?.let { p ->
|
||||
object {
|
||||
|
||||
@@ -13,6 +13,7 @@ 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
|
||||
@@ -27,7 +28,50 @@ object GetOneComment {
|
||||
val comment = repo.findById(it.comment.id) ?: throw NotFoundException("Comment ${it.comment.id} not found")
|
||||
ac.assert { canView(comment, citizenOrNull) }
|
||||
|
||||
call.respond(HttpStatusCode.OK, comment)
|
||||
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 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.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 votes: Any = object {
|
||||
val up: Int = 0
|
||||
val neutral: Int = 0
|
||||
val down: Int = 0
|
||||
val total: Int = 0
|
||||
val score: Int = 0
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,7 +533,20 @@ paths:
|
||||
$ref: '#/components/schemas/CommentResponse'
|
||||
401:
|
||||
$ref: '#/components/responses/401'
|
||||
|
||||
/comments/{comment}:
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/comment'
|
||||
get:
|
||||
summary: Get Comment by Comment ID
|
||||
tags:
|
||||
- comment
|
||||
responses:
|
||||
200:
|
||||
description: Return Comment and children
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CommentResponse'
|
||||
components:
|
||||
parameters:
|
||||
page:
|
||||
@@ -626,6 +639,16 @@ components:
|
||||
type: string
|
||||
format: uuid
|
||||
|
||||
comment:
|
||||
name: comment
|
||||
in: path
|
||||
description: The ID of comment
|
||||
example: 701dc504-db49-7e3a-2c0a-32542507ea57
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
|
||||
responses:
|
||||
401:
|
||||
description: Unautorized
|
||||
@@ -908,6 +931,7 @@ components:
|
||||
- createdBy
|
||||
- votes
|
||||
- target
|
||||
- childrenCount
|
||||
properties:
|
||||
id:
|
||||
$ref: '#/components/schemas/UUID'
|
||||
@@ -934,6 +958,9 @@ components:
|
||||
$ref: '#/components/schemas/UUID'
|
||||
reference:
|
||||
type: string
|
||||
childrenCount:
|
||||
type: integer
|
||||
minimum: 0
|
||||
votes:
|
||||
properties:
|
||||
up:
|
||||
|
||||
Reference in New Issue
Block a user