mirror of
https://github.com/cuigh/swirl
synced 2025-01-01 00:32:09 +00:00
37 lines
790 B
Go
37 lines
790 B
Go
package mongo
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/cuigh/swirl/model"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
|
|
const Setting = "setting"
|
|
|
|
func (d *Dao) SettingList(ctx context.Context) (settings []*model.Setting, err error) {
|
|
settings = []*model.Setting{}
|
|
err = d.fetch(ctx, Setting, bson.M{}, &settings)
|
|
return
|
|
}
|
|
|
|
func (d *Dao) SettingGet(ctx context.Context, id string) (setting *model.Setting, err error) {
|
|
setting = &model.Setting{}
|
|
found, err := d.find(ctx, Setting, id, setting)
|
|
if !found {
|
|
return nil, err
|
|
}
|
|
return
|
|
}
|
|
|
|
func (d *Dao) SettingUpdate(ctx context.Context, id string, options []*model.SettingOption) (err error) {
|
|
update := bson.M{
|
|
"$set": bson.M{
|
|
"options": options,
|
|
"updated_at": time.Now(),
|
|
},
|
|
}
|
|
return d.upsert(ctx, Setting, id, update)
|
|
}
|