From 27634049bbe9bd6f8b3fcc6c2cded73c040c9f5f Mon Sep 17 00:00:00 2001 From: imirazimi Date: Tue, 26 Dec 2023 23:31:45 +0330 Subject: [PATCH] fix(niki): fix typo Bugs --- param/admin/kind_box_req/delete.go | 1 + param/admin/kind_box_req/get.go | 1 + param/benefactor/kind_box_req/delete.go | 2 +- service/admin/kind_box_req/add.go | 15 ++++++++------- service/admin/kind_box_req/delete.go | 13 +++++++++++++ service/admin/kind_box_req/get.go | 5 +++++ service/admin/kind_box_req/service.go | 10 +++++----- service/benefactor/kind_box_req/delete.go | 4 ++-- 8 files changed, 36 insertions(+), 15 deletions(-) diff --git a/param/admin/kind_box_req/delete.go b/param/admin/kind_box_req/delete.go index 1126e74..20c9090 100644 --- a/param/admin/kind_box_req/delete.go +++ b/param/admin/kind_box_req/delete.go @@ -1,6 +1,7 @@ package adminkindboxreqparam type KindBoxReqDeleteRequest struct { + BenefactorID uint KindBoxReqID uint } diff --git a/param/admin/kind_box_req/get.go b/param/admin/kind_box_req/get.go index 2fdc4e6..e64c73a 100644 --- a/param/admin/kind_box_req/get.go +++ b/param/admin/kind_box_req/get.go @@ -3,6 +3,7 @@ package adminkindboxreqparam import entity "git.gocasts.ir/ebhomengo/niki/entity" type KindBoxReqGetRequest struct { + BenefactorID uint KindBoxReqID uint } diff --git a/param/benefactor/kind_box_req/delete.go b/param/benefactor/kind_box_req/delete.go index 51eabfc..d8dd89f 100644 --- a/param/benefactor/kind_box_req/delete.go +++ b/param/benefactor/kind_box_req/delete.go @@ -1,7 +1,7 @@ package userkindboxreqparam type KindBoxReqDeleteRequest struct { - BenfactorID uint + BenefactorID uint KindBoxReqID uint } diff --git a/service/admin/kind_box_req/add.go b/service/admin/kind_box_req/add.go index a0f651f..d16ad77 100644 --- a/service/admin/kind_box_req/add.go +++ b/service/admin/kind_box_req/add.go @@ -5,6 +5,7 @@ import ( entity "git.gocasts.ir/ebhomengo/niki/entity" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" + errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) @@ -12,13 +13,13 @@ func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param const op = "adminkindboxreqservice.Add" // TODO: check validation - // exist, err := s.benefactorService.IsBenefactorExist(ctx, req.BenefactorID) - //if err != nil { - // return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) - //} - //if !exist { - // return param.KindBoxReqAddResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotFound).WithKind(richerror.KindInvalid) - //} + kbr, err := s.repo.GetKindBoxReq(ctx, req.BenefactorID) + if err != nil { + return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) + } + if kbr.BenefactorID != req.BenefactorID { + return param.KindBoxReqAddResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotFound).WithKind(richerror.KindInvalid) + } kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{ BenefactorID: req.BenefactorID, diff --git a/service/admin/kind_box_req/delete.go b/service/admin/kind_box_req/delete.go index 7c99b55..d50a06f 100644 --- a/service/admin/kind_box_req/delete.go +++ b/service/admin/kind_box_req/delete.go @@ -3,7 +3,9 @@ package adminkindboxreqservice import ( "context" + entity "git.gocasts.ir/ebhomengo/niki/entity" param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" + errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) @@ -11,6 +13,17 @@ func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) // TODO: Does business domain need to delete an kindboxreq ? const op = "adminkindboxreqservice.Delete" + kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID) + if gErr != nil { + return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected) + } + if kbr.Status != entity.KindBoxReqPendingStatus { + return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid) + } + if kbr.BenefactorID != req.BenefactorID { + 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(dErr).WithKind(richerror.KindUnexpected) diff --git a/service/admin/kind_box_req/get.go b/service/admin/kind_box_req/get.go index f942444..b197da1 100644 --- a/service/admin/kind_box_req/get.go +++ b/service/admin/kind_box_req/get.go @@ -4,16 +4,21 @@ import ( "context" param "git.gocasts.ir/ebhomengo/niki/param/admin/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 = "adminkindboxreqservice.Get" + // TODO : ref to service.Update() kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID) if err != nil { return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } + if kindBoxReq.BenefactorID != req.BenefactorID { + return param.KindBoxReqGetResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden) + } return param.KindBoxReqGetResponse{KindBoxReq: kindBoxReq}, nil } diff --git a/service/admin/kind_box_req/service.go b/service/admin/kind_box_req/service.go index f0dde25..2b1c5ed 100644 --- a/service/admin/kind_box_req/service.go +++ b/service/admin/kind_box_req/service.go @@ -16,13 +16,13 @@ type Repository interface { } // TODO: check validation. -type BenefactorService interface { - IsBenefactorExist(ctx context.Context, benefactorID uint) (bool, error) -} +// type BenefactorService interface { +// IsBenefactorExist(ctx context.Context, benefactorID uint) (bool, error) +// } type Service struct { - repo Repository - benefactorService BenefactorService + repo Repository + // benefactorService BenefactorService } func New(repository Repository) Service { diff --git a/service/benefactor/kind_box_req/delete.go b/service/benefactor/kind_box_req/delete.go index bc8aac4..c8bf1a6 100644 --- a/service/benefactor/kind_box_req/delete.go +++ b/service/benefactor/kind_box_req/delete.go @@ -3,7 +3,7 @@ package userkindboxreqservice import ( "context" - "git.gocasts.ir/ebhomengo/niki/entity" + 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" @@ -20,7 +20,7 @@ func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) if kbr.Status != entity.KindBoxReqPendingStatus { return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid) } - if kbr.BenefactorID != req.BenfactorID { + if kbr.BenefactorID != req.BenefactorID { return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden) }