SQL functions find_comments_* now return VotesAggregates
create Votable Interface remove usless "resourceTarget" argument for SQL function "count_vote"
This commit is contained in:
@@ -8,7 +8,7 @@ begin
|
||||
select
|
||||
a.*,
|
||||
find_citizen_by_id(a.created_by_id) as created_by,
|
||||
count_vote('article', a.id) as votes
|
||||
count_vote(a.id) as votes
|
||||
into resource
|
||||
from article as a
|
||||
where a.id = _id
|
||||
|
||||
@@ -15,7 +15,7 @@ begin
|
||||
select
|
||||
a.*,
|
||||
find_citizen_by_id(a.created_by_id) as created_by,
|
||||
count_vote('article', a.id) as votes,
|
||||
count_vote(a.id) as votes,
|
||||
zdb.score(a.ctid) _score
|
||||
from article as a
|
||||
where (
|
||||
|
||||
@@ -15,7 +15,7 @@ begin
|
||||
select
|
||||
a.*,
|
||||
find_citizen_by_id(a.created_by_id) as created_by,
|
||||
count_vote('article', a.id) as votes
|
||||
count_vote(a.id) as votes
|
||||
from article as a
|
||||
where a.version_id = _version_id
|
||||
order by a.version_number desc
|
||||
|
||||
@@ -8,7 +8,7 @@ begin
|
||||
select
|
||||
a.*,
|
||||
find_citizen_by_id(a.created_by_id) as created_by,
|
||||
count_vote('article', a.id) as votes
|
||||
count_vote(a.id) as votes
|
||||
into resource
|
||||
from article as a
|
||||
where a.version_id = _version_id
|
||||
|
||||
@@ -10,7 +10,8 @@ begin
|
||||
select
|
||||
com.*,
|
||||
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,
|
||||
count_vote(com.id) as votes
|
||||
from "comment" as com
|
||||
where id = _id
|
||||
) as t;
|
||||
|
||||
@@ -21,7 +21,8 @@ begin
|
||||
select
|
||||
com.*,
|
||||
find_reference_by_id(com.target_id, _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,
|
||||
count_vote(com.id) as votes
|
||||
|
||||
from "comment" as com
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ begin
|
||||
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_citizen_by_id(com.created_by_id) as created_by
|
||||
find_citizen_by_id(com.created_by_id) as created_by,
|
||||
count_vote(com.id) as votes
|
||||
from "comment" as com
|
||||
where parent_id = _parent_id
|
||||
order by created_at asc,
|
||||
|
||||
@@ -14,7 +14,8 @@ begin
|
||||
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_citizen_by_id(com.created_by_id) as created_by
|
||||
find_citizen_by_id(com.created_by_id) as created_by,
|
||||
count_vote(com.id) as votes
|
||||
from "comment" as com
|
||||
where com.target_id = _target_id
|
||||
order by created_at asc,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
create or replace function count_vote(reference regclass, _target_id uuid, out resource json)
|
||||
create or replace function count_vote(_target_id uuid, out resource json)
|
||||
language plpgsql as
|
||||
$$
|
||||
declare
|
||||
@@ -16,8 +16,7 @@ begin
|
||||
when 1 then 'up'
|
||||
end) as label
|
||||
from vote v
|
||||
where v.target_reference = reference
|
||||
and v.target_id = _target_id
|
||||
where v.target_id = _target_id
|
||||
group by v.note
|
||||
order by v.note
|
||||
) t;
|
||||
@@ -26,4 +25,4 @@ begin
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- drop function if exists count_vote(regclass,uuid);
|
||||
-- drop function if exists count_vote(uuid);
|
||||
@@ -34,7 +34,7 @@ begin
|
||||
raise exception '% no implemented for vote', reference::text;
|
||||
end if;
|
||||
|
||||
select count_vote(reference, _target_id) into resource;
|
||||
select count_vote(_target_id) into resource;
|
||||
end;
|
||||
$$;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user