diff options
Diffstat (limited to '')
| -rw-r--r-- | src/db/rest/post/api_post.sql (renamed from db/rest/post/api_post.sql) | 18 | ||||
| -rw-r--r-- | src/db/rest/post/api_post_delete.sql (renamed from db/rest/post/api_post_delete.sql) | 9 | ||||
| -rw-r--r-- | src/db/rest/post/api_post_insert.sql (renamed from db/rest/post/api_post_insert.sql) | 4 | ||||
| -rw-r--r-- | src/db/rest/post/api_post_update.sql (renamed from db/rest/post/api_post_update.sql) | 5 |
4 files changed, 26 insertions, 10 deletions
diff --git a/db/rest/post/api_post.sql b/src/db/rest/post/api_post.sql index 375f292..0d60473 100644 --- a/db/rest/post/api_post.sql +++ b/src/db/rest/post/api_post.sql @@ -3,7 +3,8 @@ CREATE VIEW api.post AS p.id, p.user_id, p.content, - p.date, + p.created, + p.modified, COALESCE(c.cc, 0) AS comment_count FROM @@ -16,8 +17,19 @@ CREATE VIEW api.post AS admin.comment c GROUP BY c.post_id - ) c ON p.id = c.post_id - ORDER BY p.id DESC; + ) c + ON + p.id = c.post_id + LEFT JOIN + admin.user u + ON + u.id = p.user_id + WHERE + p.deleted <> TRUE + AND + u.deleted <> TRUE + ORDER BY + p.id DESC; GRANT SELECT ON TABLE api.post TO rest_anon, rest_user; diff --git a/db/rest/post/api_post_delete.sql b/src/db/rest/post/api_post_delete.sql index e3dec55..8f26b40 100644 --- a/db/rest/post/api_post_delete.sql +++ b/src/db/rest/post/api_post_delete.sql @@ -11,9 +11,10 @@ BEGIN PERFORM _api.raise_deny(); END IF; - DELETE FROM admin.post - WHERE user_id = _user_id - AND id = OLD.id; + UPDATE admin.post SET + deleted = TRUE, + modified = clock_timestamp() + WHERE id = OLD.id; END $BODY$; @@ -21,7 +22,7 @@ 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 +GRANT UPDATE ON TABLE admin.post TO rest_user; CREATE TRIGGER api_post_delete_trgr diff --git a/db/rest/post/api_post_insert.sql b/src/db/rest/post/api_post_insert.sql index 8b2eb48..e0594dc 100644 --- a/db/rest/post/api_post_insert.sql +++ b/src/db/rest/post/api_post_insert.sql @@ -22,7 +22,9 @@ BEGIN ) VALUES ( _user_id, NEW.content - ); + ) + RETURNING id + INTO NEW.id; RETURN NEW; END diff --git a/db/rest/post/api_post_update.sql b/src/db/rest/post/api_post_update.sql index 70230d0..7b4360d 100644 --- a/db/rest/post/api_post_update.sql +++ b/src/db/rest/post/api_post_update.sql @@ -27,8 +27,9 @@ BEGIN END IF; IF _changed THEN - UPDATE admin.post - SET content = NEW.content + UPDATE admin.post SET + content = NEW.content, + modified = clock_timestamp() WHERE id = OLD.id; END IF; |