niki/service/admin/kind_box/add.go

32 lines
1.0 KiB
Go
Raw Normal View History

2023-12-25 17:08:19 +00:00
package adminkindboxservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
2023-12-25 17:08:19 +00:00
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)
}
2024-01-01 07:22:14 +00:00
return param.KindBoxAddAfterAcceptingReqResponse{}, nil
}