package router import ( "net/http" "strconv" "git.kolaente.de/konrad/Konfi-Castle-Kasino/pkg/config" "git.kolaente.de/konrad/Konfi-Castle-Kasino/pkg/models" "github.com/labstack/echo/v4" "github.com/labstack/gommon/log" ) func addKonfi(c echo.Context) error { if !isLoggedIn(c) { return echo.NewHTTPError(http.StatusForbidden, "Login first.") } // Mode nach Kofis if config.GetMode() == 0 { kofi := &models.Kofi{} kofi.Name = c.FormValue("name") kofi.Gemeinde = c.FormValue("gemeinde") // Einfügen err := kofi.Add() if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Error.") } return c.JSON(http.StatusOK, "success") } // Mode nach Gemeinden if config.GetMode() == 1 { var err error community := &models.Community{} community.Name = c.FormValue("name") community.KonfiCount, err = strconv.ParseInt(c.FormValue("konfis"), 10, 64) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, "konfiCount not int") } err = community.Add() if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Error.") } return c.JSON(http.StatusOK, "success") } log.Error("Invalid mode.") return echo.ErrInternalServerError }