niki/delivery/http_server/benefactor/benefactor/send_otp.go

43 lines
1.1 KiB
Go

package benefactorhandler
import (
"net/http"
benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
"github.com/labstack/echo/v4"
)
// SendOtp godoc
// @Summary send otp benefactor
// @Tags benefactor
// @Accept json
// @Produce json
// @Param Request body benefactoreparam.SendOtpRequest true "send otp benefactor"
// @Success 200 {object} benefactoreparam.SendOtpResponse
// @Failure 400 {string} "Bad request"
// @Router /benefactor/send-otp [post]
func (h Handler) SendOtp(c echo.Context) error {
var req benefactoreparam.SendOtpRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
if fieldErrors, err := h.benefactorVld.ValidateSendOtpRequest(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.benefactorSvc.SendOtp(c.Request().Context(), req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusOK, resp)
}