From 6e821de7b17630e9e42dd6fedf05ad483bd3e4d2 Mon Sep 17 00:00:00 2001 From: James Brechtel Date: Sun, 21 Jun 2026 11:51:27 -0400 Subject: [PATCH] feat: add /edit handler with note prompt page and action dispatch --- spine.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/spine.el b/spine.el index 5f0f44d..3bc2226 100644 --- a/spine.el +++ b/spine.el @@ -476,6 +476,63 @@ Set by test harnesses that only need the model functions.") (ht ("app_title" "spine"))))) (insert (spine-render "add.mustache" model))))))) +(defun httpd/edit (proc uri-path query request) + "Handle /edit: GET shows prompt page, POST processes actions. +Query params: + id - book ID + action - status | note | rating + value - target status / rating value (for status/rating actions) + text - note text (for note action) + date - optional date string (for note/read actions)" + (let ((method (caar request)) + (id (cadr (assoc "id" query))) + (action (cadr (assoc "action" query))) + (value (cadr (assoc "value" query))) + (text (cadr (assoc "text" query))) + (date (cadr (assoc "date" query)))) + (if (equal method "POST") + (progn + (cond + ((equal action "note") + (spine-add-note id text date)) + ((equal action "status") + (spine-set-status id value)) + ((equal action "rating") + (spine-set-rating id value))) + (httpd-redirect proc (format "/index?id=%s" id) 303)) + ;; GET: show prompt page for actions needing input + (if (and id (equal action "note")) + (let* ((books (spine-books)) + (book (cl-find id books :key (lambda (b) (plist-get b :id)) :test #'equal)) + (title (if book (plist-get book :title) "Unknown"))) + (httpd-with-buffer proc "text/html" + (insert (format +" + + + +Spine — note + + + +
+
+
spine · add note
+

%s

+
+ + + + + +
+
+
+ +" + title id (format-time-string "%Y-%m-%d")))))) + ;; Unknown action or missing id: redirect to index + (httpd-redirect proc "/index" 302)))) (defun httpd/ (proc uri-path query request) "Redirect root to /index." (httpd-redirect proc "/index" 302))