summaryrefslogtreecommitdiff
path: root/db/rest/post
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-04-01 11:09:25 -0400
committerFreya Murphy <freya@freyacat.org>2024-04-01 11:09:25 -0400
commit3a82baec9d793edf81ac2b151b0f4d4159641375 (patch)
treef9d50c296b078ac48c2a2391c172c3ccf37edb3f /db/rest/post
parentrefactor asset dir, refactor oberver in lib (diff)
downloadxssbook2-3a82baec9d793edf81ac2b151b0f4d4159641375.tar.gz
xssbook2-3a82baec9d793edf81ac2b151b0f4d4159641375.tar.bz2
xssbook2-3a82baec9d793edf81ac2b151b0f4d4159641375.zip
login and register, liking on homepage
Diffstat (limited to 'db/rest/post')
-rw-r--r--db/rest/post/api_post.sql25
-rw-r--r--db/rest/post/api_post_delete.sql31
-rw-r--r--db/rest/post/api_post_insert.sql44
-rw-r--r--db/rest/post/api_post_update.sql50
4 files changed, 0 insertions, 150 deletions
diff --git a/db/rest/post/api_post.sql b/db/rest/post/api_post.sql
deleted file mode 100644
index 375f292..0000000
--- a/db/rest/post/api_post.sql
+++ /dev/null
@@ -1,25 +0,0 @@
-CREATE VIEW api.post AS
- SELECT
- p.id,
- p.user_id,
- p.content,
- p.date,
- COALESCE(c.cc, 0)
- AS comment_count
- FROM
- admin.post p
- LEFT JOIN (
- SELECT
- COUNT(c.id) as cc,
- c.post_id
- FROM
- admin.comment c
- GROUP BY
- c.post_id
- ) c ON p.id = c.post_id
- ORDER BY p.id DESC;
-
-GRANT SELECT ON TABLE api.post
- TO rest_anon, rest_user;
-GRANT SELECT ON TABLE admin.post
- TO rest_anon, rest_user;
diff --git a/db/rest/post/api_post_delete.sql b/db/rest/post/api_post_delete.sql
deleted file mode 100644
index e3dec55..0000000
--- a/db/rest/post/api_post_delete.sql
+++ /dev/null
@@ -1,31 +0,0 @@
-CREATE FUNCTION _api.post_delete()
-RETURNS TRIGGER
-LANGUAGE plpgsql VOLATILE
-AS $BODY$
-DECLARE
- _user_id INTEGER;
-BEGIN
- _user_id = _api.get_user_id();
-
- IF OLD.user_id <> _user_id THEN
- PERFORM _api.raise_deny();
- END IF;
-
- DELETE FROM admin.post
- WHERE user_id = _user_id
- AND id = OLD.id;
-END
-$BODY$;
-
-GRANT EXECUTE ON FUNCTION _api.post_delete()
- TO rest_user;
-GRANT DELETE ON TABLE api.post
- TO rest_user;
-GRANT DELETE ON TABLE admin.post
- TO rest_user;
-
-CREATE TRIGGER api_post_delete_trgr
- INSTEAD OF DELETE
- ON api.post
- FOR EACH ROW
- EXECUTE PROCEDURE _api.post_delete();
diff --git a/db/rest/post/api_post_insert.sql b/db/rest/post/api_post_insert.sql
deleted file mode 100644
index 8b2eb48..0000000
--- a/db/rest/post/api_post_insert.sql
+++ /dev/null
@@ -1,44 +0,0 @@
-CREATE FUNCTION _api.post_insert()
-RETURNS TRIGGER
-LANGUAGE plpgsql VOLATILE
-AS $BODY$
-DECLARE
- _user_id INTEGER;
-BEGIN
- _user_id = _api.get_user_id();
-
- NEW.content := _api.trim(NEW.content);
-
- PERFORM _api.validate_text(
- _text => NEW.content,
- _column => 'content',
- _min => 1,
- _max => 4096
- );
-
- INSERT INTO admin.post (
- user_id,
- content
- ) VALUES (
- _user_id,
- NEW.content
- );
-
- RETURN NEW;
-END
-$BODY$;
-
-GRANT EXECUTE ON FUNCTION _api.post_insert()
- TO rest_user;
-GRANT INSERT ON TABLE api.post
- TO rest_user;
-GRANT INSERT ON TABLE admin.post
- TO rest_user;
-GRANT UPDATE ON TABLE sys.post_id_seq
- TO rest_user;
-
-CREATE TRIGGER api_post_insert_trgr
- INSTEAD OF INSERT
- ON api.post
- FOR EACH ROW
- EXECUTE PROCEDURE _api.post_insert();
diff --git a/db/rest/post/api_post_update.sql b/db/rest/post/api_post_update.sql
deleted file mode 100644
index 70230d0..0000000
--- a/db/rest/post/api_post_update.sql
+++ /dev/null
@@ -1,50 +0,0 @@
-CREATE FUNCTION _api.post_update()
-RETURNS TRIGGER
-LANGUAGE plpgsql VOLATILE
-AS $BODY$
-DECLARE
- _user_id INTEGER;
- _changed BOOLEAN;
-BEGIN
- _user_id = _api.get_user_id();
- _changed = FALSE;
-
- IF OLD.user_id <> _user_id THEN
- PERFORM _api.raise_deny();
- END IF;
-
- NEW.content = COALESCE(NEW.content, OLD.content);
- NEW.content := _api.trim(NEW.content);
- PERFORM _api.validate_text(
- _text => NEW.content,
- _column => 'content',
- _min => 1,
- _max => 4096
- );
-
- IF NEW.content IS DISTINCT FROM OLD.content THEN
- _changed = TRUE;
- END IF;
-
- IF _changed THEN
- UPDATE admin.post
- SET content = NEW.content
- WHERE id = OLD.id;
- END IF;
-
- RETURN NEW;
-END
-$BODY$;
-
-GRANT EXECUTE ON FUNCTION _api.post_update()
- TO rest_user;
-GRANT UPDATE ON TABLE api.post
- TO rest_user;
-GRANT UPDATE ON TABLE admin.post
- TO rest_user;
-
-CREATE TRIGGER api_post_update_trgr
- INSTEAD OF UPDATE
- ON api.post
- FOR EACH ROW
- EXECUTE PROCEDURE _api.post_update();