add default sort latest
This commit is contained in:
parent
66f49018b5
commit
296142f7c0
|
@ -13,6 +13,7 @@ type AllQuery struct {
|
||||||
TargetID string
|
TargetID string
|
||||||
Page int64
|
Page int64
|
||||||
Limit int64
|
Limit int64
|
||||||
|
Sort interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// All ...
|
// All ...
|
||||||
|
@ -23,15 +24,16 @@ func (s Service) All(query AllQuery) []Audit {
|
||||||
skip = query.Page * query.Limit
|
skip = query.Page * query.Limit
|
||||||
result = make([]Audit, 0)
|
result = make([]Audit, 0)
|
||||||
)
|
)
|
||||||
|
opts := options.Find().SetLimit(query.Limit).SetSkip(skip).SetSort(bson.M{"_id": -1})
|
||||||
|
if query.Sort != nil {
|
||||||
|
opts.SetSort(query.Sort)
|
||||||
|
}
|
||||||
|
|
||||||
// Find db
|
// Find db
|
||||||
cursor, err := s.DB.Collection(colName).Find(ctx, bson.D{
|
cursor, err := s.DB.Collection(colName).Find(ctx, bson.D{
|
||||||
{"target", query.Target},
|
{"target", query.Target},
|
||||||
{"targetId", query.TargetID},
|
{"targetId", query.TargetID},
|
||||||
}, &options.FindOptions{
|
}, opts)
|
||||||
Limit: &query.Limit,
|
|
||||||
Skip: &skip,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue