2024-07-09 14:45:50 +00:00
|
|
|
package adminkindboxreqhandler
|
|
|
|
|
|
|
|
import (
|
2024-07-24 23:45:04 +00:00
|
|
|
"net/http"
|
|
|
|
|
2024-07-09 14:45:50 +00:00
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
|
|
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Update godoc
|
|
|
|
// @Summary Update kind box request by admin
|
2024-08-27 17:49:34 +00:00
|
|
|
// @Tags Admins KindBoxReqs
|
2024-07-09 14:45:50 +00:00
|
|
|
// @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"
|
|
|
|
// @Security AuthBearerAdmin
|
2024-08-27 17:49:34 +00:00
|
|
|
// @Router /admins/kindboxreqs/{id} [put].
|
2024-07-09 14:45:50 +00:00
|
|
|
func (h Handler) Update(c echo.Context) error {
|
|
|
|
var req param.KindBoxReqUpdateRequest
|
|
|
|
if bErr := c.Bind(&req); bErr != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest)
|
|
|
|
}
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
resp, sErr := h.adminKindBoxReqSvc.Update(c.Request().Context(), req)
|
2024-07-09 14:45:50 +00:00
|
|
|
if sErr != nil {
|
|
|
|
msg, code := httpmsg.Error(sErr)
|
2024-08-01 10:20:18 +00:00
|
|
|
if resp.FieldErrors != nil {
|
|
|
|
return c.JSON(code, echo.Map{
|
|
|
|
"message": msg,
|
|
|
|
"errors": resp.FieldErrors,
|
|
|
|
})
|
|
|
|
}
|
2024-07-09 14:45:50 +00:00
|
|
|
|
|
|
|
return echo.NewHTTPError(code, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusNoContent, nil)
|
|
|
|
}
|