2023-12-25 17:08:19 +00:00
|
|
|
package adminkindboxreqservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
2023-12-26 17:52:20 +00:00
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
2023-12-25 17:08:19 +00:00
|
|
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s Service) Update(ctx context.Context, req param.KindBoxReqUpdateRequest) (param.KindBoxReqUpdateResponse, error) {
|
|
|
|
// TODO: can benefactor update its request ?
|
|
|
|
// TODO: Is Update Mothod Service Responsible to check which kindboxreqID belongs to benefactorID ?
|
|
|
|
// TODO: updating data(s) may have side-effect on other entities by masood-keshvary accepted -> rejected
|
2023-12-26 13:11:29 +00:00
|
|
|
|
2023-12-25 17:08:19 +00:00
|
|
|
const op = "adminkindboxreqservice.Update"
|
|
|
|
|
|
|
|
kbr, gErr := s.repo.GetKindBoxReq(ctx, req.KindBoxReqID)
|
|
|
|
if gErr != nil {
|
|
|
|
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
2023-12-26 13:11:29 +00:00
|
|
|
if kbr.Status != entity.KindBoxReqPendingStatus {
|
2023-12-25 17:08:19 +00:00
|
|
|
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidStatus).WithKind(richerror.KindInvalid)
|
|
|
|
}
|
|
|
|
|
|
|
|
kindBoxReq, uErr := s.repo.UpdateKindBoxReq(ctx, req.KindBoxReqID, entity.KindBoxReq{
|
|
|
|
BenefactorID: req.BenefactorID,
|
|
|
|
TypeID: req.TypeID,
|
|
|
|
CountRequested: req.CountRequested,
|
|
|
|
})
|
|
|
|
if uErr != nil {
|
|
|
|
return param.KindBoxReqUpdateResponse{}, richerror.New(op).WithErr(uErr).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
|
|
|
|
|
|
|
return param.KindBoxReqUpdateResponse{KindBoxReq: kindBoxReq}, nil
|
|
|
|
}
|