forked from ebhomengo/niki
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package adminkindboxreqservice
|
|
|
|
import (
|
|
"context"
|
|
adminkindboxparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
)
|
|
|
|
func (s Service) Accept(ctx context.Context, req param.KindBoxReqAcceptRequest) (param.KindBoxReqAcceptResponse, error) {
|
|
const op = "adminkindboxreqservice.Accept"
|
|
err := s.repo.AcceptKindBoxReq(ctx, req.ID, req.CountAccepted)
|
|
if err != nil {
|
|
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(err)
|
|
}
|
|
|
|
// fire new event to create a kind-box.
|
|
|
|
kindBoxReq, gErr := s.repo.GetByID(ctx, req.ID)
|
|
if gErr != nil {
|
|
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(gErr)
|
|
}
|
|
|
|
res, kErr := s.kindBoxSvc.Add(ctx, adminkindboxparam.KindBoxAddRequest{
|
|
BenefactorID: kindBoxReq.BenefactorID,
|
|
KindBoxReqID: kindBoxReq.ID,
|
|
})
|
|
if kErr != nil {
|
|
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(kErr)
|
|
}
|
|
|
|
return param.KindBoxReqAcceptResponse{
|
|
KindBoxReqID: kindBoxReq.ID,
|
|
KindBoxReqStatus: kindBoxReq.Status,
|
|
CountRequested: kindBoxReq.CountRequested,
|
|
CountAccepted: kindBoxReq.CountAccepted,
|
|
ReferDate: kindBoxReq.ReferDate,
|
|
AddressID: kindBoxReq.AddressID,
|
|
KindBoxID: res.KindBox.ID,
|
|
KindBoxType: kindBoxReq.KindBoxType,
|
|
BenefactorID: kindBoxReq.BenefactorID,
|
|
KindBoxStatus: res.KindBox.Status,
|
|
KindBoxSerialNumber: res.KindBox.SerialNumber,
|
|
}, nil
|
|
}
|