2024-01-22 08:14:57 +00:00
|
|
|
package adminkindboxreqservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-01-25 17:59:18 +00:00
|
|
|
|
2024-01-22 08:14:57 +00:00
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
|
|
)
|
|
|
|
|
2024-01-25 17:59:18 +00:00
|
|
|
// @see
|
2024-01-25 15:15:53 +00:00
|
|
|
// When confirming a request, should the senderID field, which represents the person sending the kind-box to the beneficiary,
|
|
|
|
// be filled at the same time? Or is it acceptable to confirm the request first and fill in the senderID field later?
|
|
|
|
//
|
|
|
|
|
2024-01-22 08:14:57 +00:00
|
|
|
func (s Service) Accept(ctx context.Context, req param.KindBoxReqAcceptRequest) (param.KindBoxReqAcceptResponse, error) {
|
|
|
|
const op = "adminkindboxreqservice.Accept"
|
2024-08-01 10:20:18 +00:00
|
|
|
if fieldErrors, vErr := s.vld.ValidateAcceptRequest(ctx, req); vErr != nil {
|
|
|
|
return param.KindBoxReqAcceptResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
|
|
|
}
|
2024-01-22 10:43:16 +00:00
|
|
|
err := s.repo.AcceptKindBoxReq(ctx, req.ID, req.CountAccepted)
|
2024-01-22 08:14:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(err)
|
|
|
|
}
|
|
|
|
|
2024-01-22 14:07:51 +00:00
|
|
|
kindBoxReq, gErr := s.repo.GetByID(ctx, req.ID)
|
2024-01-22 08:14:57 +00:00
|
|
|
if gErr != nil {
|
2024-01-23 07:39:58 +00:00
|
|
|
return param.KindBoxReqAcceptResponse{}, richerror.New(op).WithErr(gErr)
|
|
|
|
}
|
|
|
|
|
2024-09-10 20:55:19 +00:00
|
|
|
return param.KindBoxReqAcceptResponse{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-01-22 08:14:57 +00:00
|
|
|
}
|