budgeteer/server/category_group_new.go

36 lines
835 B
Go

package server
import (
"net/http"
"git.javil.eu/jacob1123/budgeteer/postgres"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
)
type newCategoryGroupInformation struct {
BudgetID uuid.UUID `json:"budgetId"`
Group string `json:"group"`
}
func (h *Handler) newCategoryGroup(c echo.Context) error {
var newCategory newCategoryGroupInformation
if err := c.Bind(&newCategory); err != nil {
return echo.NewHTTPError(http.StatusNotAcceptable, err)
}
if newCategory.Group == "" {
return echo.NewHTTPError(http.StatusBadRequest, "category group is required")
}
budget, err := h.Service.CreateCategoryGroup(c.Request().Context(), postgres.CreateCategoryGroupParams{
BudgetID: newCategory.BudgetID,
Name: newCategory.Group,
})
if err != nil {
return err
}
return c.JSON(http.StatusOK, budget)
}