swirl/dao/mongo/setting.go

37 lines
790 B
Go
Raw Normal View History

2017-09-26 12:50:09 +00:00
package mongo
import (
2021-12-06 12:24:22 +00:00
"context"
"time"
2017-09-26 12:50:09 +00:00
"github.com/cuigh/swirl/model"
2021-12-06 12:24:22 +00:00
"go.mongodb.org/mongo-driver/bson"
2017-09-26 12:50:09 +00:00
)
2021-12-06 12:24:22 +00:00
const Setting = "setting"
2017-09-26 12:50:09 +00:00
2021-12-06 12:24:22 +00:00
func (d *Dao) SettingList(ctx context.Context) (settings []*model.Setting, err error) {
settings = []*model.Setting{}
err = d.fetch(ctx, Setting, bson.M{}, &settings)
2017-09-26 12:50:09 +00:00
return
}
2021-12-06 12:24:22 +00:00
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
}
2017-09-26 12:50:09 +00:00
return
}
2021-12-06 12:24:22 +00:00
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)
}