54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/flamego/binding"
|
|
"github.com/flamego/flamego"
|
|
"github.com/flamego/template"
|
|
|
|
"git.metaunix.net/metaunix/raven/app/db"
|
|
"git.metaunix.net/metaunix/raven/app/web/form"
|
|
)
|
|
|
|
func RegisterRoutes(f *flamego.Flame) {
|
|
// index route - landing page for the user
|
|
f.Get("/", func(t template.Template, data template.Data) {
|
|
data["title"] = "Dashboard"
|
|
t.HTML(http.StatusOK, "index")
|
|
})
|
|
|
|
// item list route - lists all of the items in the database
|
|
f.Group("/item", func() {
|
|
f.Get("/list", func(t template.Template, data template.Data) {
|
|
var items []db.Item
|
|
db.DB.Find(&items)
|
|
data["inventory"] = items
|
|
|
|
data["title"] = "List of Inventory"
|
|
t.HTML(http.StatusOK, "item/list")
|
|
})
|
|
|
|
f.Get("/create", func(t template.Template, data template.Data) {
|
|
data["title"] = "Create New Item"
|
|
t.HTML(http.StatusOK, "item/create")
|
|
})
|
|
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")
|
|
})
|
|
})
|
|
}
|