niki/service/admin/kind_box/add.go

32 lines
1.0 KiB
Go

package adminkindboxservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
"github.com/oklog/ulid/v2"
)
func (s Service) AddKindBoxAfterAcceptingRequest(ctx context.Context, req param.KindBoxAddAfterAcceptingReqRequest) (param.KindBoxAddAfterAcceptingReqResponse, error) {
const op = "adminkindboxservice.AddKindBoxAfterAcceptingRequest"
var kindBoxes []entity.KindBox
for i := 0; i < int(req.Count); i++ {
kindBoxes = append(kindBoxes, entity.KindBox{
KindBoxReqID: req.KindBoxReqID,
BenefactorID: req.BenefactorID,
Type: req.Type,
Status: entity.KindBoxPendingSendStatus,
SerialNumber: ulid.Make().String(),
})
}
err := s.repo.AddBatchKindBox(ctx, kindBoxes)
if err != nil {
return param.KindBoxAddAfterAcceptingReqResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
}
return param.KindBoxAddAfterAcceptingReqResponse{}, nil
}