Skip to content

Commit

Permalink
Bug fix find pageable input ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cataldo committed Feb 5, 2024
1 parent 4a88567 commit 727e3e6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MongoDB Template
<!--suppress ALL -->
<img align="right" src="gopher-mongo.png" alt="">

[![Project status](https://img.shields.io/badge/version-v1.1.9-vividgreen.svg)](https://github.com/GabrielHCataldo/go-mongo-template/releases/tag/v1.1.9)
[![Project status](https://img.shields.io/badge/version-v1.2.0-vividgreen.svg)](https://github.com/GabrielHCataldo/go-mongo-template/releases/tag/v1.2.0)
[![Go Report Card](https://goreportcard.com/badge/github.com/GabrielHCataldo/go-mongo-template)](https://goreportcard.com/report/github.com/GabrielHCataldo/go-mongo-template)
[![Coverage Status](https://coveralls.io/repos/GabrielHCataldo/go-mongo-template/badge.svg?branch=main&service=github)](https://coveralls.io/github/GabrielHCataldo/go-mongo?branch=main)
[![Open Source Helpers](https://www.codetriage.com/gabrielhcataldo/go-mongo-template/badges/users.svg)](https://www.codetriage.com/gabrielhcataldo/go-mongo)
Expand Down
10 changes: 5 additions & 5 deletions mongo/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ func initListTestFindPageable() []testFindPageable {
pageInput: PageInput{
Page: 0,
PageSize: 10,
Ref: []testStruct{},
Ref: testStruct{},
Sort: bson.M{"createdAt": SortAsc},
},
option: initOptionFindPageable(),
Expand All @@ -1175,7 +1175,7 @@ func initListTestFindPageable() []testFindPageable {
pageInput: PageInput{
Page: 0,
PageSize: 10,
Ref: []testStruct{},
Ref: testStruct{},
Sort: nil,
},
option: initOptionFindPageable(),
Expand All @@ -1187,7 +1187,7 @@ func initListTestFindPageable() []testFindPageable {
pageInput: PageInput{
Page: 0,
PageSize: 10,
Ref: []testStruct{},
Ref: testStruct{},
Sort: nil,
},
option: initOptionFindPageable().
Expand All @@ -1205,7 +1205,7 @@ func initListTestFindPageable() []testFindPageable {
pageInput: PageInput{
Page: 0,
PageSize: 10,
Ref: []testInvalidStruct{},
Ref: testInvalidStruct{},
Sort: nil,
},
option: initOptionFindPageable(),
Expand All @@ -1218,7 +1218,7 @@ func initListTestFindPageable() []testFindPageable {
pageInput: PageInput{
Page: 0,
PageSize: 10,
Ref: &testStruct{},
Ref: []testStruct{},
Sort: nil,
},
option: initOptionFindPageable(),
Expand Down
2 changes: 1 addition & 1 deletion mongo/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type PageInput struct {
Page int64
// PageSize page size (required)
PageSize int64
// Ref slice of the struct reference contained database and collection configured
// Ref struct reference contained database and collection configured
Ref any
// Sort value sort to result
Sort any
Expand Down
5 changes: 4 additions & 1 deletion mongo/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ func (t *Template) FindAll(ctx context.Context, dest any, opts ...*option.Find)
// For more information about the command, see https://www.mongodb.com/docs/manual/reference/command/find/.
func (t *Template) FindPageable(ctx context.Context, filter any, input PageInput, opts ...*option.FindPageable) (
*PageResult, error) {
if helper.IsNotStruct(input.Ref) {
return nil, errors.NewSkipCaller(2, "mongo: input.Ref need to be structure")
}
_, collection, err := t.getMongoInfosByAny(2, input.Ref)
if helper.IsNotNil(err) {
return nil, err
Expand Down Expand Up @@ -543,7 +546,7 @@ func (t *Template) FindPageable(ctx context.Context, filter any, input PageInput
})
defer t.closeCursor(ctx, cursor)
if helper.IsNil(err) {
dest := reflect.MakeSlice(reflect.TypeOf(input.Ref), 0, 0).Interface()
dest := reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(input.Ref)), 0, 0).Interface()
err = cursor.All(ctx, &dest)
if helper.IsNil(err) {
countTotal, _ := collection.CountDocuments(ctx, filter)
Expand Down

0 comments on commit 727e3e6

Please sign in to comment.