Added route to view hardware component

This commit is contained in:
Gregory Ballantine 2024-05-29 08:37:51 -04:00
parent 4ad9a92306
commit dcfc6e0115
3 changed files with 21 additions and 1 deletions

View File

@ -7,6 +7,12 @@
<hr> <hr>
<h3>Latest Benchmark Results:</h3>
<p>There are currently no benchmarks recorded using this hardware component.</p>
<hr>
<p><a href="/hardware">Back</a></p> <p><a href="/hardware">Back</a></p>
</div> </div>

View File

@ -22,6 +22,8 @@ func RegisterRoutes(f *flamego.Flame) {
f.Get("/create", routes.HardwareGetCreate) f.Get("/create", routes.HardwareGetCreate)
f.Post("/create", binding.Form(forms.HardwareForm{}), routes.HardwarePostCreate) f.Post("/create", binding.Form(forms.HardwareForm{}), routes.HardwarePostCreate)
f.Get("/{hardware_id}", routes.HardwareGetView)
}) })
// test routes // test routes

View File

@ -17,13 +17,25 @@ import (
func HardwareGetList(t template.Template, data template.Data) { func HardwareGetList(t template.Template, data template.Data) {
// add hardwares to template // add hardwares to template
var hardware []models.Hardware var hardware []models.Hardware
models.DB.Find(&hardware) models.DB.First(&hardware)
data["hardware"] = hardware data["hardware"] = hardware
data["title"] = "List of Hardware" data["title"] = "List of Hardware"
t.HTML(http.StatusOK, "hardware/list") t.HTML(http.StatusOK, "hardware/list")
} }
func HardwareGetView(c flamego.Context, t template.Template, data template.Data) {
// find hardware ID from request
var hardwareID := c.Param("hardware_id")
// find hardware from DB
var hardware models.Hardware
models.DB.Find(&hardware)
data["hardware"] = hardware
data["title"] = hardware.
}
func HardwareGetCreate(t template.Template, data template.Data) { func HardwareGetCreate(t template.Template, data template.Data) {
data["title"] = "Add New Hardware" data["title"] = "Add New Hardware"
t.HTML(http.StatusOK, "hardware/create") t.HTML(http.StatusOK, "hardware/create")