2024-01-02 14:04:16 +00:00
|
|
|
package benefactorkindboxreqhandler
|
2024-02-19 13:45:55 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
2024-04-27 00:05:09 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
2024-02-19 13:45:55 +00:00
|
|
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2024-05-15 07:38:39 +00:00
|
|
|
// Get godoc
|
|
|
|
// @Summary benefactor get kindboxreq
|
|
|
|
// @Tags kindboxreq
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param id path int true "Id"
|
|
|
|
// @Success 200 {object} param.KindBoxReqGetResponse
|
|
|
|
// @Failure 400 {string} "Bad request"
|
|
|
|
// @Router /benefactor/kindboxreqs/{id} [get]
|
|
|
|
// @Security AuthBearerBenefactor
|
2024-02-19 13:45:55 +00:00
|
|
|
func (h Handler) Get(c echo.Context) error {
|
|
|
|
var req param.KindBoxReqGetRequest
|
2024-04-26 23:55:26 +00:00
|
|
|
if bErr := echo.PathParamsBinder(c).Uint("id", &req.KindBoxReqID).BindError(); bErr != nil {
|
2024-02-19 13:45:55 +00:00
|
|
|
return echo.NewHTTPError(http.StatusBadRequest)
|
|
|
|
}
|
2024-04-26 23:55:26 +00:00
|
|
|
claims := claim.GetClaimsFromEchoContext(c)
|
|
|
|
req.BenefactorID = claims.UserID
|
|
|
|
|
2024-02-19 13:45:55 +00:00
|
|
|
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateGetRequest(req); err != nil {
|
|
|
|
msg, code := httpmsg.Error(err)
|
|
|
|
|
|
|
|
return c.JSON(code, echo.Map{
|
|
|
|
"message": msg,
|
|
|
|
"errors": fieldErrors,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
resp, sErr := h.benefactorKindBoxReqSvc.Get(c.Request().Context(), req)
|
|
|
|
if sErr != nil {
|
|
|
|
msg, code := httpmsg.Error(sErr)
|
|
|
|
|
|
|
|
return echo.NewHTTPError(code, msg)
|
|
|
|
}
|
|
|
|
|
2024-04-26 21:37:01 +00:00
|
|
|
return c.JSON(http.StatusOK, resp)
|
2024-02-19 13:45:55 +00:00
|
|
|
}
|