diff --git a/.gitignore b/.gitignore index 03a4ecd..68779bc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ app *.out tmp output.css +example.db diff --git a/README.md b/README.md index 5aae05f..4e4e78b 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,6 @@ Example CRUD app written in Go + HTMX + Tailwind CSS This project implements a pure dynamic web app with SPA-like features but without heavy complex Javascript or Go frameworks to keep up with. Just HTML/CSS + Go ❤️ - - - ## Develop ``` diff --git a/db/seed.sql b/db/seed.sql index 0290d71..507cb11 100644 --- a/db/seed.sql +++ b/db/seed.sql @@ -1,9 +1,6 @@ --- CREATE DATABASE IF NOT EXISTS inventory; --- USE inventory; - CREATE TABLE IF NOT EXISTS items ( ID INTEGER PRIMARY KEY, - Name TEXT NOT NULL, + Name TEXT NOT NULL UNIQUE, Notes TEXT, Description TEXT, Stage INTEGER, @@ -12,7 +9,7 @@ CREATE TABLE IF NOT EXISTS items ( CREATE TABLE IF NOT EXISTS boxes ( ID INTEGER PRIMARY KEY, - Name TEXT NOT NULL, + Name TEXT NOT NULL UNIQUE, Notes TEXT, Description TEXT, Stage INTEGER, @@ -20,7 +17,7 @@ CREATE TABLE IF NOT EXISTS boxes ( ); CREATE TABLE IF NOT EXISTS boxitems ( - ItemID INTEGER, + ItemID INTEGER UNIQUE, -- items can only exist in a single box BoxID INTEGER, PRIMARY KEY (ItemID, BoxID), FOREIGN KEY (ItemID) REFERENCES items(ID), diff --git a/example.db b/example.db deleted file mode 100644 index 4a16fd6..0000000 Binary files a/example.db and /dev/null differ diff --git a/main.go b/main.go index 0ca95fa..2619f6e 100644 --- a/main.go +++ b/main.go @@ -46,14 +46,14 @@ func main() { router := http.NewServeMux() // router.Handle("/css/output.css", http.FileServer(http.FS(css))) - router.Handle("/company/add", web.Action(companyAdd)) - router.Handle("/company/add/", web.Action(companyAdd)) + // router.Handle("/company/add", web.Action(companyAdd)) + // router.Handle("/company/add/", web.Action(companyAdd)) - router.Handle("/company/edit", web.Action(companyEdit)) - router.Handle("/company/edit/", web.Action(companyEdit)) + // router.Handle("/company/edit", web.Action(companyEdit)) + // router.Handle("/company/edit/", web.Action(companyEdit)) - router.Handle("/company", web.Action(companies)) - router.Handle("/company/", web.Action(companies)) + // router.Handle("/company", web.Action(companies)) + // router.Handle("/company/", web.Action(companies)) router.Handle("/", web.Action(index)) router.Handle("/index.html", web.Action(index)) diff --git a/routes.go b/routes.go index e82ba52..3038948 100644 --- a/routes.go +++ b/routes.go @@ -7,16 +7,6 @@ import ( "github.com/jritsema/gotoolbox/web" ) -// Delete -> DELETE /company/{id} -> delete, companys.html - -// Edit -> GET /company/edit/{id} -> row-edit.html -// Save -> PUT /company/{id} -> update, row.html -// Cancel -> GET /company/{id} -> nothing, row.html - -// Add -> GET /company/add/ -> companys-add.html (target body with row-add.html and row.html) -// Save -> POST /company -> add, companys.html (target body without row-add.html) -// Cancel -> GET /company -> nothing, companys.html - func index(r *http.Request) *web.Response { result, err := db.GetAllItems() if err != nil { @@ -25,64 +15,3 @@ func index(r *http.Request) *web.Response { return web.HTML(http.StatusOK, html, "index.html", result, nil) } - - -// GET /company/add -func companyAdd(r *http.Request) *web.Response { - return web.HTML(http.StatusOK, html, "company-add.html", data, nil) -} - -// /GET company/edit/{id} -func companyEdit(r *http.Request) *web.Response { - id, _ := web.PathLast(r) - row := getCompanyByID(id) - return web.HTML(http.StatusOK, html, "row-edit.html", row, nil) -} - -// GET /company -// GET /company/{id} -// DELETE /company/{id} -// PUT /company/{id} -// POST /company -func companies(r *http.Request) *web.Response { - id, segments := web.PathLast(r) - switch r.Method { - - case http.MethodDelete: - deleteCompany(id) - return web.HTML(http.StatusOK, html, "companies.html", data, nil) - - //cancel - case http.MethodGet: - if segments > 1 { - //cancel edit - row := getCompanyByID(id) - return web.HTML(http.StatusOK, html, "row.html", row, nil) - } else { - //cancel add - return web.HTML(http.StatusOK, html, "companies.html", data, nil) - } - - //save edit - case http.MethodPut: - row := getCompanyByID(id) - r.ParseForm() - row.Company = r.Form.Get("company") - row.Contact = r.Form.Get("contact") - row.Country = r.Form.Get("country") - updateCompany(row) - return web.HTML(http.StatusOK, html, "row.html", row, nil) - - //save add - case http.MethodPost: - row := Company{} - r.ParseForm() - row.Company = r.Form.Get("company") - row.Contact = r.Form.Get("contact") - row.Country = r.Form.Get("country") - addCompany(row) - return web.HTML(http.StatusOK, html, "companies.html", data, nil) - } - - return web.Empty(http.StatusNotImplemented) -} diff --git a/screenshot.jpeg b/screenshot.jpeg deleted file mode 100644 index 7461d46..0000000 Binary files a/screenshot.jpeg and /dev/null differ diff --git a/templates/item-row.html b/templates/item-row.html index 312eca2..9469adb 100644 --- a/templates/item-row.html +++ b/templates/item-row.html @@ -1,31 +1,8 @@