2024-07-09 14:45:50 +00:00
|
|
|
package adminkindboxreqservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
|
|
)
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func (s Service) Update(ctx context.Context, req param.KindBoxReqUpdateRequest) (param.KindBoxReqUpdateResponse, error) {
|
2024-07-09 14:45:50 +00:00
|
|
|
const op = "adminkindboxreqservice.Update"
|
2024-08-01 10:20:18 +00:00
|
|
|
if fieldErrors, vErr := s.vld.ValidateUpdateRequest(ctx, req); vErr != nil {
|
|
|
|
return param.KindBoxReqUpdateResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
|
|
|
}
|
2024-07-09 14:45:50 +00:00
|
|
|
kindBoxReq, err := s.repo.GetByID(ctx, req.ID)
|
|
|
|
if err != nil {
|
2024-08-01 10:20:18 +00:00
|
|
|
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(err)
|
2024-07-09 14:45:50 +00:00
|
|
|
}
|
2024-07-10 01:21:03 +00:00
|
|
|
|
|
|
|
kindBoxReq.KindBoxType = req.KindBoxType
|
|
|
|
kindBoxReq.CountRequested = req.CountRequested
|
|
|
|
kindBoxReq.CountAccepted = req.CountAccepted
|
|
|
|
kindBoxReq.Description = req.Description
|
|
|
|
kindBoxReq.DeliverReferTimeID = req.DeliverReferTimeID
|
|
|
|
kindBoxReq.DeliverReferDate = req.DeliverReferDate
|
|
|
|
kindBoxReq.DeliverAddressID = req.DeliverAddressID
|
|
|
|
kindBoxReq.SenderAgentID = req.SenderAgentID
|
|
|
|
|
|
|
|
uErr := s.repo.UpdateKindBoxReq(ctx, kindBoxReq)
|
2024-07-09 14:45:50 +00:00
|
|
|
if uErr != nil {
|
2024-08-01 10:20:18 +00:00
|
|
|
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(uErr)
|
2024-07-09 14:45:50 +00:00
|
|
|
}
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
return param.KindBoxReqUpdateResponse{}, nil
|
2024-07-09 14:45:50 +00:00
|
|
|
}
|