forked from ebhomengo/niki
1
0
Fork 0
niki/service/admin/kind_box/add.go

39 lines
1.2 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"
)
func (s Service) AddBatchKindBox(ctx context.Context, req param.AddKindBoxRequest) (param.AddKindBoxResponse, error) {
const op = "adminkindboxservice.AddKindBox"
kindBoxes := make([]entity.KindBox, 0)
for i := 0; i < int(req.CountAccepted); i++ {
kb := entity.KindBox{
KindBoxReqID: req.KindBoxReqID,
BenefactorID: req.BenefactorID,
KindBoxType: req.Type,
DeliverReferTimeID: req.DeliverReferTimeID,
DeliverReferDate: req.DeliverReferDate,
DeliverAddressID: req.DeliverAddressID,
DeliveredAt: req.DeliveredAt,
SenderAgentID: req.SenderAgentID,
Status: entity.KindBoxDeliveredStatus,
}
if i < len(req.SerialNumbers) {
kb.SerialNumber = req.SerialNumbers[i]
}
kindBoxes = append(kindBoxes, kb)
}
aErr := s.repo.AddBatchKindBox(ctx, kindBoxes)
if aErr != nil {
return param.AddKindBoxResponse{}, richerror.New(op).WithErr(aErr).WithKind(richerror.KindUnexpected)
}
return param.AddKindBoxResponse{}, nil
}