2023-12-25 17:08:19 +00:00
|
|
|
package adminkindboxreqservice
|
2023-12-20 08:27:13 +00:00
|
|
|
|
|
|
|
import (
|
2023-12-22 21:42:57 +00:00
|
|
|
"context"
|
2023-12-26 17:53:25 +00:00
|
|
|
|
2023-12-22 21:25:16 +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-22 21:25:16 +00:00
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
2023-12-20 08:27:13 +00:00
|
|
|
)
|
|
|
|
|
2023-12-22 21:42:57 +00:00
|
|
|
func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) {
|
2023-12-25 17:08:19 +00:00
|
|
|
const op = "adminkindboxreqservice.Add"
|
|
|
|
|
2023-12-26 17:52:20 +00:00
|
|
|
// TODO: check validation
|
2023-12-26 20:01:45 +00:00
|
|
|
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)
|
|
|
|
}
|
2023-12-26 17:52:20 +00:00
|
|
|
|
2023-12-22 21:42:57 +00:00
|
|
|
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
|
2023-12-25 17:08:19 +00:00
|
|
|
BenefactorID: req.BenefactorID,
|
2023-12-22 21:25:16 +00:00
|
|
|
TypeID: req.TypeID,
|
|
|
|
CountRequested: req.CountRequested,
|
|
|
|
Status: entity.KindBoxReqPendingStatus,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
2023-12-25 17:08:19 +00:00
|
|
|
|
2023-12-22 21:25:16 +00:00
|
|
|
return param.KindBoxReqAddResponse{KindBoxReq: kindBoxReq}, nil
|
2023-12-20 08:27:13 +00:00
|
|
|
}
|