Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
fix: get model issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jun 9, 2024
1 parent a848ec2 commit 54863d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
5 changes: 1 addition & 4 deletions grpc/server/task_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ func (svr TaskServer) SendNotification(ctx context.Context, request *grpc.Reques
}
settings, _, err := svc.GetSettingList(bson.M{
"enabled": true,
}, &entity.Pagination{
Page: 0,
Size: 99999,
}, nil)
}, nil, nil)
if err != nil {
return nil, trace.TraceError(err)
}
Expand Down
19 changes: 14 additions & 5 deletions notification/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,22 @@ func (svc *Service) SendMobile(s *Setting, entity bson.M) (err error) {
}

func (svc *Service) GetSettingList(query bson.M, pagination *entity.Pagination, sort bson.D) (res []Setting, total int, err error) {
// options
var options *mongo2.FindOptions
if pagination != nil || sort != nil {
options = new(mongo2.FindOptions)
if pagination != nil {
options.Skip = pagination.Size * (pagination.Page - 1)
options.Limit = pagination.Size
}
if sort != nil {
options.Sort = sort
}
}

// get list
var list []Setting
if err := svc.col.Find(query, &mongo2.FindOptions{
Sort: sort,
Skip: pagination.Size * (pagination.Page - 1),
Limit: pagination.Size,
}).All(&list); err != nil {
if err := svc.col.Find(query, options).All(&list); err != nil {
if err.Error() == mongo.ErrNoDocuments.Error() {
return nil, 0, nil
} else {
Expand Down

0 comments on commit 54863d2

Please sign in to comment.