2023-12-25 17:08:19 +00:00
|
|
|
package adminkindboxreqservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-12-26 20:01:45 +00:00
|
|
|
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
2023-12-26 17:52:20 +00:00
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
2023-12-26 20:01:45 +00:00
|
|
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
2023-12-25 17:08:19 +00:00
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s Service) Delete(ctx context.Context, req param.KindBoxReqDeleteRequest) (param.KindBoxReqDeleteResponse, error) {
|
2023-12-26 17:53:25 +00:00
|
|
|
// TODO: Does business domain need to delete an kindboxreq ?
|
2023-12-25 17:08:19 +00:00
|
|
|
const op = "adminkindboxreqservice.Delete"
|
|
|
|
|
2023-12-26 20:01:45 +00:00
|
|
|
kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
|
|
|
|
if gErr != nil {
|
|
|
|
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
|
|
|
if kbr.BenefactorID != req.BenefactorID {
|
|
|
|
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgUserNotAllowed).WithKind(richerror.KindForbidden)
|
|
|
|
}
|
2023-12-26 21:42:33 +00:00
|
|
|
if kbr.Status != entity.KindBoxReqPendingStatus {
|
|
|
|
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid)
|
|
|
|
}
|
2023-12-26 20:01:45 +00:00
|
|
|
|
2023-12-25 17:08:19 +00:00
|
|
|
dErr := s.repo.DeleteKindBoxReq(ctx, req.KindBoxReqID)
|
|
|
|
if dErr != nil {
|
2023-12-26 13:11:29 +00:00
|
|
|
return param.KindBoxReqDeleteResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected)
|
2023-12-25 17:08:19 +00:00
|
|
|
}
|
|
|
|
|
2023-12-26 13:11:29 +00:00
|
|
|
return param.KindBoxReqDeleteResponse{}, nil
|
2023-12-25 17:08:19 +00:00
|
|
|
}
|