forked from ebhomengo/niki
1
0
Fork 0

Compare commits

...

1 Commits

9 changed files with 40 additions and 14 deletions

View File

@ -5,5 +5,9 @@ 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, pagination, sort)
query, args = builder.BuildGetAllQuery(baseQuery, filter, params.PaginationRequest{}, params.SortRequest{})
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, pagination, sort)
query, args = builder.BuildGetAllQuery(baseQuery, filter, param.PaginationRequest{}, param.SortRequest{})
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,6 +14,10 @@ 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)
@ -45,8 +49,8 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
return param.KindBoxGetAllResponse{
Data: data,
Pagination: paginationparam.PaginationResponse{
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
Total: total,
},
}, nil

View File

@ -14,6 +14,10 @@ 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)
@ -39,8 +43,8 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest)
return param.KindBoxReqGetAllResponse{
Data: data,
Pagination: paginationparam.PaginationResponse{
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
Total: total,
},
}, nil

View File

@ -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 {
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)
@ -44,8 +48,8 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
return param.GetAllResponse{
Data: data,
Pagination: paginationparam.PaginationResponse{
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
Total: total,
},
}, nil

View File

@ -2,6 +2,7 @@ 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"
@ -14,6 +15,9 @@ 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)
@ -39,8 +43,8 @@ func (s Service) GetAllAwaitingDelivery(ctx context.Context, req param.DeliveryA
return param.DeliveryAwaitingGetAllResponse{
Data: data,
Pagination: paginationparam.PaginationResponse{
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
Total: total,
},
}, nil

View File

@ -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)
}
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)
@ -45,8 +48,8 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
return param.KindBoxGetAllResponse{
Data: data,
Pagination: params.PaginationResponse{
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
Total: total,
},
}, nil

View File

@ -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)
}
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)
@ -40,8 +43,8 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
return param.GetAllResponse{
Data: data,
Pagination: params.PaginationResponse{
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
PageSize: req.Pagination.PageSize,
PageNumber: req.Pagination.PageNumber,
Total: total,
},
}, nil