package benefactorkindboxreqhandler import ( param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" "git.gocasts.ir/ebhomengo/niki/pkg/claim" "github.com/labstack/echo/v4" "net/http" ) // Update godoc // @Summary Update kind box request by benefactor // @Tags KindBoxReq // @Accept json // @Produce json // @Param id path int true "KindBoxReq ID" // @Param Request body param.KindBoxReqUpdateRequest true "Update KindBoxReq Request Body" // @Success 204 // @Failure 400 {string} "Bad Request" // @Failure 401 {string} "invalid or expired jwt" // @Failure 403 {string} "user not allowed" // @Failure 422 {object} httpmsg.ErrorResponse // @Failure 500 {string} "something went wrong" // @Security AuthBearerBenefactor // @Router /benefactor/kindboxreqs/{id} [put] func (h Handler) Update(c echo.Context) error { var req param.KindBoxReqUpdateRequest if bErr := c.Bind(&req); bErr != nil { return echo.NewHTTPError(http.StatusBadRequest) } claims := claim.GetClaimsFromEchoContext(c) req.BenefactorID = claims.UserID if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateUpdateRequest(req); err != nil { msg, code := httpmsg.Error(err) return c.JSON(code, echo.Map{ "message": msg, "errors": fieldErrors, }) } sErr := h.benefactorKindBoxReqSvc.Update(c.Request().Context(), req) if sErr != nil { msg, code := httpmsg.Error(sErr) return echo.NewHTTPError(code, msg) } return c.JSON(http.StatusNoContent, nil) }