CREATE FUNCTION _api.like_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;

	UPDATE admin.like SET
		value = FALSE,
		modified = clock_timestamp()
		WHERE id = OLD.id;
END
$BODY$;

GRANT EXECUTE ON FUNCTION _api.like_delete()
	TO rest_user;
GRANT DELETE ON TABLE api.like
	TO rest_user;
GRANT UPDATE ON TABLE admin.like
	TO rest_user;

CREATE TRIGGER api_like_delete_trgr
	INSTEAD OF DELETE
			ON api.like
			FOR EACH ROW
				EXECUTE PROCEDURE _api.like_delete();
