Files
dc-project/src/main/resources/sql/functions/comment/comment.sql
Fabrice Lecomte 8223dd21bb Add validation on route CreateComments & EditComment
rename POST /comments/{comment}/children
method edit and create comment of repository return edited/created comment
2021-04-10 01:16:09 +02:00

25 lines
1.0 KiB
PL/PgSQL

create or replace function comment(reference regclass, inout resource json)
language plpgsql as
$$
declare
_created_by_id uuid = resource#>>'{created_by,id}';
_target_id uuid = resource#>>'{target,id}';
_content text = resource#>>'{content}';
_parent_comment_id uuid = resource#>>'{parent,id}';
_new_id uuid = coalesce((resource->>'id')::uuid, uuid_generate_v4());
begin
if reference = 'article'::regclass then
insert into comment_on_article (id, created_by_id, target_id, content, parent_comment_id)
values (_new_id, _created_by_id, _target_id, _content, _parent_comment_id);
elseif reference = 'constitution'::regclass then
insert into comment_on_constitution (id, created_by_id, target_id, content, parent_comment_id)
values (_new_id, _created_by_id, _target_id, _content, _parent_comment_id);
else
raise exception 'comment with target as "%", is not implemented', reference::text;
end if;
select find_comment_by_id(_new_id) into resource;
end;
$$;