Continue migration to echo
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type CategoryWithBalance struct {
|
||||
@@ -27,7 +27,7 @@ func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBal
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) budgetingForMonth(c *gin.Context) {
|
||||
func (h *Handler) budgetingForMonth(c echo.Context) error {
|
||||
budgetID := c.Param("budgetid")
|
||||
budgetUUID, err := uuid.Parse(budgetID)
|
||||
if err != nil {
|
||||
@@ -35,9 +35,9 @@ func (h *Handler) budgetingForMonth(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
budget, err := h.Service.GetBudget(c.Request.Context(), budgetUUID)
|
||||
budget, err := h.Service.GetBudget(c.Request().Context(), budgetUUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@ func (h *Handler) budgetingForMonth(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.getBudgetingViewForMonth(c.Request.Context(), budget, month)
|
||||
data, err := h.getBudgetingViewForMonth(c.Request().Context(), budget, month)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, data)
|
||||
@@ -105,33 +105,30 @@ type BudgetingResponse struct {
|
||||
Budget postgres.Budget
|
||||
}
|
||||
|
||||
func (h *Handler) budget(c *gin.Context) {
|
||||
func (h *Handler) budget(c echo.Context) error {
|
||||
budgetID := c.Param("budgetid")
|
||||
budgetUUID, err := uuid.Parse(budgetID)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"budgetid missing from URL"})
|
||||
return
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "budgetid missing from URL")
|
||||
}
|
||||
|
||||
h.getBudget(c, budgetUUID)
|
||||
return h.getBudget(c, budgetUUID)
|
||||
}
|
||||
|
||||
func (h *Handler) getBudget(c *gin.Context, budgetUUID uuid.UUID) {
|
||||
budget, err := h.Service.GetBudget(c.Request.Context(), budgetUUID)
|
||||
func (h *Handler) getBudget(c echo.Context, budgetUUID uuid.UUID) error {
|
||||
budget, err := h.Service.GetBudget(c.Request().Context(), budgetUUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotFound, err)
|
||||
return
|
||||
return echo.NewHTTPError(http.StatusNotFound, err)
|
||||
}
|
||||
|
||||
accounts, err := h.Service.GetAccountsWithBalance(c.Request.Context(), budgetUUID)
|
||||
accounts, err := h.Service.GetAccountsWithBalance(c.Request().Context(), budgetUUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
data := BudgetingResponse{accounts, budget}
|
||||
|
||||
c.JSON(http.StatusOK, data)
|
||||
return c.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
func (h *Handler) calculateBalances(budget postgres.Budget, month Month,
|
||||
|
||||
Reference in New Issue
Block a user