2023-12-25 17:08:19 +00:00
|
|
|
package adminkindboxreqservice
|
2024-02-03 04:56:27 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-04-28 11:27:23 +00:00
|
|
|
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
2024-02-03 04:56:27 +00:00
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
|
|
)
|
|
|
|
|
2024-06-12 08:15:28 +00:00
|
|
|
func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest) (param.KindBoxReqGetAllResponse, error) {
|
2024-02-03 04:56:27 +00:00
|
|
|
const op = "adminkindboxreqservice.GetAll"
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
|
|
|
return param.KindBoxReqGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
|
|
|
}
|
2024-06-12 08:15:28 +00:00
|
|
|
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
2024-02-03 04:56:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
2024-09-10 20:55:19 +00:00
|
|
|
var data []param.Data
|
|
|
|
for _, kindBoxReq := range allKindBoxReq {
|
|
|
|
data = append(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,
|
|
|
|
})
|
|
|
|
}
|
2024-02-03 04:56:27 +00:00
|
|
|
|
2024-04-28 11:27:23 +00:00
|
|
|
return param.KindBoxReqGetAllResponse{
|
2024-09-10 20:55:19 +00:00
|
|
|
Data: data,
|
2024-04-28 11:27:23 +00:00
|
|
|
Pagination: paginationparam.PaginationResponse{
|
2024-06-12 08:15:28 +00:00
|
|
|
PageSize: req.Pagination.GetPageSize(),
|
|
|
|
PageNumber: req.Pagination.GetPageNumber(),
|
|
|
|
Total: total,
|
2024-04-28 11:27:23 +00:00
|
|
|
},
|
|
|
|
}, nil
|
2024-02-03 04:56:27 +00:00
|
|
|
}
|