Added ability to edit tests and hardware
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -63,3 +63,43 @@ func HardwarePostCreate(c flamego.Context, form forms.HardwareForm, errs binding
|
||||
|
||||
c.Redirect(fmt.Sprintf("/hardware/%d", hardware.ID))
|
||||
}
|
||||
|
||||
func HardwareGetEdit(c flamego.Context, t template.Template, data template.Data) {
|
||||
// find hardware ID from request
|
||||
hardwareID := c.Param("hardware_id")
|
||||
|
||||
// find hardware from DB
|
||||
var hardware models.Hardware
|
||||
models.DB.Preload("Tests.Benchmarks").First(&hardware, hardwareID)
|
||||
data["hardware"] = hardware
|
||||
|
||||
data["title"] = "Edit Hardware"
|
||||
t.HTML(http.StatusOK, "hardware/edit")
|
||||
}
|
||||
|
||||
func HardwarePostEdit(c flamego.Context, form forms.HardwareForm, errs binding.Errors) {
|
||||
if len(errs) > 0 {
|
||||
var err error
|
||||
switch errs[0].Category {
|
||||
case binding.ErrorCategoryValidation:
|
||||
err = errs[0].Err.(validator.ValidationErrors)[0]
|
||||
default:
|
||||
err = errs[0].Err
|
||||
}
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// find hardware ID from request
|
||||
hardwareID := c.Param("hardware_id")
|
||||
|
||||
// find hardware from DB
|
||||
var hardware models.Hardware
|
||||
models.DB.Preload("Tests.Benchmarks").First(&hardware, hardwareID)
|
||||
|
||||
hardware.Name = form.Name
|
||||
hardware.Type = form.Type
|
||||
|
||||
models.DB.Save(&hardware)
|
||||
|
||||
c.Redirect(fmt.Sprintf("/hardware/%d", hardware.ID))
|
||||
}
|
||||
|
@@ -148,5 +148,7 @@ func TestPostEdit(c flamego.Context, form forms.TestForm, errs binding.Errors) {
|
||||
}
|
||||
}
|
||||
|
||||
models.DB.Save(&test)
|
||||
|
||||
c.Redirect(fmt.Sprintf("/test/%d", test.ID))
|
||||
}
|
||||
|
Reference in New Issue
Block a user