Add front- end backend for new category-group
This commit is contained in:
35
server/category_group_new.go
Normal file
35
server/category_group_new.go
Normal 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)
|
||||
}
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user