diff options
| author | 2026-09-08 01:10:54 -0700 | |
|---|---|---|
| committer | 2026-09-08 01:10:54 -0700 | |
| commit | 801f360b6fe596ed7c848b2aa04d28a526216fa7 (patch) | |
| tree | 862eff49f1c36dede534f85bcdfa87d8cc88c1ff /src/controller/routes.phel | |
| parent | cababf71f9411266191d4b1295c030ea533c942c (diff) | |
| download | lezer-801f360b6fe596ed7c848b2aa04d28a526216fa7.tar.gz lezer-801f360b6fe596ed7c848b2aa04d28a526216fa7.zip | |
books: Add total number of pages per book
Although each session progress has a total number of pages field for when a
change in e-reader settings changes the number of pages in a book, each book
will also have an initial or standard number of pages.
When reading a printed book, the number of pages won't change (except maybe if
you change prints of the book), so we can always just use the same number as
previously. With ebooks the number of pages will _usually_ remain the same, so
there too we can default to the previous value, as long as we allow it to be
changed.
Diffstat (limited to 'src/controller/routes.phel')
| -rw-r--r-- | src/controller/routes.phel | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/controller/routes.phel b/src/controller/routes.phel index 7e1cde8..f6ec95e 100644 --- a/src/controller/routes.phel +++ b/src/controller/routes.phel @@ -22,11 +22,13 @@ (defn book-create-handler [request] (let [title (get-in request [:parsed-body "title"]) subtitle (get-in request [:parsed-body "subtitle"]) - authors (str/split (get-in request [:parsed-body "author"]) #",")] + authors (str/split (get-in request [:parsed-body "author"]) #",") + pages (get-in request [:parsed-body "pages"])] (pdo/with-transaction conn (let [time (php/time) book-id (pdo/insert conn :books {:title title :subtitle subtitle + :pages pages :created_at time :updated_at time})] (for [a :in authors] @@ -39,6 +41,7 @@ (defn book-session-create-handler [request] (let [id (get-in request [:attributes :match :path-params :id]) + pages (pdo/fetch-column (pdo/query conn "select pages from books where id = :id" {:id id})) time (php/time)] (pdo/with-transaction conn (let [session-id (pdo/insert conn :books_sessions {:book_id id @@ -48,7 +51,7 @@ :updated_at time})] (pdo/insert conn :sessions_progress {:session_id session-id :progress 0 - :total 0 + :total pages :created_at time :updated_at time})))) (h/response-from-map {:status 301 :headers {:location "/"}})) |
