forked from ebhomengo/niki
1
0
Fork 0

Compare commits

..

No commits in common. "stage/erfan/fix-pagination" and "develop" have entirely different histories.

9 changed files with 14 additions and 40 deletions

View File

@ -5,9 +5,5 @@ import (
)
func BuildPaginationQuery(pagination param.PaginationRequest) (query string, args []any) {
if pagination.PageSize == 0 && pagination.PageNumber == 0 {
return "", nil
}
return "LIMIT ? OFFSET ?", []any{pagination.GetPageSize(), pagination.GetOffset()}
}

View File

@ -37,7 +37,7 @@ func (d *DB) GetAllKindBox(ctx context.Context, filter params.FilterRequest, pag
var total uint
baseQuery = `SELECT COUNT(*) FROM kind_boxes WHERE deleted_at IS NULL`
query, args = builder.BuildGetAllQuery(baseQuery, filter, params.PaginationRequest{}, params.SortRequest{})
query, args = builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
if qErr != nil {
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)

View File

@ -37,7 +37,7 @@ func (d *DB) GetAllKindBoxReq(ctx context.Context, filter param.FilterRequest, p
var total uint
baseQuery = `SELECT COUNT(*) FROM kind_box_reqs WHERE deleted_at IS NULL`
query, args = builder.BuildGetAllQuery(baseQuery, filter, param.PaginationRequest{}, param.SortRequest{})
query, args = builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
if qErr != nil {
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)

View File

@ -14,10 +14,6 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
return param.KindBoxGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
}
req.Pagination.GetPageSize()
req.Pagination.GetPageNumber()
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
if err != nil {
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
@ -49,8 +45,8 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
return param.KindBoxGetAllResponse{
Data: data,
Pagination: paginationparam.PaginationResponse{
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
Total: total,
},
}, nil

View File

@ -14,10 +14,6 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest)
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
return param.KindBoxReqGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
}
req.Pagination.GetPageSize()
req.Pagination.GetPageNumber()
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
if err != nil {
return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
@ -43,8 +39,8 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest)
return param.KindBoxReqGetAllResponse{
Data: data,
Pagination: paginationparam.PaginationResponse{
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
Total: total,
},
}, nil

View File

@ -13,10 +13,6 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
return param.GetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
}
req.Pagination.GetPageSize()
req.Pagination.GetPageNumber()
allKindBoxes, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
if err != nil {
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
@ -48,8 +44,8 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
return param.GetAllResponse{
Data: data,
Pagination: paginationparam.PaginationResponse{
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
Total: total,
},
}, nil

View File

@ -2,7 +2,6 @@ package agentkindboxreqservice
import (
"context"
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
@ -15,9 +14,6 @@ func (s Service) GetAllAwaitingDelivery(ctx context.Context, req param.DeliveryA
return param.DeliveryAwaitingGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
}
req.Pagination.GetPageSize()
req.Pagination.GetPageNumber()
allAwaitingKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
if err != nil {
return param.DeliveryAwaitingGetAllResponse{}, richerror.New(op).WithErr(err)
@ -43,8 +39,8 @@ func (s Service) GetAllAwaitingDelivery(ctx context.Context, req param.DeliveryA
return param.DeliveryAwaitingGetAllResponse{
Data: data,
Pagination: paginationparam.PaginationResponse{
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
Total: total,
},
}, nil

View File

@ -14,9 +14,6 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
return param.KindBoxGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
}
req.Pagination.GetPageSize()
req.Pagination.GetPageNumber()
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
if err != nil {
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
@ -48,8 +45,8 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
return param.KindBoxGetAllResponse{
Data: data,
Pagination: params.PaginationResponse{
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
Total: total,
},
}, nil

View File

@ -14,9 +14,6 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
return param.GetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
}
req.Pagination.GetPageSize()
req.Pagination.GetPageNumber()
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
if err != nil {
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
@ -43,8 +40,8 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
return param.GetAllResponse{
Data: data,
Pagination: params.PaginationResponse{
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
Total: total,
},
}, nil