From 94ef10d1fe4ed27f8442944c25ecc0300c5e5655 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 27 Aug 2026 00:11:47 -0700 Subject: Add subtitle to books --- src/controller/routes.phel | 6 ++++-- src/view/main.phel | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/controller/routes.phel b/src/controller/routes.phel index 75d1d5f..726f57b 100644 --- a/src/controller/routes.phel +++ b/src/controller/routes.phel @@ -8,7 +8,7 @@ (:require phel.string :as str)) (def conn (pdo/connect "sqlite:test.db")) -(pdo/exec conn "create table if not exists books (id integer primary key autoincrement, title varchar(255))") +(pdo/exec conn "create table if not exists books (id integer primary key autoincrement, title varchar(255), subtitle varchar(255))") (pdo/exec conn "create table if not exists authors (id integer primary key autoincrement, name varchar(255))") (pdo/exec conn "create table if not exists authors_books (author_id integer, book_id integer)") @@ -25,9 +25,11 @@ (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"]) #",")] (pdo/with-transaction conn - (let [book-id (pdo/insert conn :books {:title title})] + (let [book-id (pdo/insert conn :books {:title title + :subtitle subtitle})] (for [a :in authors] (pdo/insert conn :authors_books {:book_id book-id :author_id (or (pdo/fetch-column (pdo/query conn "select id from authors where name = :name" {:name a})) diff --git a/src/view/main.phel b/src/view/main.phel index f7a0190..809b765 100644 --- a/src/view/main.phel +++ b/src/view/main.phel @@ -52,6 +52,9 @@ [:label {:for "title"} "Title: "] [:input {:type "text" :name "title"}] [:br] + [:label {:for "subtitle"} "Subtitle: "] + [:input {:type "text" :name "subtitle"}] + [:br] [:label {:for "author"} "Author: "] [:input {:type "text" :name "author"}] [:input {:type "submit"}]]]]]])) -- cgit v1.3-2-g0d8e