46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package controllers
|
|
|
|
import (
|
|
"echoTest/models"
|
|
"echoTest/utils"
|
|
"strconv"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func (c *Controller) ParseBewertungen(ctx echo.Context) models.Bewertung {
|
|
newName := utils.ValidateName(ctx, c.Bewertungen)
|
|
vorname := ctx.FormValue("vorname")
|
|
if c.MaxPunkte.HvMax == 0.00 {
|
|
hvMax, _ := strconv.ParseFloat(ctx.FormValue("hv_max"), 64)
|
|
lvMax, _ := strconv.ParseFloat(ctx.FormValue("lv_max"), 64)
|
|
hvGewichtung, _ := strconv.ParseFloat(ctx.FormValue("hv_gewichtung"), 64)
|
|
lvGewichtung, _ := strconv.ParseFloat(ctx.FormValue("lv_gewichtung"), 64)
|
|
c.MaxPunkte.HvMax = hvMax
|
|
c.MaxPunkte.LvMax = lvMax
|
|
c.MaxPunkte.LvGewichtung = lvGewichtung
|
|
c.MaxPunkte.HvGewichtung = hvGewichtung
|
|
}
|
|
hvPunkte, _ := strconv.ParseFloat(ctx.FormValue("hv_punkte"), 64)
|
|
lvPunkte, _ := strconv.ParseFloat(ctx.FormValue("lv_punkte"), 64)
|
|
hvProzent := 100.00 / c.MaxPunkte.HvMax * hvPunkte
|
|
lvProzent := 100.00 / c.MaxPunkte.LvMax * lvPunkte
|
|
hvNote := utils.SetNote(hvProzent)
|
|
lvNote := utils.SetNote(lvProzent)
|
|
gesamtProzent := hvProzent*c.MaxPunkte.HvGewichtung/100 + lvProzent*c.MaxPunkte.LvGewichtung/100
|
|
gesamtNote := utils.SetNote(gesamtProzent)
|
|
return models.Bewertung{
|
|
ID: len(*c.Bewertungen) + 1,
|
|
Vorname: string(vorname),
|
|
Nachname: string(newName),
|
|
HvPunkte: hvPunkte,
|
|
HvProzent: hvProzent,
|
|
HvNote: int(hvNote),
|
|
LvPunkte: lvPunkte,
|
|
LvProzent: lvProzent,
|
|
LvNote: int(lvNote),
|
|
GesamtProzent: gesamtProzent,
|
|
GesamtNote: int(gesamtNote),
|
|
Gewertet: true,
|
|
}
|
|
}
|