forked from ebhomengo/niki
fix(niki): fix typo Bugs
This commit is contained in:
parent
199be38efd
commit
27634049bb
|
@ -1,6 +1,7 @@
|
|||
package adminkindboxreqparam
|
||||
|
||||
type KindBoxReqDeleteRequest struct {
|
||||
BenefactorID uint
|
||||
KindBoxReqID uint
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package adminkindboxreqparam
|
|||
import entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
|
||||
type KindBoxReqGetRequest struct {
|
||||
BenefactorID uint
|
||||
KindBoxReqID uint
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package userkindboxreqparam
|
||||
|
||||
type KindBoxReqDeleteRequest struct {
|
||||
BenfactorID uint
|
||||
BenefactorID uint
|
||||
KindBoxReqID uint
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
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"
|
||||
)
|
||||
|
||||
|
@ -12,13 +13,13 @@ 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)
|
||||
//}
|
||||
kbr, err := s.repo.GetKindBoxReq(ctx, req.BenefactorID)
|
||||
if err != nil {
|
||||
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
if kbr.BenefactorID != req.BenefactorID {
|
||||
return param.KindBoxReqAddResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotFound).WithKind(richerror.KindInvalid)
|
||||
}
|
||||
|
||||
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
|
||||
BenefactorID: req.BenefactorID,
|
||||
|
|
|
@ -3,7 +3,9 @@ package adminkindboxreqservice
|
|||
import (
|
||||
"context"
|
||||
|
||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
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"
|
||||
)
|
||||
|
||||
|
@ -11,6 +13,17 @@ func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest)
|
|||
// TODO: Does business domain need to delete an kindboxreq ?
|
||||
const op = "adminkindboxreqservice.Delete"
|
||||
|
||||
kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
|
||||
if gErr != nil {
|
||||
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
if kbr.Status != entity.KindBoxReqPendingStatus {
|
||||
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid)
|
||||
}
|
||||
if kbr.BenefactorID != req.BenefactorID {
|
||||
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden)
|
||||
}
|
||||
|
||||
dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID)
|
||||
if dErr != nil {
|
||||
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected)
|
||||
|
|
|
@ -4,16 +4,21 @@ import (
|
|||
"context"
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) {
|
||||
const op = "adminkindboxreqservice.Get"
|
||||
|
||||
// TODO : ref to service.Update()
|
||||
kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
|
||||
if err != nil {
|
||||
return param.KindBoxReqGetResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
if kindBoxReq.BenefactorID != req.BenefactorID {
|
||||
return param.KindBoxReqGetResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden)
|
||||
}
|
||||
|
||||
return param.KindBoxReqGetResponse{KindBoxReq: kindBoxReq}, nil
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@ type Repository interface {
|
|||
}
|
||||
|
||||
// TODO: check validation.
|
||||
type BenefactorService interface {
|
||||
IsBenefactorExist(ctx context.Context, benefactorID uint) (bool, error)
|
||||
}
|
||||
// type BenefactorService interface {
|
||||
// IsBenefactorExist(ctx context.Context, benefactorID uint) (bool, error)
|
||||
// }
|
||||
|
||||
type Service struct {
|
||||
repo Repository
|
||||
benefactorService BenefactorService
|
||||
// benefactorService BenefactorService
|
||||
}
|
||||
|
||||
func New(repository Repository) Service {
|
||||
|
|
|
@ -3,7 +3,7 @@ package userkindboxreqservice
|
|||
import (
|
||||
"context"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
entity "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"
|
||||
|
@ -20,7 +20,7 @@ func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest)
|
|||
if kbr.Status != entity.KindBoxReqPendingStatus {
|
||||
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid)
|
||||
}
|
||||
if kbr.BenefactorID != req.BenfactorID {
|
||||
if kbr.BenefactorID != req.BenefactorID {
|
||||
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue