Finishing the test/edit route
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -32,13 +31,8 @@ func (t *Test) SelectedBenchmarks() []string {
|
||||
return ids
|
||||
}
|
||||
|
||||
func (t *Test) IsBenchmarkSelected(benchmarkID string) bool {
|
||||
benchmarkConv, err := strconv.ParseUint(benchmarkID, 10, 0)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing Uint: ", err)
|
||||
}
|
||||
|
||||
benchmarkUint := uint(benchmarkConv)
|
||||
func (t *Test) IsBenchmarkSelected(benchmarkID uint) bool {
|
||||
benchmarkUint := uint(benchmarkID)
|
||||
|
||||
for _, b := range t.Benchmarks {
|
||||
if b.ID == benchmarkUint {
|
||||
|
@@ -4,5 +4,15 @@ type TestForm struct {
|
||||
Name string `form:"test_name" validate:"required"`
|
||||
Description string `form:"test_description"`
|
||||
Hardware int `form:"test_hardware" validate:"required"`
|
||||
Benchmarks []string `form:"test_benchmarks" validate:"required"`
|
||||
Benchmarks []uint `form:"test_benchmarks" validate:"required"`
|
||||
}
|
||||
|
||||
func (t *TestForm) IsBenchmarkSelected(checkID uint) bool {
|
||||
for _, selectedID := range t.Benchmarks {
|
||||
if checkID == selectedID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
@@ -54,6 +54,7 @@ func RegisterRoutes(f *flamego.Flame) {
|
||||
f.Group("/{test_id}", func() {
|
||||
f.Get("", routes.TestGetView)
|
||||
f.Get("/edit", routes.TestGetEdit)
|
||||
f.Post("/edit", binding.Form(forms.TestForm{}), routes.TestPostEdit)
|
||||
})
|
||||
})
|
||||
|
||||
|
@@ -141,7 +141,11 @@ func TestPostEdit(c flamego.Context, form forms.TestForm, errs binding.Errors) {
|
||||
|
||||
// removed associated benchmarks that weren't in the form
|
||||
for _, b := range test.Benchmarks {
|
||||
|
||||
if ! form.IsBenchmarkSelected(b.ID) {
|
||||
var benchmark models.Benchmark
|
||||
models.DB.First(&benchmark, b) // find benchmark
|
||||
models.DB.Model(&test).Association("Benchmarks").Delete(&benchmark)
|
||||
}
|
||||
}
|
||||
|
||||
c.Redirect(fmt.Sprintf("/test/%d", test.ID))
|
||||
|
Reference in New Issue
Block a user