59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package officialWebsitemod
|
|
|
|
import (
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type Photograph struct {
|
|
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
|
HeroID primitive.ObjectID `json:"heroId" bson:"heroId"`
|
|
Name string `json:"name" bson:"name"`
|
|
SeoSlug string `json:"seoSlug" bson:"seoSlug,omitempty"` // SEO 语义化唯一标识(纯小写字母)
|
|
Description string `json:"description" bson:"description"`
|
|
Cover string `json:"cover" bson:"cover"`
|
|
Photos []string `json:"photos" bson:"photos"`
|
|
Tags []Tag `json:"tags" bson:"tags"`
|
|
SortModel `bson:",inline"`
|
|
BaseModel `bson:",inline"`
|
|
}
|
|
|
|
func (p *Photograph) tableName() string {
|
|
return tablePhotograph
|
|
}
|
|
|
|
func (p *Photograph) FindOne(filter M) error {
|
|
return findOneByTable(p.tableName(), p, filter)
|
|
}
|
|
|
|
func (p *Photograph) FindMany(filter M, opts ...*options.FindOptions) ([]Photograph, error) {
|
|
out := make([]Photograph, 0)
|
|
err := findManyByTable(p.tableName(), &out, filter, opts...)
|
|
return out, err
|
|
}
|
|
|
|
func (p *Photograph) Count(filter M) (int64, error) {
|
|
return countByTable(p.tableName(), filter)
|
|
}
|
|
|
|
func (p *Photograph) Create() error {
|
|
p.CreatedAt = time.Now().UTC()
|
|
p.UpdatedAt = p.CreatedAt
|
|
id, err := createByTable(p.tableName(), p)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
p.ID = id
|
|
return nil
|
|
}
|
|
|
|
func (p *Photograph) Update(filter M, update M) (int64, error) {
|
|
return updateByTable(p.tableName(), filter, update)
|
|
}
|
|
|
|
func (p *Photograph) Delete(filter M) (int64, error) {
|
|
return deleteByTable(p.tableName(), filter)
|
|
}
|