Big refactoring #77
@@ -43,6 +43,7 @@ object CreateCommentArticle {
|
|||||||
object {
|
object {
|
||||||
val id: UUID = comment.id
|
val id: UUID = comment.id
|
||||||
val content: String = comment.content
|
val content: String = comment.content
|
||||||
|
val childrenCount: Int = 0
|
||||||
val createdAt: DateTime = comment.createdAt
|
val createdAt: DateTime = comment.createdAt
|
||||||
val parent: Any? = comment.parent?.let { p ->
|
val parent: Any? = comment.parent?.let { p ->
|
||||||
object {
|
object {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ object GetArticleComments {
|
|||||||
object {
|
object {
|
||||||
val id: UUID = comment.id
|
val id: UUID = comment.id
|
||||||
val content: String = comment.content
|
val content: String = comment.content
|
||||||
|
val childrenCount: Int = comment.childrenCount ?: 0
|
||||||
val createdAt: DateTime = comment.createdAt
|
val createdAt: DateTime = comment.createdAt
|
||||||
val parent: Any? = comment.parent?.let { p ->
|
val parent: Any? = comment.parent?.let { p ->
|
||||||
object {
|
object {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ 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
|
||||||
@@ -27,7 +28,50 @@ object GetOneComment {
|
|||||||
val comment = repo.findById(it.comment.id) ?: throw NotFoundException("Comment ${it.comment.id} not found")
|
val comment = repo.findById(it.comment.id) ?: throw NotFoundException("Comment ${it.comment.id} not found")
|
||||||
ac.assert { canView(comment, citizenOrNull) }
|
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'
|
$ref: '#/components/schemas/CommentResponse'
|
||||||
401:
|
401:
|
||||||
$ref: '#/components/responses/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:
|
components:
|
||||||
parameters:
|
parameters:
|
||||||
page:
|
page:
|
||||||
@@ -626,6 +639,16 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
format: uuid
|
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:
|
responses:
|
||||||
401:
|
401:
|
||||||
description: Unautorized
|
description: Unautorized
|
||||||
@@ -908,6 +931,7 @@ components:
|
|||||||
- createdBy
|
- createdBy
|
||||||
- votes
|
- votes
|
||||||
- target
|
- target
|
||||||
|
- childrenCount
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
$ref: '#/components/schemas/UUID'
|
$ref: '#/components/schemas/UUID'
|
||||||
@@ -934,6 +958,9 @@ components:
|
|||||||
$ref: '#/components/schemas/UUID'
|
$ref: '#/components/schemas/UUID'
|
||||||
reference:
|
reference:
|
||||||
type: string
|
type: string
|
||||||
|
childrenCount:
|
||||||
|
type: integer
|
||||||
|
minimum: 0
|
||||||
votes:
|
votes:
|
||||||
properties:
|
properties:
|
||||||
up:
|
up:
|
||||||
|
|||||||
Reference in New Issue
Block a user