From 57bae08a8b9accc1d4bfb7165080e7d5a5ef2a30 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sun, 13 Mar 2022 17:40:45 -0500 Subject: deletion support; some cache syncing in client functions; --- lib/client.lisp | 68 ++++++++++++++++++++++++++++++++++++++------------------- lib/state.lisp | 4 ++++ 2 files changed, 49 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/client.lisp b/lib/client.lisp index aa7e896..4aff60d 100644 --- a/lib/client.lisp +++ b/lib/client.lisp @@ -16,8 +16,8 @@ ;; along with this program. If not, see . (in-package :oneliners.cli) -;; NOTE WHILE HACKING. Each of the functions below that make HTTP -;; requests is meant to be called within the body of a +;; >>>>>NOTE WHILE HACKING<<<<<. Each of the functions below that make +;; HTTP requests are meant to be called within the body of a ;; WITH-LOCAL-STATE form. If you are hacking in the REPL, make sure ;; to wrap function calls appropriately. @@ -277,6 +277,7 @@ running the body. If such a oneliner can be found." ;(merge-oneliners (list new-item)) ;;TODO: this is broken, wait for API update. (format t "Edits accepted~%"))))))) +;;TODO: need to sync cache here. (defun publish-draft (name) (when-draft (ol name) (api:request-with @@ -292,29 +293,50 @@ running the body. If such a oneliner can be found." ;;; ADMIN OF ONELINER ENTRIES +(defun delete-item (ident) + (when-oneliner (ol ident) + (api:delete--oneliner-oneliner + ident + :token (api-token)) + ;; if we've made it this far no http error has been returned, + ;; hence we can delete it from the cache + (remove-from-cache ident))) + (defun flag-item (ident) + (when-oneliner (ol ident) + (api:put--oneliner-entry-flag + ident + :token (api-token) + :value "true") + ;; no http error, so we flag the cached version, ol. + (setf (oneliner-isflagged ol) t))) + +(defun unflag-item (ident) + (when-oneliner (ol ident) + (api:put--oneliner-entry-flag + ident + :token (api-token) + :value "false") + ;; no http error, so we can unflag the cached version, ol + (setf (oneliner-isflagged ol) nil))) + +(defun lock-item (ident) + (when-oneliner (ol ident) + (api:put--oneliner-oneliner-locked + ident + :token (api-token) + :value "true") + ;; no http error, so we can lock the cached version, ol + (setf (oneliner-islocked ol) t))) + +(defun unlock-item (ident) (when-oneliner (ol ident) - (api:put--oneliner-entry-flag (oneliner-id ol) - :token (api-token) - :value "true"))) - -(defun unflag-item (item-number) - (when-oneliner (ol item-number) - (api:put--oneliner-entry-flag (oneliner-id ol) - :token (api-token) - :value "false"))) - -(defun lock-item (item-number) - (when-oneliner (ol item-number) - (api:put--oneliner-oneliner-locked (oneliner-id ol) - :token (api-token) - :value "true"))) - -(defun unlock-item (item-number) - (when-oneliner (ol item-number) - (api:put--oneliner-oneliner-locked (oneliner-id ol) - :token (api-token) - :value "false"))) + (api:put--oneliner-oneliner-locked + ident + :token (api-token) + :value "false") + ;; no http error, so we can unlock the cached version, ol + (setf (oneliner-islocked ol) nil))) ;;; ACCOUNT AND INVITE STUFF diff --git a/lib/state.lisp b/lib/state.lisp index 9c25ab6..7a9a427 100644 --- a/lib/state.lisp +++ b/lib/state.lisp @@ -78,6 +78,10 @@ (string #'oneliner-name)) :test #'equal)) +(defun remove-from-cache (id-or-name) + "Removes an item from the contents of *cache*." + (a:when-let (found (get-cached id-or-name)) + (setf *cache* (delete found *cache*)))) ;;; DRAFTS VAR AND OPERATIONS -- cgit v1.2.3