-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
treat issue problem index out of bounds! #13
Changes from 2 commits
72b5a2f
49e5e26
913bc65
1e5d8c6
18ce821
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ 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 | ||
} | ||
|
||
//DBClient is a mongodb Client instance | ||
|
@@ -98,16 +99,18 @@ func (c *DBClient) GetMonthlyInfo(agencies []Agency, year int) (map[string][]Age | |
return result, nil | ||
} | ||
|
||
//GetDataForSecondScreen GetDataForSecondScreen | ||
//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 | ||
if err == mongo.ErrNoDocuments { | ||
return nil, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por favor não retorne um elemento de outro pacote que você está abstraindo do usuário. Fazendo isso você está expondo um detalhe de implementação: a forma como seu dado é armazenado. É super simples criar uma constante dentro do seu próprio pacote e retornar ela There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Entendi, vou ter mais cuidado a partir de agora. |
||
} | ||
} | ||
var mr []AgencyMonthlyInfo | ||
resultMonthly.All(context.TODO(), &mr) | ||
return &mr[0], nil | ||
return &resultMonthly, nil | ||
} | ||
|
||
//Collection Changes active collection | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.