2024-06-21 06:57:35 +00:00
|
|
|
package adminkindboxreqservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/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) {
|
|
|
|
const op = "adminkindboxreqservice.Add"
|
2024-08-01 10:20:18 +00:00
|
|
|
if fieldErrors, vErr := s.vld.ValidateAddRequest(ctx, req); vErr != nil {
|
|
|
|
return param.KindBoxReqAddResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
|
|
|
}
|
2024-06-21 06:57:35 +00:00
|
|
|
date, 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,
|
2024-07-03 17:18:06 +00:00
|
|
|
KindBoxType: req.KindBoxType,
|
2024-06-21 06:57:35 +00:00
|
|
|
DeliverAddressID: req.DeliverAddressID,
|
|
|
|
DeliverReferDate: date,
|
|
|
|
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
|
|
|
|
}
|