forked from ebhomengo/niki
fix(repository): resolve pagination 500 error on page_number field (#160)
This commit is contained in:
parent
4ef5c0ed66
commit
385fa2645a
|
@ -5,5 +5,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuildPaginationQuery(pagination param.PaginationRequest) (query string, args []any) {
|
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()}
|
return "LIMIT ? OFFSET ?", []any{pagination.GetPageSize(), pagination.GetOffset()}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (d *DB) GetAllKindBox(ctx context.Context, filter params.FilterRequest, pag
|
||||||
|
|
||||||
var total uint
|
var total uint
|
||||||
baseQuery = `SELECT COUNT(*) FROM kind_boxes WHERE deleted_at IS NULL`
|
baseQuery = `SELECT COUNT(*) FROM kind_boxes WHERE deleted_at IS NULL`
|
||||||
query, args = builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
|
query, args = builder.BuildGetAllQuery(baseQuery, filter, params.PaginationRequest{}, params.SortRequest{})
|
||||||
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
||||||
if qErr != nil {
|
if qErr != nil {
|
||||||
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (d *DB) GetAllKindBoxReq(ctx context.Context, filter param.FilterRequest, p
|
||||||
|
|
||||||
var total uint
|
var total uint
|
||||||
baseQuery = `SELECT COUNT(*) FROM kind_box_reqs WHERE deleted_at IS NULL`
|
baseQuery = `SELECT COUNT(*) FROM kind_box_reqs WHERE deleted_at IS NULL`
|
||||||
query, args = builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
|
query, args = builder.BuildGetAllQuery(baseQuery, filter, param.PaginationRequest{}, param.SortRequest{})
|
||||||
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
||||||
if qErr != nil {
|
if qErr != nil {
|
||||||
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||||
|
|
|
@ -14,6 +14,10 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
||||||
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
||||||
return param.KindBoxGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
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)
|
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
|
@ -45,8 +49,8 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
||||||
return param.KindBoxGetAllResponse{
|
return param.KindBoxGetAllResponse{
|
||||||
Data: data,
|
Data: data,
|
||||||
Pagination: paginationparam.PaginationResponse{
|
Pagination: paginationparam.PaginationResponse{
|
||||||
PageSize: req.Pagination.GetPageSize(),
|
PageSize: req.Pagination.PageSize,
|
||||||
PageNumber: req.Pagination.GetPageNumber(),
|
PageNumber: req.Pagination.PageNumber,
|
||||||
Total: total,
|
Total: total,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -14,6 +14,10 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest)
|
||||||
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
||||||
return param.KindBoxReqGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
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)
|
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||||
|
@ -39,8 +43,8 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest)
|
||||||
return param.KindBoxReqGetAllResponse{
|
return param.KindBoxReqGetAllResponse{
|
||||||
Data: data,
|
Data: data,
|
||||||
Pagination: paginationparam.PaginationResponse{
|
Pagination: paginationparam.PaginationResponse{
|
||||||
PageSize: req.Pagination.GetPageSize(),
|
PageSize: req.Pagination.PageSize,
|
||||||
PageNumber: req.Pagination.GetPageNumber(),
|
PageNumber: req.Pagination.PageNumber,
|
||||||
Total: total,
|
Total: total,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -13,6 +13,10 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
||||||
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
||||||
return param.GetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
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)
|
allKindBoxes, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
|
@ -44,8 +48,8 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
||||||
return param.GetAllResponse{
|
return param.GetAllResponse{
|
||||||
Data: data,
|
Data: data,
|
||||||
Pagination: paginationparam.PaginationResponse{
|
Pagination: paginationparam.PaginationResponse{
|
||||||
PageSize: req.Pagination.GetPageSize(),
|
PageSize: req.Pagination.PageSize,
|
||||||
PageNumber: req.Pagination.GetPageNumber(),
|
PageNumber: req.Pagination.PageNumber,
|
||||||
Total: total,
|
Total: total,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -2,6 +2,7 @@ package agentkindboxreqservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
@ -14,6 +15,9 @@ func (s Service) GetAllAwaitingDelivery(ctx context.Context, req param.DeliveryA
|
||||||
return param.DeliveryAwaitingGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
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)
|
allAwaitingKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.DeliveryAwaitingGetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.DeliveryAwaitingGetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
|
@ -39,8 +43,8 @@ func (s Service) GetAllAwaitingDelivery(ctx context.Context, req param.DeliveryA
|
||||||
return param.DeliveryAwaitingGetAllResponse{
|
return param.DeliveryAwaitingGetAllResponse{
|
||||||
Data: data,
|
Data: data,
|
||||||
Pagination: paginationparam.PaginationResponse{
|
Pagination: paginationparam.PaginationResponse{
|
||||||
PageSize: req.Pagination.GetPageSize(),
|
PageSize: req.Pagination.PageSize,
|
||||||
PageNumber: req.Pagination.GetPageNumber(),
|
PageNumber: req.Pagination.PageNumber,
|
||||||
Total: total,
|
Total: total,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -14,6 +14,9 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
||||||
return param.KindBoxGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
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)
|
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
|
@ -45,8 +48,8 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
||||||
return param.KindBoxGetAllResponse{
|
return param.KindBoxGetAllResponse{
|
||||||
Data: data,
|
Data: data,
|
||||||
Pagination: params.PaginationResponse{
|
Pagination: params.PaginationResponse{
|
||||||
PageSize: req.Pagination.GetPageSize(),
|
PageSize: req.Pagination.PageSize,
|
||||||
PageNumber: req.Pagination.GetPageNumber(),
|
PageNumber: req.Pagination.PageNumber,
|
||||||
Total: total,
|
Total: total,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -14,6 +14,9 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
||||||
return param.GetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
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)
|
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
|
@ -40,8 +43,8 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
||||||
return param.GetAllResponse{
|
return param.GetAllResponse{
|
||||||
Data: data,
|
Data: data,
|
||||||
Pagination: params.PaginationResponse{
|
Pagination: params.PaginationResponse{
|
||||||
PageSize: req.Pagination.GetPageSize(),
|
PageSize: req.Pagination.PageSize,
|
||||||
PageNumber: req.Pagination.GetPageNumber(),
|
PageNumber: req.Pagination.PageNumber,
|
||||||
Total: total,
|
Total: total,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
Loading…
Reference in New Issue