budgeteer/server/category_group_new.go
2022-09-23 19:20:24 +00:00

36 lines
849 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")
}
categoryGroup, 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, categoryGroup)
}