forked from ebhomengo/niki
1
0
Fork 0
niki/service/benefactor/kind_box_req/add.go

44 lines
1.6 KiB
Go
Raw Permalink Normal View History

package benefactorkindboxreqservice
import (
"context"
"git.gocasts.ir/ebhomengo/niki/entity"
2023-12-25 17:08:19 +00:00
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) {
2023-12-25 17:08:19 +00:00
const op = "userkindboxreqservice.Add"
if fieldErrors, vErr := s.vld.ValidateAddRequest(ctx, req); vErr != nil {
return param.KindBoxReqAddResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
}
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
BenefactorID: req.BenefactorID,
KindBoxType: req.KindBoxType,
DeliverAddressID: req.DeliverAddressID,
DeliverReferDate: req.DeliverReferDate,
DeliverReferTimeID: req.DeliverReferTimeID,
CountRequested: req.CountRequested,
Status: entity.KindBoxReqPendingStatus,
})
if err != nil {
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
}
2023-12-25 17:08:19 +00:00
return param.KindBoxReqAddResponse{Data: param.Data{
ID: kindBoxReq.ID,
BenefactorID: kindBoxReq.BenefactorID,
KindBoxType: kindBoxReq.KindBoxType,
CountRequested: kindBoxReq.CountRequested,
CountAccepted: kindBoxReq.CountAccepted,
Description: kindBoxReq.Description,
Status: kindBoxReq.Status,
DeliverReferTimeID: kindBoxReq.DeliverReferTimeID,
DeliverReferDate: kindBoxReq.DeliverReferDate,
DeliverAddressID: kindBoxReq.DeliverAddressID,
SenderAgentID: kindBoxReq.SenderAgentID,
DeliveredAt: kindBoxReq.DeliveredAt,
}}, nil
}