swirl/dao/mongo/setting.go

37 lines
824 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"
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-16 08:11:16 +00:00
func (d *Dao) SettingGetAll(ctx context.Context) (settings []*model.Setting, err error) {
2021-12-06 12:24:22 +00:00
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
2021-12-16 08:11:16 +00:00
func (d *Dao) SettingUpdate(ctx context.Context, setting *model.Setting) (err error) {
2021-12-06 12:24:22 +00:00
update := bson.M{
"$set": bson.M{
2021-12-16 08:11:16 +00:00
"options": setting.Options,
"updated_at": setting.UpdatedAt,
"updated_by": setting.UpdatedBy,
2021-12-06 12:24:22 +00:00
},
}
2021-12-16 08:11:16 +00:00
return d.upsert(ctx, Setting, setting.ID, update)
2021-12-06 12:24:22 +00:00
}