forked from ebhomengo/niki
1
0
Fork 0

fix(benefactor): fix getting benefactor kind box request by id

This commit is contained in:
Erfan Mohammadi 2024-04-27 01:07:01 +03:30 committed by Alireza Mokhtari Garakani
parent 8521cdbf20
commit d405c01b7b
4 changed files with 11 additions and 4 deletions

View File

@ -28,5 +28,5 @@ func (h Handler) Get(c echo.Context) error {
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusCreated, resp)
return c.JSON(http.StatusOK, resp)
}

View File

@ -9,8 +9,11 @@ import (
func (h Handler) SetRoutes(e *echo.Echo) {
r := e.Group("/benefactor/kindboxreqs")
r.POST("/", h.Add, middleware.Auth(h.authSvc, h.authConfig),
middleware.BenefactorAuthorization(entity.UserBenefactorRole))
r.Use(
middleware.Auth(h.authSvc, h.authConfig),
middleware.BenefactorAuthorization(entity.UserBenefactorRole),
)
r.POST("/", h.Add)
r.GET("/:id", h.Get)
}

View File

@ -98,6 +98,10 @@ func (d DB) GetKindBoxReqByID(ctx context.Context, kindBoxReqID, benefactorID ui
)
k, err := scanKindBoxReq(row)
if err != nil {
if err == sql.ErrNoRows {
return entity.KindBoxReq{}, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindNotFound)
}
return entity.KindBoxReq{}, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgCantScanQueryResult).WithKind(richerror.KindUnexpected)
}

View File

@ -12,7 +12,7 @@ func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param
kindBoxReq, err := s.repo.GetKindBoxReqByID(ctx, req.KindBoxReqID, req.BenefactorID)
if err != nil {
return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err)
}
return param.KindBoxReqGetResponse{KindBoxReq: kindBoxReq}, nil