57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package tonemod
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"91porn-server/common/log"
|
|
"91porn-server/common/pageopt"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type Matcher = pageopt.Matcher
|
|
|
|
// EnableMatch
|
|
type EnableMatch struct {
|
|
Enable *bool
|
|
}
|
|
|
|
func (i *EnableMatch) New() Matcher {
|
|
return pageopt.NewAssignMatch("enable", i.Enable)
|
|
}
|
|
|
|
// List
|
|
func List(sort D, skip, limit int64, matchers ...Matcher) ([]Tone, error) {
|
|
filter := pageopt.MergeM(matchers)
|
|
opt := &options.FindOptions{}
|
|
if len(sort) != 0 {
|
|
opt.SetSort(sort)
|
|
}
|
|
opt.SetSkip(skip)
|
|
opt.SetLimit(limit)
|
|
toneList := make([]Tone, 0, limit)
|
|
if err := coll(nil).Find(&toneList, filter, opt); err != nil {
|
|
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "List", table, "Find", err),
|
|
log.Any("sort", sort),
|
|
log.Any("skip", skip),
|
|
log.Any("limit", limit),
|
|
log.Any("matchers", matchers),
|
|
)
|
|
return nil, err
|
|
}
|
|
return toneList, nil
|
|
}
|
|
|
|
// Count
|
|
func Count(matchers ...Matcher) (int64, error) {
|
|
filter := pageopt.MergeM(matchers)
|
|
count, err := coll(nil).Count(filter)
|
|
if err != nil {
|
|
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Count", table, "Count", err),
|
|
log.Any("matchers", matchers),
|
|
)
|
|
return 0, err
|
|
}
|
|
return count, nil
|
|
}
|