2022-12-07 21:24:11 -05:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2022-12-08 00:19:58 -05:00
|
|
|
"github.com/flamego/binding"
|
2022-12-07 21:24:11 -05:00
|
|
|
"github.com/flamego/flamego"
|
|
|
|
"github.com/flamego/template"
|
2022-12-08 00:19:58 -05:00
|
|
|
|
|
|
|
"git.metaunix.net/metaunix/raven/app/db"
|
|
|
|
"git.metaunix.net/metaunix/raven/app/web/form"
|
2022-12-07 21:24:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func RegisterRoutes(f *flamego.Flame) {
|
|
|
|
// index route - landing page for the user
|
|
|
|
f.Get("/", func(t template.Template, data template.Data) {
|
2022-12-07 22:12:46 -05:00
|
|
|
data["title"] = "Dashboard"
|
2022-12-07 21:24:11 -05:00
|
|
|
t.HTML(http.StatusOK, "index")
|
|
|
|
})
|
|
|
|
|
|
|
|
// item list route - lists all of the items in the database
|
2022-12-07 21:51:49 -05:00
|
|
|
f.Group("/item", func() {
|
|
|
|
f.Get("/list", func(t template.Template, data template.Data) {
|
2022-12-08 00:19:58 -05:00
|
|
|
var items []db.Item
|
|
|
|
db.DB.Find(&items)
|
|
|
|
data["inventory"] = items
|
|
|
|
|
2022-12-07 22:12:46 -05:00
|
|
|
data["title"] = "List of Inventory"
|
2022-12-07 21:51:49 -05:00
|
|
|
t.HTML(http.StatusOK, "item/list")
|
|
|
|
})
|
|
|
|
|
|
|
|
f.Get("/create", func(t template.Template, data template.Data) {
|
2022-12-07 22:12:46 -05:00
|
|
|
data["title"] = "Create New Item"
|
2022-12-07 21:51:49 -05:00
|
|
|
t.HTML(http.StatusOK, "item/create")
|
|
|
|
})
|
2022-12-08 00:19:58 -05:00
|
|
|
f.Post("/create", binding.Form(form.Item{}), func(c flamego.Context, form form.Item) {
|
|
|
|
// Create new Item object
|
|
|
|
item := db.Item{
|
|
|
|
Name: form.Name,
|
|
|
|
SerialNumber: form.SerialNumber,
|
|
|
|
SkuNumber: form.SkuNumber,
|
|
|
|
Manufacturer: form.Manufacturer,
|
|
|
|
Type: form.Type,
|
|
|
|
PurchasedFrom: form.PurchasedFrom,
|
|
|
|
PurchasedAt: form.PurchasedAt,
|
|
|
|
}
|
|
|
|
db.DB.Create(&item)
|
|
|
|
|
|
|
|
// Redirect user to items list
|
|
|
|
c.Redirect("/item/list")
|
|
|
|
})
|
2022-12-07 21:51:49 -05:00
|
|
|
})
|
2022-12-07 21:24:11 -05:00
|
|
|
}
|