2023-08-17 00:49:46 +02:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"emperror.dev/errors"
|
|
|
|
"github.com/rs/xid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UserSettings struct {
|
|
|
|
ReadChangelog string `json:"read_changelog"`
|
|
|
|
ReadSettingsNotice string `json:"read_settings_notice"`
|
2023-09-09 17:20:18 +02:00
|
|
|
ReadGlobalNotice int `json:"read_global_notice"`
|
2023-08-17 00:49:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (db *DB) UpdateUserSettings(ctx context.Context, id xid.ID, us UserSettings) error {
|
|
|
|
sql, args, err := sq.Update("users").Set("settings", us).Where("id = ?", id).ToSql()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "building sql")
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = db.Exec(ctx, sql, args...)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "executing query")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|