niki/delivery/http_server/admin/kind_box_req/add.go

45 lines
1.3 KiB
Go
Raw Normal View History

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)
}
result := h.adminKindBoxReqVld.ValidateAddRequest(req)
if result != nil {
msg, code := httpmsg.Error(result.Err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": result.Fields,
})
}
resp, sErr := h.adminKindBoxReqSvc.Add(c.Request().Context(), req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
}