From 199be38efdf6c8aba4ba5f84ced7b25d4d60ce5d Mon Sep 17 00:00:00 2001 From: masoodk Date: Tue, 26 Dec 2023 21:23:25 +0330 Subject: [PATCH] feat(service): add benefactor kindbox service --- entity/kind_box.go | 3 ++- param/admin/kind_box/update.go | 2 +- param/admin/kind_box_req/get_all.go | 2 +- param/benefactor/kind_box/get.go | 10 +++++----- param/benefactor/kind_box/get_all.go | 8 ++++---- pkg/err_msg/message.go | 1 + service/admin/kind_box_req/add.go | 4 ++-- service/admin/kind_box_req/delete.go | 2 +- service/admin/kind_box_req/get.go | 1 - service/admin/kind_box_req/get_all.go | 3 +-- service/admin/kind_box_req/service.go | 2 +- service/benefactor/kind_box/get.go | 19 +++++++++--------- service/benefactor/kind_box/get_all.go | 17 ++++++++-------- service/benefactor/kind_box/service.go | 23 +++++++++++++++++++++- service/benefactor/kind_box_req/delete.go | 6 +++--- service/benefactor/kind_box_req/get.go | 1 - service/benefactor/kind_box_req/get_all.go | 3 +-- 17 files changed, 62 insertions(+), 45 deletions(-) diff --git a/entity/kind_box.go b/entity/kind_box.go index 88135dd..589dcc5 100644 --- a/entity/kind_box.go +++ b/entity/kind_box.go @@ -4,7 +4,8 @@ import "time" type KindBox struct { ID uint - KindBoxReqID uint + KindBoxReqID uint // TODO like database model + BenefactorID uint // TODO need in business entity TotalAmount uint ReceiverID uint SenderID uint diff --git a/param/admin/kind_box/update.go b/param/admin/kind_box/update.go index b2358ce..ea69a25 100644 --- a/param/admin/kind_box/update.go +++ b/param/admin/kind_box/update.go @@ -7,7 +7,7 @@ type KindBoxUpdateRequest struct { ReceiverID uint SenderID uint SerialNumber string - Status KindBoxStatus + Status entity.KindBoxStatus } type KindBoxUpdateResponse struct { diff --git a/param/admin/kind_box_req/get_all.go b/param/admin/kind_box_req/get_all.go index 98f3eb8..5ac6c4c 100644 --- a/param/admin/kind_box_req/get_all.go +++ b/param/admin/kind_box_req/get_all.go @@ -2,7 +2,7 @@ package adminkindboxreqparam import entity "git.gocasts.ir/ebhomengo/niki/entity" -type KindBoxReqGetAllRequest struct {} +type KindBoxReqGetAllRequest struct{} type KindBoxReqGetAllResponse struct { AllKindBoxReq []entity.KindBoxReq diff --git a/param/benefactor/kind_box/get.go b/param/benefactor/kind_box/get.go index 3feb856..c4ced5b 100644 --- a/param/benefactor/kind_box/get.go +++ b/param/benefactor/kind_box/get.go @@ -1,12 +1,12 @@ -package userkindboxreqparam +package userkindboxparam import entity "git.gocasts.ir/ebhomengo/niki/entity" -type KindBoxReqGetRequest struct { +type KindBoxGetRequest struct { BenefactorID uint - KindBoxReqID uint + KindBoxID uint } -type KindBoxReqGetResponse struct { - entity.KindBoxReq +type KindBoxGetResponse struct { + entity.KindBox } diff --git a/param/benefactor/kind_box/get_all.go b/param/benefactor/kind_box/get_all.go index be4b653..35d7775 100644 --- a/param/benefactor/kind_box/get_all.go +++ b/param/benefactor/kind_box/get_all.go @@ -1,11 +1,11 @@ -package userkindboxreqparam +package userkindboxparam import entity "git.gocasts.ir/ebhomengo/niki/entity" -type KindBoxReqGetAllRequest struct { +type KindBoxGetAllRequest struct { BenefactorID uint } -type KindBoxReqGetAllResponse struct { - AllKindBoxReq []entity.KindBoxReq +type KindBoxGetAllResponse struct { + AllKindBox []entity.KindBox } diff --git a/pkg/err_msg/message.go b/pkg/err_msg/message.go index 20a4e62..ac57851 100644 --- a/pkg/err_msg/message.go +++ b/pkg/err_msg/message.go @@ -8,6 +8,7 @@ const ( ErrorMsgPhoneNumberIsNotUnique = "phone number is not unique" ErrorMsgPhoneNumberIsNotValid = "phone number is not valid" ErrorMsgUserNotAllowed = "user not allowed" + ErrorMsgUserNotFound = "benefactor not found" ) // const ( diff --git a/service/admin/kind_box_req/add.go b/service/admin/kind_box_req/add.go index 4f337df..a0f651f 100644 --- a/service/admin/kind_box_req/add.go +++ b/service/admin/kind_box_req/add.go @@ -2,17 +2,17 @@ package adminkindboxreqservice import ( "context" + entity "git.gocasts.ir/ebhomengo/niki/entity" 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) + // exist, err := s.benefactorService.IsBenefactorExist(ctx, req.BenefactorID) //if err != nil { // return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) //} diff --git a/service/admin/kind_box_req/delete.go b/service/admin/kind_box_req/delete.go index 87e9c73..7c99b55 100644 --- a/service/admin/kind_box_req/delete.go +++ b/service/admin/kind_box_req/delete.go @@ -8,7 +8,7 @@ import ( ) func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) (param.KindBoxReqDeleteResponse, error) { - //TODO: Does bussiness domain need to delete an kindboxreq ? + // TODO: Does business domain need to delete an kindboxreq ? const op = "adminkindboxreqservice.Delete" dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID) diff --git a/service/admin/kind_box_req/get.go b/service/admin/kind_box_req/get.go index 94283dd..f942444 100644 --- a/service/admin/kind_box_req/get.go +++ b/service/admin/kind_box_req/get.go @@ -8,7 +8,6 @@ import ( ) 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) diff --git a/service/admin/kind_box_req/get_all.go b/service/admin/kind_box_req/get_all.go index 1c905d7..6c9e85d 100644 --- a/service/admin/kind_box_req/get_all.go +++ b/service/admin/kind_box_req/get_all.go @@ -7,9 +7,8 @@ import ( richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) -// TODO: Pagination, Filters, Sort +// TODO: Pagination, Filters, Sort. func (s Service) GetAll(ctx context.Context) (param.KindBoxReqGetAllResponse, error) { - const op = "adminkindboxreqservice.GetAll" allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx) diff --git a/service/admin/kind_box_req/service.go b/service/admin/kind_box_req/service.go index f0b328c..f0dde25 100644 --- a/service/admin/kind_box_req/service.go +++ b/service/admin/kind_box_req/service.go @@ -15,7 +15,7 @@ type Repository interface { GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error) } -// TODO: check validation +// TODO: check validation. type BenefactorService interface { IsBenefactorExist(ctx context.Context, benefactorID uint) (bool, error) } diff --git a/service/benefactor/kind_box/get.go b/service/benefactor/kind_box/get.go index 822f508..f4ee87e 100644 --- a/service/benefactor/kind_box/get.go +++ b/service/benefactor/kind_box/get.go @@ -1,25 +1,24 @@ -package userkindboxreqservice +package userkindboxservice import ( "context" - param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box" 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) { +func (s Service) Get(ctx context.Context, req param.KindBoxGetRequest) (param.KindBoxGetResponse, error) { + const op = "userkindboxservice.Get" - const op = "userkindboxreqservice.Get" - - kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID) + kindBox, err := s.repo.GetKindBox(ctx, req.KindBoxID) if err != nil { - return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) + return param.KindBoxGetResponse{}, 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) + if kindBox.BenefactorID != req.BenefactorID { + return param.KindBoxGetResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden) } - return param.KindBoxReqGetResponse{KindBoxReq: kindBoxReq}, nil + return param.KindBoxGetResponse{KindBox: kindBox}, nil } diff --git a/service/benefactor/kind_box/get_all.go b/service/benefactor/kind_box/get_all.go index 0be733c..9ed7b0e 100644 --- a/service/benefactor/kind_box/get_all.go +++ b/service/benefactor/kind_box/get_all.go @@ -1,21 +1,20 @@ -package userkindboxreqservice +package userkindboxservice import ( "context" - param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box" 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) { +// TODO: Pagination, Filters, Sort. +func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (param.KindBoxGetAllResponse, error) { + const op = "userkindboxservice.GetAll" - const op = "userkindboxreqservice.GetAll" - - allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx, req.BenefactorID) + allKindBox, err := s.repo.GetAllKindBox(ctx, req.BenefactorID) if err != nil { - return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) + return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } - return param.KindBoxReqGetAllResponse{AllKindBoxReq: allKindBoxReq}, nil + return param.KindBoxGetAllResponse{AllKindBox: allKindBox}, nil } diff --git a/service/benefactor/kind_box/service.go b/service/benefactor/kind_box/service.go index 07b75a0..35d78e1 100644 --- a/service/benefactor/kind_box/service.go +++ b/service/benefactor/kind_box/service.go @@ -1 +1,22 @@ -package kind_box +package userkindboxservice + +import ( + "context" + + entity "git.gocasts.ir/ebhomengo/niki/entity" +) + +type Repository interface { + GetAllKindBox(ctx context.Context, benefactorID uint) ([]entity.KindBox, error) + GetKindBox(ctx context.Context, kindBoxID uint) (entity.KindBox, error) +} + +type Service struct { + repo Repository +} + +func New(repository Repository) Service { + return Service{ + repo: repository, + } +} diff --git a/service/benefactor/kind_box_req/delete.go b/service/benefactor/kind_box_req/delete.go index f1c2d9b..bc8aac4 100644 --- a/service/benefactor/kind_box_req/delete.go +++ b/service/benefactor/kind_box_req/delete.go @@ -2,15 +2,15 @@ package userkindboxreqservice import ( "context" - "git.gocasts.ir/ebhomengo/niki/entity" - errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" + "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) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) (param.KindBoxReqDeleteResponse, error) { - //TODO: Does bussiness domain need to delete an kindboxreq ? + // TODO: Does business domain need to delete an kindboxreq ? const op = "userkindboxreqservice.Delete" kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID) diff --git a/service/benefactor/kind_box_req/get.go b/service/benefactor/kind_box_req/get.go index 822f508..8ad0d20 100644 --- a/service/benefactor/kind_box_req/get.go +++ b/service/benefactor/kind_box_req/get.go @@ -9,7 +9,6 @@ import ( ) 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) diff --git a/service/benefactor/kind_box_req/get_all.go b/service/benefactor/kind_box_req/get_all.go index 0be733c..9b7ce79 100644 --- a/service/benefactor/kind_box_req/get_all.go +++ b/service/benefactor/kind_box_req/get_all.go @@ -7,9 +7,8 @@ import ( richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) -// TODO: Pagination, Filters, Sort +// 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)