forked from ebhomengo/niki
fix(service): complete admin kindboxreq service
This commit is contained in:
parent
3e0e8567eb
commit
9674f61402
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -2,9 +2,8 @@ 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"
|
||||
)
|
||||
|
||||
|
@ -12,6 +11,15 @@ func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param
|
|||
|
||||
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,
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
package kind_box
|
Loading…
Reference in New Issue