can get comment children of an other comment

This commit is contained in:
2019-09-22 23:54:53 +02:00
parent dc490dcac3
commit 3a77eff86e
5 changed files with 75 additions and 9 deletions

View File

@@ -10,7 +10,8 @@ open class Comment <T: UuidEntity> (
var content: String,
var responses: List<Comment<T>>? = null,
var parent: Comment<T>? = null,
var parentsIds: List<UUID>? = null
var parentsIds: List<UUID>? = null,
val childrenCount: Int? = null
): Extra<T>(id, createdBy),
EntityUpdatedAt by EntityUpdatedAtImp(),
EntityDeletedAt by EntityDeletedAtImp()

View File

@@ -19,6 +19,17 @@ import fr.dcproject.repository.CommentGeneric as CommentRepository
object CommentPaths {
// TODO: change UUID by entity converter
@Location("/comments/{comment}") class CommentRequest(val comment: UUID)
@Location("/comments/{comment}/children")
class CommentChildrenRequest(
val comment: UUID,
page: Int = 1,
limit: Int = 50,
val search: String? = null
) {
val page: Int = if (page < 1) 1 else page
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
}
}
@KtorExperimentalLocationsAPI
@@ -30,6 +41,19 @@ fun Route.comment(repo: CommentRepository) {
call.respond(HttpStatusCode.OK, comment)
}
get<CommentPaths.CommentChildrenRequest> {
val comments =
repo.findByParent(
it.comment,
it.page,
it.limit
)
assertCan(VIEW, comments.result)
call.respond(HttpStatusCode.OK, comments)
}
put<CommentPaths.CommentRequest> {
val comment = repo.findById(it.comment)!!
assertCan(UPDATE,comment)