diff --git a/entity/kind_box.go b/entity/kind_box.go index 88135dd5..589dcc57 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 b2358ce3..ea69a25b 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 98f3eb8b..5ac6c4c9 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 3feb8561..c4ced5be 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 be4b6534..35d7775b 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 20a4e621..ac578510 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 4f337df6..a0f651f2 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 87e9c73d..7c99b555 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 94283ddb..f9424444 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 1c905d72..6c9e85d3 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 f0b328ce..f0dde253 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 822f5083..f4ee87e2 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 0be733c1..9ed7b0ef 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 07b75a09..35d78e18 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 f1c2d9bd..bc8aac40 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 822f5083..8ad0d203 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 0be733c1..9b7ce794 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)