forked from ebhomengo/niki
				
			feat(service): add benefactor kindbox service
This commit is contained in:
		
							parent
							
								
									9674f61402
								
							
						
					
					
						commit
						199be38efd
					
				| 
						 | 
					@ -4,7 +4,8 @@ import "time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type KindBox struct {
 | 
					type KindBox struct {
 | 
				
			||||||
	ID              uint
 | 
						ID              uint
 | 
				
			||||||
	KindBoxReqID    uint
 | 
						KindBoxReqID    uint // TODO like database model
 | 
				
			||||||
 | 
						BenefactorID    uint // TODO need in business entity
 | 
				
			||||||
	TotalAmount     uint
 | 
						TotalAmount     uint
 | 
				
			||||||
	ReceiverID      uint
 | 
						ReceiverID      uint
 | 
				
			||||||
	SenderID        uint
 | 
						SenderID        uint
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,7 +7,7 @@ type KindBoxUpdateRequest struct {
 | 
				
			||||||
	ReceiverID   uint
 | 
						ReceiverID   uint
 | 
				
			||||||
	SenderID     uint
 | 
						SenderID     uint
 | 
				
			||||||
	SerialNumber string
 | 
						SerialNumber string
 | 
				
			||||||
	Status       KindBoxStatus
 | 
						Status       entity.KindBoxStatus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type KindBoxUpdateResponse struct {
 | 
					type KindBoxUpdateResponse struct {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,12 +1,12 @@
 | 
				
			||||||
package userkindboxreqparam
 | 
					package userkindboxparam
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import entity "git.gocasts.ir/ebhomengo/niki/entity"
 | 
					import entity "git.gocasts.ir/ebhomengo/niki/entity"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type KindBoxReqGetRequest struct {
 | 
					type KindBoxGetRequest struct {
 | 
				
			||||||
	BenefactorID uint
 | 
						BenefactorID uint
 | 
				
			||||||
	KindBoxReqID uint
 | 
						KindBoxID    uint
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type KindBoxReqGetResponse struct {
 | 
					type KindBoxGetResponse struct {
 | 
				
			||||||
	entity.KindBoxReq
 | 
						entity.KindBox
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,11 @@
 | 
				
			||||||
package userkindboxreqparam
 | 
					package userkindboxparam
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import entity "git.gocasts.ir/ebhomengo/niki/entity"
 | 
					import entity "git.gocasts.ir/ebhomengo/niki/entity"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type KindBoxReqGetAllRequest struct {
 | 
					type KindBoxGetAllRequest struct {
 | 
				
			||||||
	BenefactorID uint
 | 
						BenefactorID uint
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type KindBoxReqGetAllResponse struct {
 | 
					type KindBoxGetAllResponse struct {
 | 
				
			||||||
	AllKindBoxReq []entity.KindBoxReq
 | 
						AllKindBox []entity.KindBox
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ const (
 | 
				
			||||||
	ErrorMsgPhoneNumberIsNotUnique = "phone number is not unique"
 | 
						ErrorMsgPhoneNumberIsNotUnique = "phone number is not unique"
 | 
				
			||||||
	ErrorMsgPhoneNumberIsNotValid  = "phone number is not valid"
 | 
						ErrorMsgPhoneNumberIsNotValid  = "phone number is not valid"
 | 
				
			||||||
	ErrorMsgUserNotAllowed         = "user not allowed"
 | 
						ErrorMsgUserNotAllowed         = "user not allowed"
 | 
				
			||||||
 | 
						ErrorMsgUserNotFound           = "benefactor not found"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// const (
 | 
					// const (
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,13 +2,13 @@ package adminkindboxreqservice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	entity "git.gocasts.ir/ebhomengo/niki/entity"
 | 
						entity "git.gocasts.ir/ebhomengo/niki/entity"
 | 
				
			||||||
	param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
 | 
						param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
 | 
				
			||||||
	richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
						richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) {
 | 
					func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	const op = "adminkindboxreqservice.Add"
 | 
						const op = "adminkindboxreqservice.Add"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO: check validation
 | 
						// TODO: check validation
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,7 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) (param.KindBoxReqDeleteResponse, 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 = "adminkindboxreqservice.Delete"
 | 
						const op = "adminkindboxreqservice.Delete"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID)
 | 
						dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,6 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) {
 | 
					func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	const op = "adminkindboxreqservice.Get"
 | 
						const op = "adminkindboxreqservice.Get"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
 | 
						kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,9 +7,8 @@ import (
 | 
				
			||||||
	richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
						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) {
 | 
					func (s Service) GetAll(ctx context.Context) (param.KindBoxReqGetAllResponse, error) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	const op = "adminkindboxreqservice.GetAll"
 | 
						const op = "adminkindboxreqservice.GetAll"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx)
 | 
						allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ type Repository interface {
 | 
				
			||||||
	GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error)
 | 
						GetKindBoxReq(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: check validation
 | 
					// TODO: check validation.
 | 
				
			||||||
type BenefactorService interface {
 | 
					type BenefactorService interface {
 | 
				
			||||||
	IsBenefactorExist(ctx context.Context, benefactorID uint) (bool, error)
 | 
						IsBenefactorExist(ctx context.Context, benefactorID uint) (bool, error)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,25 +1,24 @@
 | 
				
			||||||
package userkindboxreqservice
 | 
					package userkindboxservice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"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"
 | 
						errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
 | 
				
			||||||
	richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
						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"
 | 
						kindBox, err := s.repo.GetKindBox(ctx, req.KindBoxID)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						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()
 | 
						// TODO : ref to service.Update()
 | 
				
			||||||
	if kindBoxReq.BenefactorID != req.BenefactorID {
 | 
						if kindBox.BenefactorID != req.BenefactorID {
 | 
				
			||||||
		return param.KindBoxReqGetResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden)
 | 
							return param.KindBoxGetResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return param.KindBoxReqGetResponse{KindBoxReq: kindBoxReq}, nil
 | 
						return param.KindBoxGetResponse{KindBox: kindBox}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,21 +1,20 @@
 | 
				
			||||||
package userkindboxreqservice
 | 
					package userkindboxservice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"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"
 | 
						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) {
 | 
					func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (param.KindBoxGetAllResponse, error) {
 | 
				
			||||||
 | 
						const op = "userkindboxservice.GetAll"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const op = "userkindboxreqservice.GetAll"
 | 
						allKindBox, err := s.repo.GetAllKindBox(ctx, req.BenefactorID)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx, req.BenefactorID)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						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
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,15 +2,15 @@ package userkindboxreqservice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"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"
 | 
						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"
 | 
						richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) (param.KindBoxReqDeleteResponse, 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"
 | 
						const op = "userkindboxreqservice.Delete"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
 | 
						kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,6 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) {
 | 
					func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	const op = "userkindboxreqservice.Get"
 | 
						const op = "userkindboxreqservice.Get"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
 | 
						kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,9 +7,8 @@ import (
 | 
				
			||||||
	richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
 | 
						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) {
 | 
					func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest) (param.KindBoxReqGetAllResponse, error) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	const op = "userkindboxreqservice.GetAll"
 | 
						const op = "userkindboxreqservice.GetAll"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx, req.BenefactorID)
 | 
						allKindBoxReq, err := s.repo.GetAllKindBoxReq(ctx, req.BenefactorID)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue