2024-06-21 06:57:35 +00:00
|
|
|
package adminkindboxreqservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"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
|
|
|
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
|
2024-09-15 20:17:26 +00:00
|
|
|
BenefactorID: req.BenefactorID,
|
|
|
|
KindBoxType: req.KindBoxType,
|
|
|
|
DeliverAddressID: req.DeliverAddressID,
|
|
|
|
DeliverReferDate: req.DeliverReferDate,
|
|
|
|
DeliverReferTimeID: req.DeliverReferTimeID,
|
|
|
|
CountRequested: req.CountRequested,
|
|
|
|
Status: entity.KindBoxReqPendingStatus,
|
2024-06-21 06:57:35 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
|
|
|
|
2024-09-10 20:55: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
|
2024-06-21 06:57:35 +00:00
|
|
|
}
|