Add front- end backend for new category-group

This commit is contained in:
2022-09-23 19:12:10 +00:00
parent 99979a35b0
commit 403544e99f
5 changed files with 98 additions and 2 deletions

View File

@@ -0,0 +1,35 @@
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)
}

View File

@@ -56,6 +56,9 @@ func (h *Handler) LoadRoutes(router *echo.Echo) {
category := authenticated.Group("/category")
category.POST("/new", h.newCategory)
categoryGroup := authenticated.Group("/category-group")
categoryGroup.POST("/new", h.newCategoryGroup)
budget := authenticated.Group("/budget")
budget.POST("/new", h.newBudget)
budget.GET("/:budgetid", h.budget)