Test openapi schema of /comments/{comment}

This commit is contained in:
2021-03-17 18:09:05 +01:00
parent 07ae50c40a
commit ca402dbea7
4 changed files with 75 additions and 2 deletions

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