Continue migration to echo

This commit is contained in:
2022-08-20 22:44:59 +00:00
parent 1a11555075
commit 9da4a6f03e
10 changed files with 76 additions and 99 deletions

View File

@ -18,28 +18,24 @@ func (h *Handler) setCategoryAssignment(c echo.Context) error {
categoryID := c.Param("categoryid")
categoryUUID, err := uuid.Parse(categoryID)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, ErrorResponse{"categoryid missing from URL"})
return
return echo.NewHTTPError(http.StatusBadRequest, "categoryid missing from URL")
}
var request SetCategoryAssignmentRequest
err = c.BindJSON(&request)
err = c.Bind(&request)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("invalid payload: %w", err))
return
}
date, err := getDate(c)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("date invalid: %w", err))
return
}
var amount numeric.Numeric
err = amount.Set(request.Assigned)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Errorf("parse amount: %w", err))
return
}
updateArgs := postgres.UpdateAssignmentParams{
@ -49,7 +45,8 @@ func (h *Handler) setCategoryAssignment(c echo.Context) error {
}
err = h.Service.UpdateAssignment(c.Request().Context(), updateArgs)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("update assignment: %w", err))
return
return fmt.Errorf("update assignment: %w", err)
}
return nil
}