From e774d11af63764a7457d842ecd74b30a183fa71e Mon Sep 17 00:00:00 2001 From: ckonstanski Date: Sun, 6 Sep 2026 22:04:28 -0600 Subject: migrate to react --- lisp/service/gallery-service.lisp | 52 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'lisp/service/gallery-service.lisp') diff --git a/lisp/service/gallery-service.lisp b/lisp/service/gallery-service.lisp index c3d0825..44a7804 100644 --- a/lisp/service/gallery-service.lisp +++ b/lisp/service/gallery-service.lisp @@ -9,12 +9,6 @@ :accessor admin-p)) (:documentation "")) -(defun gallery-json () - (with-noauth (instance gallery-service) - (with-valid-user (user "gallery-modify") - (setf (admin-p instance) nil) - (setf (admin-p instance) t)))) - (defclass gallery/view-service (gallery-service) ((results :initarg :results :initform nil @@ -22,6 +16,18 @@ (location-p :initform nil)) (:documentation "")) +(defclass gallery/modify-service (gallery/view-service) + ((form :initarg :form + :initform nil + :accessor form)) + (:documentation "")) + +(defun gallery-json () + (with-noauth (instance gallery-service) + (with-valid-user (user "gallery-modify") + (setf (admin-p instance) nil) + (setf (admin-p instance) t)))) + (defun gallery-view-json () (with-noauth (instance gallery/view-service) (with-valid-user (user "gallery-modify") @@ -35,14 +41,8 @@ (loop for gallery in (results instance) do (sanitize-json gallery)))) -(defclass gallery/add-modify-delete-service (gallery/view-service) - ((form :initarg :form - :initform nil - :accessor form)) - (:documentation "")) - (defun gallery-add-json () - (with-auth (instance gallery/add-modify-delete-service "gallery-modify") + (with-auth (instance gallery/modify-service "gallery-modify") (setf (form instance) (make-form "gallery-add-form" nil t @@ -53,7 +53,7 @@ (defun gallery-add-submit-json (description video_embed_url upload) (declare (special description video_embed_url)) - (with-auth (instance gallery/add-modify-delete-service "gallery-modify") + (with-auth (instance gallery/modify-service "gallery-modify") (with-bogenherr-database (let ((general-pkg (make-instance 'general-pkg)) (gallery (make-instance 'gallery)) @@ -75,7 +75,7 @@ (setf (session-value :message) "Gallery added successfully."))))) (defun gallery-modify-json (id) - (with-auth (instance gallery/add-modify-delete-service "gallery-modify") + (with-auth (instance gallery/modify-service "gallery-modify") (with-bogenherr-database (let* ((general-pkg (make-instance 'general-pkg)) (gallery (get-gallery general-pkg id))) @@ -88,11 +88,11 @@ (:name "video_embed_url" :label "Video embed URL" :field-type "text" :value ,(video_embed_url gallery)) (:name "upload" :label "Image/Video" :field-type "file") (:label "Modify Gallery" :field-type "button" :onclick "on_gallery_modify_submit_clicked()")))) - (setf (session-value :errormsg) "Error: could not modify gallery. Not found.")))))) + (setf (errormsg instance) "Error: could not modify gallery. Not found.")))))) (defun gallery-modify-submit-json (id description video_embed_url upload) (declare (special description video_embed_url)) - (with-auth (instance gallery/add-modify-delete-service "gallery-modify") + (with-auth (instance gallery/modify-service "gallery-modify") (with-bogenherr-database (let* ((general-pkg (make-instance 'general-pkg)) (gallery (get-gallery general-pkg id))) @@ -112,19 +112,19 @@ (setf (mime_type gallery) (org-ckons-file::get-mime-type new-filepath)) (setf (content gallery) (org-ckons-file::file-as-hex new-filepath)))) (update-gallery general-pkg gallery) - (setf (session-value :message) "Gallery saved successfully.")) - (setf (session-value :errormsg) "An error occurred.")))))) + (setf (message instance) "Gallery saved successfully.")) + (setf (errormsg instance) "An error occurred.")))))) (defun gallery-delete-json (id) - (with-auth (instance gallery/add-modify-delete-service "gallery-modify") + (with-auth (instance gallery/modify-service "gallery-modify") (with-bogenherr-database (let* ((general-pkg (make-instance 'general-pkg)) (gallery (get-gallery general-pkg id))) (if gallery (progn (delete-record general-pkg gallery) - (setf (session-value :message) "Gallery deleted successfully.")) - (setf (session-value :errormsg) "Error: could not delete gallery. Not found.")))))) + (setf (message instance) "Gallery deleted successfully.")) + (setf (errormsg instance) "Error: could not delete gallery. Not found.")))))) (defun gallery-file-view (id) (with-noauth-raw (instance gallery/view-service) @@ -134,3 +134,11 @@ (when gallery (setf (org-ckons-session::content-type *header-register*) (mime_type gallery)) (ironclad:hex-string-to-byte-array (content gallery))))))) + +(define-endpoint ("/gallery" :method :get) () gallery-json) +(define-endpoint ("/gallery/view" :method :get) () gallery-view-json) +(define-endpoint ("/gallery/add" :method :post) () gallery-add-json) +(define-endpoint ("/gallery/add/submit" :method :post) (&post (description :parameter-type 'string) (video_embed_url :parameter-type 'string) (upload :parameter-type 'string)) gallery-add-submit-json description video_embed_url upload) +(define-endpoint ("/gallery/modify" :method :post) (&post (id :parameter-type 'integer)) gallery-modify-json id) +(define-endpoint ("/gallery/modify/submit" :method :post) (&post (id :parameter-type 'integer) (description :parameter-type 'string) (video_embed_url :parameter-type 'string) (upload :parameter-type 'string)) gallery-modify-submit-json id description video_embed_url upload) +(define-endpoint ("/gallery/delete" :method :post) (&post (id :parameter-type 'integer)) gallery-delete-json id) -- cgit v1.3