From 9674f61402197cfb709ae81bce4b985d319c25fa Mon Sep 17 00:00:00 2001 From: masoodk Date: Tue, 26 Dec 2023 21:22:20 +0330 Subject: [PATCH] fix(service): complete admin kindboxreq service --- param/benefactor/kind_box/get.go | 12 ++++++++++++ param/benefactor/kind_box/get_all.go | 11 +++++++++++ service/admin/kind_box_req/add.go | 14 +++++++++++--- service/admin/kind_box_req/delete.go | 2 +- service/admin/kind_box_req/get.go | 2 +- service/admin/kind_box_req/get_all.go | 6 +++--- service/admin/kind_box_req/service.go | 8 +++++++- service/admin/kind_box_req/update.go | 2 +- service/benefactor/kind_box/get.go | 25 +++++++++++++++++++++++++ service/benefactor/kind_box/get_all.go | 21 +++++++++++++++++++++ service/benefactor/kind_box/service.go | 1 + 11 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 param/benefactor/kind_box/get.go create mode 100644 param/benefactor/kind_box/get_all.go create mode 100644 service/benefactor/kind_box/get.go create mode 100644 service/benefactor/kind_box/get_all.go create mode 100644 service/benefactor/kind_box/service.go diff --git a/param/benefactor/kind_box/get.go b/param/benefactor/kind_box/get.go new file mode 100644 index 0000000..3feb856 --- /dev/null +++ b/param/benefactor/kind_box/get.go @@ -0,0 +1,12 @@ +package userkindboxreqparam + +import entity "git.gocasts.ir/ebhomengo/niki/entity" + +type KindBoxReqGetRequest struct { + BenefactorID uint + KindBoxReqID uint +} + +type KindBoxReqGetResponse struct { + entity.KindBoxReq +} diff --git a/param/benefactor/kind_box/get_all.go b/param/benefactor/kind_box/get_all.go new file mode 100644 index 0000000..be4b653 --- /dev/null +++ b/param/benefactor/kind_box/get_all.go @@ -0,0 +1,11 @@ +package userkindboxreqparam + +import entity "git.gocasts.ir/ebhomengo/niki/entity" + +type KindBoxReqGetAllRequest struct { + BenefactorID uint +} + +type KindBoxReqGetAllResponse struct { + AllKindBoxReq []entity.KindBoxReq +} diff --git a/service/admin/kind_box_req/add.go b/service/admin/kind_box_req/add.go index e3baf1c..4f337df 100644 --- a/service/admin/kind_box_req/add.go +++ b/service/admin/kind_box_req/add.go @@ -2,16 +2,24 @@ package adminkindboxreqservice import ( "context" - entity "git.gocasts.ir/ebhomengo/niki/entity" - param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) { - + 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) + //} + kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{ BenefactorID: req.BenefactorID, TypeID: req.TypeID, diff --git a/service/admin/kind_box_req/delete.go b/service/admin/kind_box_req/delete.go index 648e4a9..87e9c73 100644 --- a/service/admin/kind_box_req/delete.go +++ b/service/admin/kind_box_req/delete.go @@ -3,7 +3,7 @@ package adminkindboxreqservice import ( "context" - param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) diff --git a/service/admin/kind_box_req/get.go b/service/admin/kind_box_req/get.go index 68cd332..94283dd 100644 --- a/service/admin/kind_box_req/get.go +++ b/service/admin/kind_box_req/get.go @@ -3,7 +3,7 @@ package adminkindboxreqservice import ( "context" - param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) diff --git a/service/admin/kind_box_req/get_all.go b/service/admin/kind_box_req/get_all.go index 1ca290b..1c905d7 100644 --- a/service/admin/kind_box_req/get_all.go +++ b/service/admin/kind_box_req/get_all.go @@ -3,19 +3,19 @@ package adminkindboxreqservice import ( "context" - param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) // TODO: Pagination, Filters, Sort func (s Service) GetAll(ctx context.Context) (param.KindBoxReqGetAllResponse, error) { - + const op = "adminkindboxreqservice.GetAll" allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx) if err != nil { return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } - + return param.KindBoxReqGetAllResponse{AllKindBoxReq: allKindBoxReq}, nil } diff --git a/service/admin/kind_box_req/service.go b/service/admin/kind_box_req/service.go index ab60a90..f0b328c 100644 --- a/service/admin/kind_box_req/service.go +++ b/service/admin/kind_box_req/service.go @@ -15,8 +15,14 @@ type Repository interface { GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error) } +// TODO: check validation +type BenefactorService interface { + IsBenefactorExist(ctx context.Context, benefactorID uint) (bool, error) +} + type Service struct { - repo Repository + repo Repository + benefactorService BenefactorService } func New(repository Repository) Service { diff --git a/service/admin/kind_box_req/update.go b/service/admin/kind_box_req/update.go index 66c9cd5..fc53bd3 100644 --- a/service/admin/kind_box_req/update.go +++ b/service/admin/kind_box_req/update.go @@ -4,7 +4,7 @@ import ( "context" entity "git.gocasts.ir/ebhomengo/niki/entity" - param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" + 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" ) diff --git a/service/benefactor/kind_box/get.go b/service/benefactor/kind_box/get.go new file mode 100644 index 0000000..822f508 --- /dev/null +++ b/service/benefactor/kind_box/get.go @@ -0,0 +1,25 @@ +package userkindboxreqservice + +import ( + "context" + + 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) + } + // TODO : ref to service.Update() + 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/benefactor/kind_box/get_all.go b/service/benefactor/kind_box/get_all.go new file mode 100644 index 0000000..0be733c --- /dev/null +++ b/service/benefactor/kind_box/get_all.go @@ -0,0 +1,21 @@ +package userkindboxreqservice + +import ( + "context" + + param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" + richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" +) + +// TODO: Pagination, Filters, Sort +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/service.go b/service/benefactor/kind_box/service.go new file mode 100644 index 0000000..07b75a0 --- /dev/null +++ b/service/benefactor/kind_box/service.go @@ -0,0 +1 @@ +package kind_box