blt/web/routes/result.go

40 lines
876 B
Go
Raw Normal View History

2024-05-29 11:40:42 -04:00
package routes
import (
2024-05-29 11:43:42 -04:00
"fmt"
2024-05-29 11:40:42 -04:00
"log"
"github.com/flamego/binding"
"github.com/flamego/flamego"
"github.com/flamego/validator"
"git.metaunix.net/bitgoblin/blt/models"
"git.metaunix.net/bitgoblin/blt/web/forms"
)
2024-05-29 11:43:17 -04:00
func ResultPostCreate(c flamego.Context, form forms.ResultForm, errs binding.Errors) {
2024-05-29 11:40:42 -04:00
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)
}
result := models.Result{
2024-05-29 11:43:17 -04:00
TestID: form.Test,
HardwareID: form.Hardware,
BenchmarkID: form.Benchmark,
2024-05-29 11:40:42 -04:00
AverageScore: form.AverageScore,
MinimumScore: form.MinimumScore,
MaximumScore: form.MaximumScore,
}
_ = models.DB.Create(&result)
c.Redirect(fmt.Sprintf("/test/%d", result.TestID))
}