fix(niki): fix typo Bugs

This commit is contained in:
imirazimi 2023-12-26 23:31:45 +03:30
parent 199be38efd
commit 27634049bb
8 changed files with 36 additions and 15 deletions

View File

@ -1,6 +1,7 @@
package adminkindboxreqparam package adminkindboxreqparam
type KindBoxReqDeleteRequest struct { type KindBoxReqDeleteRequest struct {
BenefactorID uint
KindBoxReqID uint KindBoxReqID uint
} }

View File

@ -3,6 +3,7 @@ package adminkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqGetRequest struct { type KindBoxReqGetRequest struct {
BenefactorID uint
KindBoxReqID uint KindBoxReqID uint
} }

View File

@ -1,7 +1,7 @@
package userkindboxreqparam package userkindboxreqparam
type KindBoxReqDeleteRequest struct { type KindBoxReqDeleteRequest struct {
BenfactorID uint BenefactorID uint
KindBoxReqID uint KindBoxReqID uint
} }

View File

@ -5,6 +5,7 @@ import (
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"
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"
) )
@ -12,13 +13,13 @@ func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param
const op = "adminkindboxreqservice.Add" const op = "adminkindboxreqservice.Add"
// TODO: check validation // TODO: check validation
// exist, err := s.benefactorService.IsBenefactorExist(ctx, req.BenefactorID) kbr, err := s.repo.GetKindBoxReq(ctx, req.BenefactorID)
//if err != nil { if err != nil {
// return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
//} }
//if !exist { if kbr.BenefactorID != req.BenefactorID {
// return param.KindBoxReqAddResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotFound).WithKind(richerror.KindInvalid) return param.KindBoxReqAddResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotFound).WithKind(richerror.KindInvalid)
//} }
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{ kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
BenefactorID: req.BenefactorID, BenefactorID: req.BenefactorID,

View File

@ -3,7 +3,9 @@ package adminkindboxreqservice
import ( import (
"context" "context"
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"
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"
) )
@ -11,6 +13,17 @@ func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest)
// TODO: Does business domain need to delete an kindboxreq ? // TODO: Does business domain need to delete an kindboxreq ?
const op = "adminkindboxreqservice.Delete" 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) dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID)
if dErr != nil { if dErr != nil {
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected) return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected)

View File

@ -4,16 +4,21 @@ import (
"context" "context"
param "git.gocasts.ir/ebhomengo/niki/param/admin/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" 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.KindBoxReqGetRequest) (param.KindBoxReqGetResponse, error) {
const op = "adminkindboxreqservice.Get" const op = "adminkindboxreqservice.Get"
// TODO : ref to service.Update()
kindBoxReq, err := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID) 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.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 return param.KindBoxReqGetResponse{KindBoxReq: kindBoxReq}, nil
} }

View File

@ -16,13 +16,13 @@ type Repository interface {
} }
// 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)
} // }
type Service struct { type Service struct {
repo Repository repo Repository
benefactorService BenefactorService // benefactorService BenefactorService
} }
func New(repository Repository) Service { func New(repository Repository) Service {

View File

@ -3,7 +3,7 @@ package userkindboxreqservice
import ( import (
"context" "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" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
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"
@ -20,7 +20,7 @@ func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest)
if kbr.Status != entity.KindBoxReqPendingStatus { if kbr.Status != entity.KindBoxReqPendingStatus {
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid) 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) return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden)
} }