Files
blt/models/test.go
Gregory Ballantine 4b98322022
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Continued work on the test/edit post routet
2025-08-12 11:40:56 -04:00

51 lines
912 B
Go

package models
import (
"fmt"
"strconv"
"gorm.io/gorm"
)
type Test struct {
gorm.Model
Name string
Description string
// belongs to hardware
HardwareID int
Hardware Hardware
// many-to-many benchmarks
Benchmarks []Benchmark `gorm:"many2many:tests_benchmarks;"`
// has many results
Results []Result
}
func (t *Test) SelectedBenchmarks() []string {
benchmarks := t.Benchmarks
ids := make([]string, len(benchmarks))
for i, b := range benchmarks {
ids[i] = strconv.Itoa(int(b.ID))
}
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)
for _, b := range t.Benchmarks {
if b.ID == benchmarkUint {
return true
}
}
return false
}