From dcfc6e0115d0b8ee0ae28131c9bb00ebebd81e92 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 29 May 2024 08:37:51 -0400 Subject: [PATCH] Added route to view hardware component --- templates/hardware/view.tmpl | 6 ++++++ web/routes.go | 2 ++ web/routes/hardware.go | 14 +++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/templates/hardware/view.tmpl b/templates/hardware/view.tmpl index 907f5a1..3f42e56 100644 --- a/templates/hardware/view.tmpl +++ b/templates/hardware/view.tmpl @@ -7,6 +7,12 @@
+

Latest Benchmark Results:

+ +

There are currently no benchmarks recorded using this hardware component.

+ +
+

Back

diff --git a/web/routes.go b/web/routes.go index c507aa1..42e094f 100644 --- a/web/routes.go +++ b/web/routes.go @@ -22,6 +22,8 @@ func RegisterRoutes(f *flamego.Flame) { f.Get("/create", routes.HardwareGetCreate) f.Post("/create", binding.Form(forms.HardwareForm{}), routes.HardwarePostCreate) + + f.Get("/{hardware_id}", routes.HardwareGetView) }) // test routes diff --git a/web/routes/hardware.go b/web/routes/hardware.go index 7bc254a..0de9b2c 100644 --- a/web/routes/hardware.go +++ b/web/routes/hardware.go @@ -17,13 +17,25 @@ import ( func HardwareGetList(t template.Template, data template.Data) { // add hardwares to template var hardware []models.Hardware - models.DB.Find(&hardware) + models.DB.First(&hardware) data["hardware"] = hardware data["title"] = "List of Hardware" 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) { data["title"] = "Add New Hardware" t.HTML(http.StatusOK, "hardware/create")