swirl/dao/mongo/event.go

29 lines
707 B
Go
Raw Normal View History

2017-09-26 12:50:09 +00:00
package mongo
import (
2021-12-06 12:24:22 +00:00
"context"
2017-09-26 12:50:09 +00:00
"github.com/cuigh/swirl/model"
2021-12-06 12:24:22 +00:00
"go.mongodb.org/mongo-driver/bson"
2017-09-26 12:50:09 +00:00
)
2021-12-06 12:24:22 +00:00
const Event = "event"
2017-09-26 12:50:09 +00:00
2021-12-16 08:11:16 +00:00
func (d *Dao) EventSearch(ctx context.Context, args *model.EventSearchArgs) (events []*model.Event, count int, err error) {
2021-12-06 12:24:22 +00:00
filter := bson.M{}
if args.Type != "" {
filter["type"] = args.Type
}
if args.Name != "" {
filter["name"] = args.Name
}
opts := searchOptions{filter: filter, sorter: bson.M{"_id": -1}, pageIndex: args.PageIndex, pageSize: args.PageSize}
events = []*model.Event{}
count, err = d.search(ctx, Event, opts, &events)
2017-09-26 12:50:09 +00:00
return
}
2021-12-06 12:24:22 +00:00
func (d *Dao) EventCreate(ctx context.Context, event *model.Event) (err error) {
return d.create(ctx, Event, event)
2017-09-26 12:50:09 +00:00
}