Started working on test edit page; removed nodemon because it wasn't working

This commit is contained in:
2025-07-02 17:34:06 -04:00
parent 3fa86ad23d
commit 6434fd0b9c
9 changed files with 101 additions and 142 deletions

10
web/helpers.go Normal file
View File

@ -0,0 +1,10 @@
package web
func Contains(slice []string, val string) bool {
for _, v := range slice {
if v == val {
return true
}
}
return false
}

View File

@ -51,7 +51,10 @@ func RegisterRoutes(f *flamego.Flame) {
f.Get("/create", routes.TestGetCreate)
f.Post("/create", binding.Form(forms.TestForm{}), routes.TestPostCreate)
f.Get("/{test_id}", routes.TestGetView)
f.Group("/{test_id}", func() {
f.Get("", routes.TestGetView)
f.Get("/edit", routes.TestGetEdit)
})
})
// result routes

View File

@ -81,3 +81,24 @@ func TestPostCreate(c flamego.Context, form forms.TestForm, errs binding.Errors)
c.Redirect(fmt.Sprintf("/test/%d", test.ID))
}
func TestGetEdit(c flamego.Context, t template.Template, data template.Data) {
// find test in DB
testID := c.Param("test_id")
var test models.Test
models.DB.Preload("Hardware").Preload("Benchmarks").First(&test, testID)
data["test"] = test
// add hardware components to template
var hardware []models.Hardware
models.DB.Find(&hardware)
data["hardware"] = hardware
// add benchmarks to template
var benchmarks []models.Benchmark
models.DB.Find(&benchmarks)
data["benchmarks"] = benchmarks
data["title"] = fmt.Sprintf("Editing Test: %s", test.Name)
t.HTML(http.StatusOK, "test/edit")
}