forked from ebhomengo/niki
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package adminkindboxreqhandler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
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
|
|
// @Tags Admins KindBoxReqs
|
|
// @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
|
|
// @Router /admins/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)
|
|
}
|
|
|
|
resp, sErr := h.adminKindBoxReqSvc.Update(c.Request().Context(), req)
|
|
if sErr != nil {
|
|
msg, code := httpmsg.Error(sErr)
|
|
if resp.FieldErrors != nil {
|
|
return c.JSON(code, echo.Map{
|
|
"message": msg,
|
|
"errors": resp.FieldErrors,
|
|
})
|
|
}
|
|
|
|
return echo.NewHTTPError(code, msg)
|
|
}
|
|
|
|
return c.JSON(http.StatusNoContent, nil)
|
|
}
|