39 lines
857 B
Go
39 lines
857 B
Go
|
package routes
|
||
|
|
||
|
import (
|
||
|
"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"
|
||
|
)
|
||
|
|
||
|
func TestPostCreate(c flamego.Context, form forms.ResultForm, 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)
|
||
|
}
|
||
|
|
||
|
result := models.Result{
|
||
|
TestID: form.Test,
|
||
|
HardwareID: form.Hardware,
|
||
|
BenchmarkID: form.Benchmark,
|
||
|
AverageScore: form.AverageScore,
|
||
|
MinimumScore: form.MinimumScore,
|
||
|
MaximumScore: form.MaximumScore,
|
||
|
}
|
||
|
|
||
|
_ = models.DB.Create(&result)
|
||
|
|
||
|
c.Redirect(fmt.Sprintf("/test/%d", result.TestID))
|
||
|
}
|