summaryrefslogtreecommitdiffstats
path: root/src/controller/routes.phel
diff options
context:
space:
mode:
authorGravatar Tom Willemse2026-09-08 00:54:36 -0700
committerGravatar Tom Willemse2026-09-08 00:54:36 -0700
commitcababf71f9411266191d4b1295c030ea533c942c (patch)
tree407c8c5424263d8563b3713b8cabfd953bbd4a2b /src/controller/routes.phel
parent528cbf2ef570894aaf919ed3da0d3cd129a2c8e8 (diff)
downloadlezer-cababf71f9411266191d4b1295c030ea533c942c.tar.gz
lezer-cababf71f9411266191d4b1295c030ea533c942c.zip
Add reading session and progress tables
Each book can have multiple reading sessions, when something is re-read later. Each session has multiple progress updates. Each progress update has a separate total number of pages because the total can change for ebooks depending on the device and the settings that are used.
Diffstat (limited to 'src/controller/routes.phel')
-rw-r--r--src/controller/routes.phel16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/controller/routes.phel b/src/controller/routes.phel
index 2e537db..7e1cde8 100644
--- a/src/controller/routes.phel
+++ b/src/controller/routes.phel
@@ -37,6 +37,22 @@
:updated_at time}))})))))
(h/response-from-map {:status 301 :headers {:location "/"}}))
+(defn book-session-create-handler [request]
+ (let [id (get-in request [:attributes :match :path-params :id])
+ time (php/time)]
+ (pdo/with-transaction conn
+ (let [session-id (pdo/insert conn :books_sessions {:book_id id
+ :status "started"
+ :started_at time
+ :created_at time
+ :updated_at time})]
+ (pdo/insert conn :sessions_progress {:session_id session-id
+ :progress 0
+ :total 0
+ :created_at time
+ :updated_at time}))))
+ (h/response-from-map {:status 301 :headers {:location "/"}}))
+
(defn author-view-handler [req]
(let [id (get-in req [:attributes :match :path-params :id])
author (first (pdo/select conn "select * from authors where id = :author_id" {:author_id id}))