From 708594d32ffe779cf547c816fa7cdd19d095be2e Mon Sep 17 00:00:00 2001
From: Freya Murphy <freya@freyacat.org>
Date: Mon, 20 May 2024 17:11:38 -0400
Subject: v2 done

---
 src/db/rest/media/api_delete_user_media.sql | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 src/db/rest/media/api_delete_user_media.sql

(limited to 'src/db/rest/media/api_delete_user_media.sql')

diff --git a/src/db/rest/media/api_delete_user_media.sql b/src/db/rest/media/api_delete_user_media.sql
new file mode 100644
index 0000000..d9a4529
--- /dev/null
+++ b/src/db/rest/media/api_delete_user_media.sql
@@ -0,0 +1,26 @@
+CREATE FUNCTION api.delete_user_media(
+	media_type admin.user_media_type
+)
+RETURNS void
+LANGUAGE plpgsql VOLATILE
+AS $BODY$
+DECLARE
+	_user_id INTEGER;
+	_data BYTEA;
+BEGIN
+	_user_id = _api.get_user_id();
+
+	DELETE FROM
+		admin.user_media
+	WHERE
+		"type" = media_type AND
+		"user_id" = _user_id;
+END
+$BODY$;
+
+GRANT EXECUTE ON FUNCTION api.delete_user_media(admin.user_media_type)
+	TO rest_user;
+GRANT DELETE ON TABLE admin.user_media
+	TO rest_user;
+GRANT UPDATE ON TABLE sys.user_media_id_seq
+	TO rest_user;
-- 
cgit v1.2.3-freya

