Skip to content

Commit

Permalink
Merge pull request #13 from dadosjusbr/bugfix/issue9
Browse files Browse the repository at this point in the history
treat issue problem index out of bounds!
  • Loading branch information
joeberth authored Feb 28, 2020
2 parents 369c836 + 18ce821 commit 8f7ec8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 12 additions & 6 deletions mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ import (
type collection interface {
ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)
Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)
FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult
}

// Errors raised by package storage.
var (
ErrNothingFound = fmt.Errorf("There is no document with this parameters")
)

//DBClient is a mongodb Client instance
type DBClient struct {
mgoClient *mongo.Client
Expand Down Expand Up @@ -99,16 +105,16 @@ func (c *DBClient) GetMonthlyInfo(agencies []Agency, year int) (map[string][]Age
return result, nil
}

//GetDataForSecondScreen return all documents in monthlyInfo collection that match with arguments.
//GetDataForSecondScreen Search if DB has a match for filters
func (c *DBClient) GetDataForSecondScreen(month int, year int, agency string) (*AgencyMonthlyInfo, error) {
c.Collection(c.monthlyInfoCol)
resultMonthly, err := c.col.Find(context.TODO(), bson.D{{Key: "aid", Value: agency}, {Key: "year", Value: year}, {Key: "month", Value: month}})
var resultMonthly AgencyMonthlyInfo
err := c.col.FindOne(context.TODO(), bson.D{{Key: "aid", Value: agency}, {Key: "year", Value: year}, {Key: "month", Value: month}}).Decode(&resultMonthly)
if err != nil {
return nil, fmt.Errorf("Error in GetMonthlyInfo %v", err)
// ErrNoDocuments means that the filter did not match any documents in the collection
return nil, ErrNothingFound
}
var mr []AgencyMonthlyInfo
resultMonthly.All(context.TODO(), &mr)
return &mr[0], nil
return &resultMonthly, nil
}

//Collection Changes active collection
Expand Down
4 changes: 4 additions & 0 deletions mgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ func (c *checkCollection) Find(ctx context.Context, filter interface{}, opts ...
return nil, nil
}

func (c *checkCollection) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult {
return nil
}

func (cs *checkStorage) ObjectPut(container string, objectName string, contents io.Reader, checkHash bool, Hash string, contentType string, h swift.Headers) (headers swift.Headers, err error) {
if cs.check {
assert.Equal(cs.t, cs.container, container)
Expand Down

0 comments on commit 8f7ec8c

Please sign in to comment.