forked from ebhomengo/niki
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package benefactorkindboxreqservice
|
|
|
|
import (
|
|
"context"
|
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
"time"
|
|
)
|
|
|
|
func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) {
|
|
const op = "userkindboxreqservice.Add"
|
|
t, tErr := time.Parse(time.DateTime, req.DeliverReferDate)
|
|
if tErr != nil {
|
|
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(tErr).WithKind(richerror.KindInvalid)
|
|
}
|
|
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
|
|
BenefactorID: req.BenefactorID,
|
|
KindBoxType: req.TypeID,
|
|
DeliverAddressID: req.DeliverAddressID,
|
|
DeliverReferDate: t,
|
|
CountRequested: req.CountRequested,
|
|
Status: entity.KindBoxReqPendingStatus,
|
|
})
|
|
if err != nil {
|
|
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
|
}
|
|
|
|
return param.KindBoxReqAddResponse{KindBoxReq: kindBoxReq}, nil
|
|
}
|