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 content: String,
|
||||||
var responses: List<Comment<T>>? = null,
|
var responses: List<Comment<T>>? = null,
|
||||||
var parent: 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),
|
): Extra<T>(id, createdBy),
|
||||||
EntityUpdatedAt by EntityUpdatedAtImp(),
|
EntityUpdatedAt by EntityUpdatedAtImp(),
|
||||||
EntityDeletedAt by EntityDeletedAtImp()
|
EntityDeletedAt by EntityDeletedAtImp()
|
||||||
|
|||||||
@@ -19,6 +19,17 @@ import fr.dcproject.repository.CommentGeneric as CommentRepository
|
|||||||
object CommentPaths {
|
object CommentPaths {
|
||||||
// TODO: change UUID by entity converter
|
// TODO: change UUID by entity converter
|
||||||
@Location("/comments/{comment}") class CommentRequest(val comment: UUID)
|
@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
|
@KtorExperimentalLocationsAPI
|
||||||
@@ -30,6 +41,19 @@ fun Route.comment(repo: CommentRepository) {
|
|||||||
call.respond(HttpStatusCode.OK, comment)
|
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> {
|
put<CommentPaths.CommentRequest> {
|
||||||
val comment = repo.findById(it.comment)!!
|
val comment = repo.findById(it.comment)!!
|
||||||
assertCan(UPDATE,comment)
|
assertCan(UPDATE,comment)
|
||||||
|
|||||||
@@ -257,8 +257,17 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/ConstitutionResponse'
|
$ref: '#/components/schemas/ConstitutionResponse'
|
||||||
/comments/{comment}:
|
/comments/{comment}:
|
||||||
|
parameters:
|
||||||
|
- name: comment
|
||||||
|
in: path
|
||||||
|
description: The ID of comment
|
||||||
|
example: 701dc504-db49-7e3a-2c0a-32542507ea57
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
get:
|
get:
|
||||||
summary: Get Comment and children by Comment ID
|
summary: Get Comment by Comment ID
|
||||||
tags:
|
tags:
|
||||||
- comment
|
- comment
|
||||||
responses:
|
responses:
|
||||||
@@ -286,6 +295,36 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/CommentResponse'
|
$ref: '#/components/schemas/CommentResponse'
|
||||||
|
|
||||||
|
/comments/{comment}/children:
|
||||||
|
parameters:
|
||||||
|
- name: comment
|
||||||
|
in: path
|
||||||
|
description: The ID of comment
|
||||||
|
example: 701dc504-db49-7e3a-2c0a-32542507ea57
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
get:
|
||||||
|
summary: Get Comment children by Comment ID
|
||||||
|
tags:
|
||||||
|
- comment
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Return Comment children
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/components/schemas/Paginated'
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
result:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/CommentResponse'
|
||||||
|
|
||||||
/articles/{article}/comments:
|
/articles/{article}/comments:
|
||||||
parameters:
|
parameters:
|
||||||
- name: article
|
- name: article
|
||||||
@@ -297,7 +336,7 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
get:
|
get:
|
||||||
summary: Get comment and children of one article
|
summary: Get comments of one article
|
||||||
tags:
|
tags:
|
||||||
- comment
|
- comment
|
||||||
responses:
|
responses:
|
||||||
@@ -547,7 +586,7 @@ components:
|
|||||||
CreatedBy:
|
CreatedBy:
|
||||||
properties:
|
properties:
|
||||||
created_by:
|
created_by:
|
||||||
$ref: '#/components/schemas/UuidEntity'
|
$ref: '#/components/schemas/CitizenResponse'
|
||||||
|
|
||||||
CreatedAt:
|
CreatedAt:
|
||||||
properties:
|
properties:
|
||||||
|
|||||||
@@ -7,16 +7,17 @@ create or replace function find_comments_by_parent(
|
|||||||
) language plpgsql as
|
) language plpgsql as
|
||||||
$$
|
$$
|
||||||
begin
|
begin
|
||||||
select json_agg(t), (select count(id) from "comment" com where com.parents_ids @> array[_parent_id])
|
select json_agg(t), (select count(id) from "comment" c3 where c3.parent_id = _parent_id)
|
||||||
into resource, total
|
into resource, total
|
||||||
from (
|
from (
|
||||||
select
|
select
|
||||||
com.*,
|
com.*,
|
||||||
|
(select count(*) from "comment" c2 where c2.parents_ids @> array[com.id]) as children_count,
|
||||||
find_reference_by_id(com.target_id, com.target_reference) as target,
|
find_reference_by_id(com.target_id, com.target_reference) as target,
|
||||||
find_citizen_by_id(com.created_by_id) as created_by
|
find_citizen_by_id(com.created_by_id) as created_by
|
||||||
from "comment" as com
|
from "comment" as com
|
||||||
where parent_id = _parent_id
|
where parent_id = _parent_id
|
||||||
order by com.parents_ids nulls first, created_at desc,
|
order by created_at desc,
|
||||||
com.created_at desc
|
com.created_at desc
|
||||||
limit "limit" offset "offset"
|
limit "limit" offset "offset"
|
||||||
) as t;
|
) as t;
|
||||||
|
|||||||
@@ -7,16 +7,17 @@ create or replace function find_comments_by_target(
|
|||||||
) language plpgsql as
|
) language plpgsql as
|
||||||
$$
|
$$
|
||||||
begin
|
begin
|
||||||
select json_agg(t), (select count(id) from "comment" com where com.target_id = _target_id)
|
select json_agg(t), (select count(id) from "comment" c3 where c3.parent_id = _target_id)
|
||||||
into resource, total
|
into resource, total
|
||||||
from (
|
from (
|
||||||
select
|
select
|
||||||
com.*,
|
com.*,
|
||||||
|
(select count(*) from "comment" c2 where c2.parents_ids @> array[com.id]) as children_count,
|
||||||
find_reference_by_id(com.target_id, com.target_reference) as target,
|
find_reference_by_id(com.target_id, com.target_reference) as target,
|
||||||
find_citizen_by_id(com.created_by_id) as created_by
|
find_citizen_by_id(com.created_by_id) as created_by
|
||||||
from "comment" as com
|
from "comment" as com
|
||||||
where com.target_id = _target_id
|
where com.parent_id = _target_id
|
||||||
order by com.parents_ids nulls first, created_at desc,
|
order by created_at desc,
|
||||||
com.created_at desc
|
com.created_at desc
|
||||||
limit "limit" offset "offset"
|
limit "limit" offset "offset"
|
||||||
) as t;
|
) as t;
|
||||||
|
|||||||
Reference in New Issue
Block a user