2024-01-22 08:14:57 +00:00
|
|
|
package adminkindboxreqservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-01-23 10:21:56 +00:00
|
|
|
|
2024-01-23 07:39:58 +00:00
|
|
|
adminkindboxparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
2024-01-22 08:14:57 +00:00
|
|
|
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"
|
2024-01-22 10:43:16 +00:00
|
|
|
err := s.repo.AcceptKindBoxReq(ctx, req.ID, req.CountAccepted)
|
2024-01-22 08:14:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// fire new event to create a kind-box.
|
|
|
|
|
2024-01-22 14:07:51 +00:00
|
|
|
kindBoxReq, gErr := s.repo.GetByID(ctx, req.ID)
|
2024-01-22 08:14:57 +00:00
|
|
|
if gErr != nil {
|
2024-01-23 07:39:58 +00:00
|
|
|
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(gErr)
|
|
|
|
}
|
|
|
|
|
2024-01-23 10:21:56 +00:00
|
|
|
_, kErr := s.kindBoxClient.AddKindBoxAfterAcceptingRequest(ctx, adminkindboxparam.KindBoxAddAfterAcceptingReqRequest{
|
2024-01-23 07:39:58 +00:00
|
|
|
BenefactorID: kindBoxReq.BenefactorID,
|
|
|
|
KindBoxReqID: kindBoxReq.ID,
|
2024-01-23 10:21:56 +00:00
|
|
|
Type: kindBoxReq.KindBoxType,
|
|
|
|
Count: kindBoxReq.CountAccepted,
|
2024-01-23 07:39:58 +00:00
|
|
|
})
|
|
|
|
if kErr != nil {
|
|
|
|
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(kErr)
|
2024-01-22 08:14:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return param.KindBoxReqAcceptResponse{
|
2024-01-23 10:21:56 +00:00
|
|
|
KindBoxReqID: kindBoxReq.ID,
|
|
|
|
KindBoxReqStatus: kindBoxReq.Status,
|
|
|
|
CountRequested: kindBoxReq.CountRequested,
|
|
|
|
CountAccepted: kindBoxReq.CountAccepted,
|
|
|
|
ReferDate: kindBoxReq.ReferDate,
|
|
|
|
AddressID: kindBoxReq.AddressID,
|
2024-01-22 08:14:57 +00:00
|
|
|
}, nil
|
|
|
|
}
|