feature #14: Add routes for get follows of one citizen

This commit is contained in:
2019-08-21 13:37:16 +02:00
parent 9b2b5e681f
commit 4e9f737e00
11 changed files with 179 additions and 21 deletions

View File

@@ -0,0 +1,26 @@
create or replace function find_follows_article_by_citizen(
_citizen_id uuid,
"limit" int default 50,
"offset" int default 0,
out resource json,
out total int
) language plpgsql as
$$
begin
select json_agg(t), (select count(id) from follow)
into resource, total
from (
select
f.*,
find_article_by_id(f.target_id) as target,
find_citizen_by_id(f.citizen_id) as citizen
from follow as f
where citizen_id = _citizen_id
order by created_at desc,
f.created_at desc
limit "limit" offset "offset"
) as t;
end;
$$;
-- drop function if exists find_follows_article_by_citizen(uuid, int, int);

View File

@@ -0,0 +1,26 @@
create or replace function find_follows_by_citizen(
_citizen_id uuid,
"limit" int default 50,
"offset" int default 0,
out resource json,
out total int
) language plpgsql as
$$
begin
select json_agg(t), (select count(id) from follow)
into resource, total
from (
select
f.*,
json_build_object('id', f.target_id) as target,
find_citizen_by_id(f.citizen_id) as citizen
from follow as f
where citizen_id = _citizen_id
order by created_at desc,
f.created_at desc
limit "limit" offset "offset"
) as t;
end;
$$;
-- drop function if exists find_follows_by_citizen(uuid, int, int);

View File

@@ -0,0 +1,26 @@
create or replace function find_follows_constitution_by_citizen(
_citizen_id uuid,
"limit" int default 50,
"offset" int default 0,
out resource json,
out total int
) language plpgsql as
$$
begin
select json_agg(t), (select count(id) from follow)
into resource, total
from (
select
f.*,
find_constitution_by_id(f.target_id) as target,
find_citizen_by_id(f.citizen_id) as citizen
from follow as f
where citizen_id = _citizen_id
order by created_at desc,
f.created_at desc
limit "limit" offset "offset"
) as t;
end;
$$;
-- drop function if exists find_follows_constitution_by_citizen(uuid, int, int);