63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
package officialWebsitemod
|
|
|
|
import (
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
// Hero 创作者
|
|
// 表: official_website_hero
|
|
type Hero struct {
|
|
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
|
Name string `json:"name" bson:"name"`
|
|
SeoSlug string `json:"seoSlug" bson:"seoSlug,omitempty"` // SEO 语义化唯一标识(纯小写字母)
|
|
Avatar string `json:"avatar" bson:"avatar"`
|
|
Height int64 `json:"height" bson:"height"`
|
|
Bust int64 `json:"bust" bson:"bust"`
|
|
Waist int64 `json:"waist" bson:"waist"`
|
|
Hip int64 `json:"hip" bson:"hip"`
|
|
Description string `json:"description" bson:"description"`
|
|
FansCount int64 `json:"fansCount" bson:"fansCount"`
|
|
Cover string `json:"cover" bson:"cover"`
|
|
Partners []primitive.ObjectID `json:"partners" bson:"partners"` //合作伙伴ID列表
|
|
SortModel `bson:",inline"`
|
|
BaseModel `bson:",inline"`
|
|
}
|
|
|
|
func (h *Hero) tableName() string { return tableHero }
|
|
|
|
func (h *Hero) FindOne(filter M) error {
|
|
return findOneByTable(h.tableName(), &h, filter)
|
|
}
|
|
|
|
func (h *Hero) FindMany(filter M, opts ...*options.FindOptions) ([]Hero, error) {
|
|
out := make([]Hero, 0)
|
|
err := findManyByTable(h.tableName(), &out, filter, opts...)
|
|
return out, err
|
|
}
|
|
|
|
func (h *Hero) Count(filter M) (int64, error) {
|
|
return countByTable(h.tableName(), filter)
|
|
}
|
|
|
|
func (h *Hero) Create() error {
|
|
h.CreatedAt = time.Now().UTC()
|
|
h.UpdatedAt = h.CreatedAt
|
|
id, err := createByTable(h.tableName(), h)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
h.ID = id
|
|
return nil
|
|
}
|
|
|
|
func (h *Hero) Update(filter M, update M) (int64, error) {
|
|
return updateByTable(h.tableName(), filter, update)
|
|
}
|
|
|
|
func (h *Hero) Delete(filter M) (int64, error) {
|
|
return deleteByTable(h.tableName(), filter)
|
|
}
|