can get comment children of an other comment
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user