diff options
author | Colin Okay <okay@toyful.space> | 2022-03-13 17:40:45 -0500 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-03-13 17:40:45 -0500 |
commit | 57bae08a8b9accc1d4bfb7165080e7d5a5ef2a30 (patch) | |
tree | ad737e3a5d2d61817fcd89ea0cf7a972202f98c5 /lib | |
parent | 7a97e9d6ba5737f1088dd3a81b9b16121cf47c39 (diff) |
deletion support; some cache syncing in client functions;
Diffstat (limited to 'lib')
-rw-r--r-- | lib/client.lisp | 68 | ||||
-rw-r--r-- | lib/state.lisp | 4 |
2 files changed, 49 insertions, 23 deletions
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 <http://www.gnu.org/licenses/>. (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 |