Continued work on the test/edit post routet
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Gregory Ballantine
2025-08-12 11:40:56 -04:00
parent 60d8554cf1
commit 4b98322022
2 changed files with 31 additions and 10 deletions

View File

@@ -126,19 +126,22 @@ func TestPostEdit(c flamego.Context, form forms.TestForm, errs binding.Errors) {
var test models.Test
models.DB.Preload("Hardware").Preload("Benchmarks").First(&test, testID)
test := models.Test{
Name: form.Name,
Description: form.Description,
HardwareID: form.Hardware,
test.Name = form.Name
test.Description = form.Description
test.HardwareID = form.Hardware
// bind benchmarks to test that aren't already associated
for _, b := range form.Benchmarks {
if ! test.IsBenchmarkSelected(b) {
var benchmark models.Benchmark
models.DB.First(&benchmark, b) // find benchmark
models.DB.Model(&test).Association("Benchmarks").Append(&benchmark)
}
}
_ = models.DB.Create(&test)
// removed associated benchmarks that weren't in the form
for _, b := range test.Benchmarks {
// bind benchmarks to test
for _, v := range form.Benchmarks {
var benchmark models.Benchmark
models.DB.First(&benchmark, v) // find benchmark
models.DB.Model(&test).Association("Benchmarks").Append(&benchmark)
}
c.Redirect(fmt.Sprintf("/test/%d", test.ID))