feat: update HTTP handlers for shelf model

This commit is contained in:
2026-06-21 22:55:20 -04:00
parent de057de0bf
commit 346fd7af5b
+9 -10
View File
@@ -403,11 +403,11 @@ Set by test harnesses that only need the model functions.")
(defservlet index text/html (path query request) (defservlet index text/html (path query request)
(let* ((books (spine-books)) (let* ((books (spine-books))
(filter (cadr (assoc "filter" query)))) (shelf-filter (cadr (assoc "shelf" query))))
(if books (if books
(insert (spine-render "index.mustache" (insert (spine-render "index.mustache"
(spine-index-model books filter (cadr (assoc "id" query))))) (spine-index-model books shelf-filter (cadr (assoc "id" query)))))
(insert (spine-render-empty-state))))) (insert (spine-render-empty-state))))
(defun httpd/add (proc uri-path query request) (defun httpd/add (proc uri-path query request)
"Handle /add: GET shows form, POST creates a book." "Handle /add: GET shows form, POST creates a book."
@@ -417,7 +417,7 @@ Set by test harnesses that only need the model functions.")
(spine-add-book (spine-add-book
:title (cadr (assoc "title" query)) :title (cadr (assoc "title" query))
:author (cadr (assoc "author" query)) :author (cadr (assoc "author" query))
:category (cadr (assoc "category" query)) :shelf (cadr (assoc "shelf" query))
:format (cadr (assoc "format" query)) :format (cadr (assoc "format" query))
:isbn (cadr (assoc "isbn" query)) :isbn (cadr (assoc "isbn" query))
:cover (cadr (assoc "cover" query)) :cover (cadr (assoc "cover" query))
@@ -430,17 +430,18 @@ Set by test harnesses that only need the model functions.")
(let* ((books (spine-books)) (let* ((books (spine-books))
(model (if books (model (if books
(spine-add-form-model books) (spine-add-form-model books)
(ht ("app_title" "spine"))))) (ht ("app_title" "spine" "shelves" '())))))
(insert (spine-render "add.mustache" model))))))) (insert (spine-render "add.mustache" model)))))))
(defun httpd/edit (proc uri-path query request) (defun httpd/edit (proc uri-path query request)
"Handle /edit: GET shows prompt page, POST processes actions. "Handle /edit: GET shows prompt page, POST processes actions.
Query params: Query params:
id - book ID id - book ID
action - status | note | rating action - note | rating
value - target status / rating value (for status/rating actions)
text - note text (for note action) text - note text (for note action)
date - optional date string (for note/read actions)" date - optional date string (for note action)
value - rating value (for rating action)"
(let ((method (caar request)) (let ((method (caar request))
(id (cadr (assoc "id" query))) (id (cadr (assoc "id" query)))
(action (cadr (assoc "action" query))) (action (cadr (assoc "action" query)))
@@ -452,8 +453,6 @@ Query params:
(cond (cond
((equal action "note") ((equal action "note")
(spine-add-note id text date)) (spine-add-note id text date))
((equal action "status")
(spine-set-status id value))
((equal action "rating") ((equal action "rating")
(spine-set-rating id value))) (spine-set-rating id value)))
(httpd-redirect proc (format "/index?id=%s" id) 303)) (httpd-redirect proc (format "/index?id=%s" id) 303))