From 3e0e8567eb22ecd9db2027f55a5fa18e69fbff4f Mon Sep 17 00:00:00 2001 From: Alireza Mokhtari G Date: Tue, 26 Dec 2023 16:41:29 +0330 Subject: [PATCH] fix(Benefactor&Admin kind_box_req): refactor some code error (listed in body) Benefactor: - delete.go -> dErr instead of err - get.go -> import errmsg - update.go -> entity.KindBoxReqPendingStatus instead of KindBoxReqPendingStatus Admin: - delete.go -> dErr instead of err - update.go -> entity.KindBoxReqPendingStatus instead of KindBoxReqPendingStatus --- service/admin/kind_box_req/delete.go | 5 ++--- service/admin/kind_box_req/get.go | 5 ++--- service/admin/kind_box_req/update.go | 4 ++-- service/benefactor/kind_box_req/delete.go | 17 +++++++++-------- service/benefactor/kind_box_req/get.go | 6 +++--- service/benefactor/kind_box_req/get_all.go | 6 +++--- service/benefactor/kind_box_req/update.go | 2 +- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/service/admin/kind_box_req/delete.go b/service/admin/kind_box_req/delete.go index 26891be..648e4a9 100644 --- a/service/admin/kind_box_req/delete.go +++ b/service/admin/kind_box_req/delete.go @@ -3,7 +3,6 @@ package adminkindboxreqservice import ( "context" - entity "git.gocasts.ir/ebhomengo/niki/entity" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) @@ -14,8 +13,8 @@ func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID) if dErr != nil { - return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) + return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected) } - return param.KindBoxReqDeleteResponse{KindBoxReq: kindBoxReq}, nil + return param.KindBoxReqDeleteResponse{}, nil } diff --git a/service/admin/kind_box_req/get.go b/service/admin/kind_box_req/get.go index 4cb5cc4..68cd332 100644 --- a/service/admin/kind_box_req/get.go +++ b/service/admin/kind_box_req/get.go @@ -3,15 +3,14 @@ package adminkindboxreqservice import ( "context" - entity "git.gocasts.ir/ebhomengo/niki/entity" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) { - + const op = "adminkindboxreqservice.Get" - + kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID) if err != nil { return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) diff --git a/service/admin/kind_box_req/update.go b/service/admin/kind_box_req/update.go index c530ab8..66c9cd5 100644 --- a/service/admin/kind_box_req/update.go +++ b/service/admin/kind_box_req/update.go @@ -13,14 +13,14 @@ func (s Service) Update(ctx context.Context, req param.KindBoxReqUpdateRequest) // TODO: can benefactor update its request ? // TODO: Is Update Mothod Service Responsible to check which kindboxreqID belongs to benefactorID ? // TODO: updating data(s) may have side-effect on other entities by masood-keshvary accepted -> rejected - + const op = "adminkindboxreqservice.Update" kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID) if gErr != nil { return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected) } - if kbr.Status != KindBoxReqPendingStatus { + if kbr.Status != entity.KindBoxReqPendingStatus { return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid) } diff --git a/service/benefactor/kind_box_req/delete.go b/service/benefactor/kind_box_req/delete.go index 37c4a33..f1c2d9b 100644 --- a/service/benefactor/kind_box_req/delete.go +++ b/service/benefactor/kind_box_req/delete.go @@ -2,8 +2,9 @@ package userkindboxreqservice import ( "context" + "git.gocasts.ir/ebhomengo/niki/entity" + errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" - entity "git.gocasts.ir/ebhomengo/niki/entity" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) @@ -14,19 +15,19 @@ func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID) if gErr != nil { - return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected) + return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected) } - if kbr.Status != KindBoxReqPendingStatus { - return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid) + if kbr.Status != entity.KindBoxReqPendingStatus { + return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid) } - if kbr.BenefactorID != req.BenefactorID { - return param.KindBoxReqGetResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden) + if kbr.BenefactorID != req.BenfactorID { + return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden) } dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID) if dErr != nil { - return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) + return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected) } - return param.KindBoxReqDeleteResponse{KindBoxReq: kindBoxReq}, nil + return param.KindBoxReqDeleteResponse{}, nil } diff --git a/service/benefactor/kind_box_req/get.go b/service/benefactor/kind_box_req/get.go index bb3ee22..822f508 100644 --- a/service/benefactor/kind_box_req/get.go +++ b/service/benefactor/kind_box_req/get.go @@ -3,15 +3,15 @@ package userkindboxreqservice import ( "context" - entity "git.gocasts.ir/ebhomengo/niki/entity" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" + errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) { - + const op = "userkindboxreqservice.Get" - + kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID) if err != nil { return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) diff --git a/service/benefactor/kind_box_req/get_all.go b/service/benefactor/kind_box_req/get_all.go index 4d3074e..0be733c 100644 --- a/service/benefactor/kind_box_req/get_all.go +++ b/service/benefactor/kind_box_req/get_all.go @@ -8,14 +8,14 @@ import ( ) // TODO: Pagination, Filters, Sort -func (s Service) GetAll(ctx context.Context) (param.KindBoxReqGetAllResponse, error) { - +func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest) (param.KindBoxReqGetAllResponse, error) { + const op = "userkindboxreqservice.GetAll" allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx, req.BenefactorID) if err != nil { return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } - + return param.KindBoxReqGetAllResponse{AllKindBoxReq: allKindBoxReq}, nil } diff --git a/service/benefactor/kind_box_req/update.go b/service/benefactor/kind_box_req/update.go index da455c7..b5dd9f2 100644 --- a/service/benefactor/kind_box_req/update.go +++ b/service/benefactor/kind_box_req/update.go @@ -18,7 +18,7 @@ func (s Service) Update(ctx context.Context, req param.KindBoxReqUpdateRequest) if gErr != nil { return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected) } - if kbr.Status != KindBoxReqPendingStatus { + if kbr.Status != entity.KindBoxReqPendingStatus { return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid) }