swirl/dao/mongo/event.go

29 lines
697 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"
2021-12-23 11:28:31 +00:00
"github.com/cuigh/swirl/dao"
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-23 11:28:31 +00:00
func (d *Dao) EventSearch(ctx context.Context, args *dao.EventSearchArgs) (events []*dao.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}
2021-12-23 11:28:31 +00:00
events = []*dao.Event{}
2021-12-06 12:24:22 +00:00
count, err = d.search(ctx, Event, opts, &events)
2017-09-26 12:50:09 +00:00
return
}
2021-12-23 11:28:31 +00:00
func (d *Dao) EventCreate(ctx context.Context, event *dao.Event) (err error) {
2021-12-06 12:24:22 +00:00
return d.create(ctx, Event, event)
2017-09-26 12:50:09 +00:00
}