54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package officialWebsitemod
|
|
|
|
import (
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type Partner struct {
|
|
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
|
Name string `json:"name" bson:"name"`
|
|
Description string `json:"description" bson:"description"`
|
|
Logo string `json:"logo" bson:"logo"`
|
|
Url string `json:"url" bson:"url"`
|
|
SortModel `bson:",inline"`
|
|
BaseModel `bson:",inline"`
|
|
}
|
|
|
|
func (p *Partner) tableName() string { return tablePartner }
|
|
|
|
func (p *Partner) FindOne(filter M) error {
|
|
return findOneByTable(p.tableName(), &p, filter)
|
|
}
|
|
|
|
func (p *Partner) FindMany(filter M, opts ...*options.FindOptions) ([]Partner, error) {
|
|
out := make([]Partner, 0)
|
|
err := findManyByTable(p.tableName(), &out, filter, opts...)
|
|
return out, err
|
|
}
|
|
|
|
func (p *Partner) Count(filter M) (int64, error) {
|
|
return countByTable(p.tableName(), filter)
|
|
}
|
|
|
|
func (p *Partner) 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 *Partner) Update(filter M, update M) (int64, error) {
|
|
return updateByTable(p.tableName(), filter, update)
|
|
}
|
|
|
|
func (p *Partner) Delete(filter M) (int64, error) {
|
|
return deleteByTable(p.tableName(), filter)
|
|
}
|