@@ -0,0 +1,58 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// News 资讯
|
||||
// 表: official_website_news
|
||||
type News struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"`
|
||||
SeoSlug string `json:"seoSlug" bson:"seoSlug,omitempty"` // SEO 语义化唯一标识(纯小写字母)
|
||||
Description string `json:"description" bson:"description"`
|
||||
Cover string `json:"cover" bson:"cover"`
|
||||
Url string `json:"url" bson:"url"`
|
||||
Tags []Tag `json:"tags" bson:"tags"`
|
||||
Detail string `json:"detail" bson:"detail"`
|
||||
SortModel `bson:",inline"`
|
||||
BaseModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (n *News) tableName() string { return tableNews }
|
||||
|
||||
func (n *News) FindOne(filter M) error {
|
||||
return findOneByTable(n.tableName(), &n, filter)
|
||||
}
|
||||
|
||||
func (n *News) FindMany(filter M, opts ...*options.FindOptions) ([]News, error) {
|
||||
out := make([]News, 0)
|
||||
err := findManyByTable(n.tableName(), &out, filter, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (n *News) Count(filter M) (int64, error) {
|
||||
return countByTable(n.tableName(), filter)
|
||||
}
|
||||
|
||||
func (n *News) Create() error {
|
||||
n.CreatedAt = time.Now().UTC()
|
||||
n.UpdatedAt = n.CreatedAt
|
||||
id, err := createByTable(n.tableName(), n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n.ID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *News) Update(filter M, update M) (int64, error) {
|
||||
return updateByTable(n.tableName(), filter, update)
|
||||
}
|
||||
|
||||
func (n *News) Delete(filter M) (int64, error) {
|
||||
return deleteByTable(n.tableName(), filter)
|
||||
}
|
||||
Reference in New Issue
Block a user