Big refactoring #77

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

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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
}
}
)
}
}
}

View File

@@ -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: