diff options
author | Freya Murphy <freya@freyacat.org> | 2024-04-05 12:58:11 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-04-05 12:58:11 -0400 |
commit | b6ae609ee3186148836f96260aa203202f230d6a (patch) | |
tree | dc47fe1cd7cb98e046f1a1ffeba6edb1f739485c /src/db/rest/follow/api_follow_insert.sql | |
parent | i did thing oh god large commit (diff) | |
download | xssbook2-b6ae609ee3186148836f96260aa203202f230d6a.tar.gz xssbook2-b6ae609ee3186148836f96260aa203202f230d6a.tar.bz2 xssbook2-b6ae609ee3186148836f96260aa203202f230d6a.zip |
follow ppl
Diffstat (limited to 'src/db/rest/follow/api_follow_insert.sql')
-rw-r--r-- | src/db/rest/follow/api_follow_insert.sql | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/db/rest/follow/api_follow_insert.sql b/src/db/rest/follow/api_follow_insert.sql new file mode 100644 index 0000000..6351855 --- /dev/null +++ b/src/db/rest/follow/api_follow_insert.sql @@ -0,0 +1,46 @@ +CREATE FUNCTION _api.follow_insert() +RETURNS TRIGGER +LANGUAGE plpgsql VOLATILE +AS $BODY$ +DECLARE + _user_id INTEGER; +BEGIN + _user_id = _api.get_user_id(); + + IF NEW.followee_id IS NULL THEN + -- for now + PERFORM _api.raise_deny(); + END IF; + + NEW.value := COALESCE(NEW.value, TRUE); + + INSERT INTO admin.follow ( + follower_id, + followee_id, + value + ) VALUES ( + _user_id, + NEW.followee_id, + NEW.value + ) + RETURNING id + INTO NEW.id; + + RETURN NEW; +END +$BODY$; + +GRANT EXECUTE ON FUNCTION _api.follow_insert() + TO rest_user; +GRANT INSERT ON TABLE api.follow + TO rest_user; +GRANT INSERT ON TABLE admin.follow + TO rest_user; +GRANT UPDATE ON TABLE sys.follow_id_seq + TO rest_user; + +CREATE TRIGGER api_follow_insert_trgr + INSTEAD OF INSERT + ON api.follow + FOR EACH ROW + EXECUTE PROCEDURE _api.follow_insert(); |