swirl/dao/mongo/setting.go

37 lines
812 B
Go
Raw Permalink Normal View History

2017-09-26 12:50:09 +00:00
package mongo
import (
2021-12-06 12:24:22 +00:00
"context"
2021-12-23 11:28:31 +00:00
"github.com/cuigh/swirl/dao"
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-23 11:28:31 +00:00
func (d *Dao) SettingGetAll(ctx context.Context) (settings []*dao.Setting, err error) {
settings = []*dao.Setting{}
2021-12-06 12:24:22 +00:00
err = d.fetch(ctx, Setting, bson.M{}, &settings)
2017-09-26 12:50:09 +00:00
return
}
2021-12-23 11:28:31 +00:00
func (d *Dao) SettingGet(ctx context.Context, id string) (setting *dao.Setting, err error) {
setting = &dao.Setting{}
2021-12-06 12:24:22 +00:00
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-23 11:28:31 +00:00
func (d *Dao) SettingUpdate(ctx context.Context, setting *dao.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
}