@@ -0,0 +1,63 @@
|
||||
package cmtmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/pageopt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Matcher = pageopt.Matcher
|
||||
|
||||
// ToUserIDMatch
|
||||
type ToUserIDMatch struct {
|
||||
ToUserID *uint64
|
||||
}
|
||||
|
||||
func (t *ToUserIDMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("toUserID", t.ToUserID)
|
||||
}
|
||||
|
||||
// PublisherIDMatch
|
||||
type PublisherIDMatch struct {
|
||||
PublisherID *uint64
|
||||
}
|
||||
|
||||
func (t *PublisherIDMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("publisherID", t.PublisherID)
|
||||
}
|
||||
|
||||
type CreatedAtGTEMatch struct {
|
||||
GTE *time.Time
|
||||
}
|
||||
|
||||
func (c *CreatedAtGTEMatch) New() Matcher {
|
||||
return pageopt.NewGTEMatch("createdAt", c.GTE)
|
||||
}
|
||||
|
||||
// List
|
||||
func List(sort bson.D, skip, limit int64, matchers ...Matcher) ([]Comment, error) {
|
||||
filter := pageopt.MergeM(matchers)
|
||||
opt := &options.FindOptions{}
|
||||
if len(sort) != 0 {
|
||||
opt.SetSort(sort)
|
||||
}
|
||||
opt.SetSkip(skip)
|
||||
opt.SetLimit(limit)
|
||||
list := make([]Comment, 0, limit)
|
||||
err := coll(nil).Find(&list, filter, opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Count
|
||||
func Count(matchers ...Matcher) (int64, error) {
|
||||
filter := pageopt.MergeM(matchers)
|
||||
count, err := coll(nil).Count(filter)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
Reference in New Issue
Block a user