feature #4: create function for follow
This commit is contained in:
21
resources/functions/follow/follow.sql
Normal file
21
resources/functions/follow/follow.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
create or replace function follow(reference regclass, target_id uuid, citizen_id uuid) returns void
|
||||
language plpgsql as
|
||||
$$
|
||||
declare
|
||||
_citizen_id alias for citizen_id;
|
||||
_target_id alias for target_id;
|
||||
begin
|
||||
if reference = 'article'::regclass then
|
||||
insert into follow_article (citizen_id, target_id)
|
||||
values (_citizen_id, _target_id);
|
||||
elseif reference = 'constitution'::regclass then
|
||||
insert into follow_constitution (citizen_id, target_id)
|
||||
values (_citizen_id, _target_id);
|
||||
elseif reference = 'citizen'::regclass then
|
||||
insert into follow_citizen (citizen_id, target_id)
|
||||
values (_citizen_id, _target_id);
|
||||
end if;
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- drop function if exists follow(regclass, uuid, uuid);
|
||||
16
resources/functions/follow/unfollow.sql
Normal file
16
resources/functions/follow/unfollow.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
create or replace function unfollow(reference regclass, target_id uuid, citizen_id uuid) returns void
|
||||
language plpgsql as
|
||||
$$
|
||||
declare
|
||||
_citizen_id alias for citizen_id;
|
||||
_target_id alias for target_id;
|
||||
begin
|
||||
delete
|
||||
from follow f
|
||||
where f.citizen_id = _citizen_id
|
||||
and f.target_id = _target_id
|
||||
and f.target_reference = reference;
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- drop function if exists unfollow(regclass, uuid, uuid);
|
||||
Reference in New Issue
Block a user