fix(service): complete admin kindboxreq service

This commit is contained in:
Masood Keshvari 2023-12-26 21:22:20 +03:30
parent 3e0e8567eb
commit 9674f61402
11 changed files with 94 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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
benefactorService BenefactorService
}
func New(repository Repository) Service {

View File

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

View File

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

View File

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

View File

@ -0,0 +1 @@
package kind_box