forked from ebhomengo/niki
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package benefactorkindboxreqservice
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
|
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
)
|
|
|
|
func (s Service) UpdateKindBoxReq(ctx context.Context, req param.KindBoxReqUpdateRequest) (param.KindBoxReqUpdateResponse, error) {
|
|
const op = "benefactorkindboxreqservice.UpdateKindBoxReq"
|
|
|
|
|
|
t, tErr := time.Parse(time.DateTime, req.DeliverReferDate)
|
|
if tErr != nil {
|
|
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(tErr).WithKind(richerror.KindInvalid)
|
|
}
|
|
|
|
updatedKindBoxReq, err := s.repo.UpdateKindBoxReq(ctx, entity.KindBoxReq{
|
|
ID: req.KindBoxReqID,
|
|
BenefactorID: req.BenefactorID,
|
|
KindBoxType: req.KindBoxType,
|
|
CountRequested: req.CountRequested,
|
|
Description: req.Description,
|
|
DeliverReferDate: t,
|
|
DeliverReferTimeID: req.DeliverReferTimeID,
|
|
DeliverAddressID: req.DeliverAddressID,
|
|
})
|
|
|
|
if err != nil {
|
|
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
|
}
|
|
|
|
return param.KindBoxReqUpdateResponse{KindBoxReq: updatedKindBoxReq}, nil
|
|
}
|