2024-06-21 06:57:35 +00:00
|
|
|
package adminkindboxreqhandler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
|
|
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
|
|
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
|
|
|
echo "github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AddKindBoxReq godoc
|
|
|
|
// @Summary Add a new kind box request for a benefactor by admin
|
|
|
|
// @Tags KindBoxReq
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param Request body param.KindBoxReqAddRequest true "New kind box request details"
|
|
|
|
// @Success 200 {object} param.KindBoxReqAddResponse
|
|
|
|
// @Failure 400 {string} "Bad request"
|
|
|
|
// @Security AuthBearerAdmin
|
|
|
|
// @Router /admin/kindboxreqs [post].
|
|
|
|
func (h Handler) AddKindBoxReq(c echo.Context) error {
|
|
|
|
req := param.KindBoxReqAddRequest{}
|
|
|
|
if err := c.Bind(&req); err != nil {
|
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, errmsg.ErrBadRequest)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, sErr := h.adminKindBoxReqSvc.Add(c.Request().Context(), req)
|
|
|
|
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-06-21 06:57:35 +00:00
|
|
|
|
|
|
|
return echo.NewHTTPError(code, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusCreated, resp)
|
|
|
|
}
|