2024-07-09 17:17:04 +00:00
|
|
|
package adminkindboxservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (param.KindBoxGetAllResponse, error) {
|
|
|
|
const op = "adminkindboxservice.GetAll"
|
2024-09-10 20:55:19 +00:00
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
|
|
|
return param.KindBoxGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
|
|
|
}
|
2024-07-09 17:17:04 +00:00
|
|
|
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
|
|
|
if err != nil {
|
|
|
|
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
|
|
|
}
|
|
|
|
|
2024-09-10 20:55:19 +00:00
|
|
|
var data []param.Data
|
|
|
|
for _, kindBox := range allKindBox {
|
|
|
|
data = append(data, param.Data{
|
|
|
|
ID: kindBox.ID,
|
|
|
|
KindBoxReqID: kindBox.KindBoxReqID,
|
|
|
|
BenefactorID: kindBox.BenefactorID,
|
|
|
|
KindBoxType: kindBox.KindBoxType,
|
|
|
|
Amount: kindBox.Amount,
|
|
|
|
SerialNumber: kindBox.SerialNumber,
|
|
|
|
Status: kindBox.Status,
|
|
|
|
DeliverReferTimeID: kindBox.DeliverReferTimeID,
|
|
|
|
DeliverReferDate: kindBox.DeliverReferDate,
|
|
|
|
DeliverAddressID: kindBox.DeliverAddressID,
|
|
|
|
SenderAgentID: kindBox.SenderAgentID,
|
|
|
|
DeliveredAt: kindBox.DeliveredAt,
|
|
|
|
ReturnReferTimeID: kindBox.ReturnReferTimeID,
|
|
|
|
ReturnReferDate: kindBox.ReturnReferDate,
|
|
|
|
ReturnAddressID: kindBox.ReturnAddressID,
|
|
|
|
ReceiverAgentID: kindBox.ReceiverAgentID,
|
|
|
|
ReturnedAt: kindBox.ReturnedAt,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-07-09 17:17:04 +00:00
|
|
|
return param.KindBoxGetAllResponse{
|
2024-09-10 20:55:19 +00:00
|
|
|
Data: data,
|
2024-07-09 17:17:04 +00:00
|
|
|
Pagination: paginationparam.PaginationResponse{
|
|
|
|
PageSize: req.Pagination.GetPageSize(),
|
|
|
|
PageNumber: req.Pagination.GetPageNumber(),
|
|
|
|
Total: total,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|