diff --git a/db/entities.go b/db/entities.go index 3c97446..175f95c 100644 --- a/db/entities.go +++ b/db/entities.go @@ -51,4 +51,6 @@ type BoxItemWithItemInfo struct { Name string Stage PackingStage Category Category + Description *string + Notes *string } diff --git a/db/sql.go b/db/sql.go index 5f16eb0..e202155 100644 --- a/db/sql.go +++ b/db/sql.go @@ -156,7 +156,7 @@ func GetBoxItemsByBoxID(boxID int) ([]BoxItemWithItemInfo, error) { // get all rows from box_items where boxid = boxID // also get the item info for each item rows, err := db.Query( - "SELECT id, items.name, items.stage, items.category FROM boxitems JOIN items ON itemid=items.id WHERE boxid = ?", + "SELECT id, items.name, items.stage, items.category, items.description, items.notes FROM boxitems JOIN items ON itemid=items.id WHERE boxid = ?", boxID) if err != nil { @@ -169,7 +169,7 @@ func GetBoxItemsByBoxID(boxID int) ([]BoxItemWithItemInfo, error) { for rows.Next() { boxItem := BoxItemWithItemInfo{} - if err = rows.Scan(&boxItem.ID, &boxItem.Name, &boxItem.Stage, &boxItem.Category); err != nil { + if err = rows.Scan(&boxItem.ID, &boxItem.Name, &boxItem.Stage, &boxItem.Category, &boxItem.Description, &boxItem.Notes); err != nil { return nil, err } diff --git a/main.go b/main.go index 68c4709..d4c35b2 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,8 @@ func main() { boxActions := routes.Boxes(html) boxItemActions := routes.BoxItems(html) + + router.Handle("/items/edit", web.Action(itemActions.Edit)) router.Handle("/items/delete", web.Action(itemActions.Delete)) router.Handle("/items/save", web.Action(itemActions.Save)) diff --git a/routes/items.go b/routes/items.go index ab35795..e86174d 100644 --- a/routes/items.go +++ b/routes/items.go @@ -107,11 +107,18 @@ func GetItemByID(r *http.Request) *web.Response { func Put(r *http.Request) *web.Response { id, _ := web.PathLast(r) - err := r.ParseForm() - if err != nil { + if err := r.ParseForm(); err != nil { return web.Error(http.StatusBadRequest, err, nil) } + if r.Form.Get("category") == "" { + panic(r.Form.Get("")) + } + + if r.Form.Get("stage") == "" { + panic(r.Form.Get("")) + } + name := r.Form.Get("name") stage := r.Form.Get("stage") category := r.Form.Get("category") @@ -145,9 +152,7 @@ func Put(r *http.Request) *web.Response { }(), } - _, err = db.PutItem(item) - - if err != nil { + if _, err := db.PutItem(item); err != nil { return web.Error(http.StatusInternalServerError, err, nil) } diff --git a/scripts/index.js b/scripts/index.js new file mode 100644 index 0000000..e69de29 diff --git a/templates/box-items/box-item-list.html b/templates/box-items/box-item-list.html index 3070add..6447658 100644 --- a/templates/box-items/box-item-list.html +++ b/templates/box-items/box-item-list.html @@ -1,3 +1,23 @@ - - Hooray! + + + + + + + + + + + + + + + + + {{range .}} + {{ template "box-items/box-item-row.html" . }} + {{end}} + +
#NameStageCategoryDescriptionNotes
+ diff --git a/templates/box-items/box-item-row.html b/templates/box-items/box-item-row.html new file mode 100644 index 0000000..ddf60c3 --- /dev/null +++ b/templates/box-items/box-item-row.html @@ -0,0 +1,10 @@ + + {{ .ID }} + {{ .Name }} + + {{ template "components/parsed-packing-stage.html" .Stage }} + {{ template "components/parsed-category.html" .Category }} + + {{ .Description }} + {{ .Notes }} + diff --git a/templates/boxes/box-row.html b/templates/boxes/box-row.html index 089c07f..44f121f 100644 --- a/templates/boxes/box-row.html +++ b/templates/boxes/box-row.html @@ -3,6 +3,7 @@