feat(service): add benefactor kindbox service

This commit is contained in:
Masood Keshvari 2023-12-26 21:23:25 +03:30
parent 9674f61402
commit 199be38efd
17 changed files with 62 additions and 45 deletions

View File

@ -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

View File

@ -7,7 +7,7 @@ type KindBoxUpdateRequest struct {
ReceiverID uint
SenderID uint
SerialNumber string
Status KindBoxStatus
Status entity.KindBoxStatus
}
type KindBoxUpdateResponse struct {

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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 (

View File

@ -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)
//}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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,
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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)