forked from ebhomengo/niki
1
0
Fork 0
niki/service/admin/kind_box_req/accept.go

36 lines
1.1 KiB
Go

package adminkindboxreqservice
import (
"context"
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.
//get kind box req
kindBoxReq, gErr := s.repo.FindByID(ctx, req.ID)
if gErr != nil {
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(err)
}
return param.KindBoxReqAcceptResponse{
ID: kindBoxReq.ID,
KindBoxType: kindBoxReq.KindBoxType,
CountRequested: kindBoxReq.CountRequested,
CountAccepted: kindBoxReq.CountAccepted,
BenefactorID: kindBoxReq.BenefactorID,
Status: kindBoxReq.Status,
Description: kindBoxReq.Description,
ReferDate: kindBoxReq.ReferDate,
AddressID: kindBoxReq.AddressID,
}, nil
}