CREATE FUNCTION api.delete_user_media(
	media_type xssbook.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
		xssbook.user_media
	WHERE
		"type" = media_type AND
		"user_id" = _user_id;
END
$BODY$;

GRANT EXECUTE ON FUNCTION api.delete_user_media(xssbook.user_media_type)
	TO rest_user;
GRANT DELETE ON TABLE xssbook.user_media
	TO rest_user;
GRANT UPDATE ON TABLE sys.user_media_id_seq
	TO rest_user;
