You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1019 B
34 lines
1019 B
package database
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/analogj/scrutiny/webapp/backend/pkg/models"
|
|
)
|
|
|
|
func (sr *scrutinyRepository) GetSettings(ctx context.Context) (*models.Settings, error) {
|
|
settingsEntries := []models.SettingEntry{}
|
|
if err := sr.gormClient.WithContext(ctx).Find(&settingsEntries).Error; err != nil {
|
|
return nil, fmt.Errorf("Could not get settings from DB: %v", err)
|
|
}
|
|
|
|
settings := models.Settings{}
|
|
settings.PopulateFromSettingEntries(settingsEntries)
|
|
|
|
return &settings, nil
|
|
}
|
|
func (sr *scrutinyRepository) SaveSettings(ctx context.Context, settings models.Settings) error {
|
|
|
|
//get current settings
|
|
settingsEntries := []models.SettingEntry{}
|
|
if err := sr.gormClient.WithContext(ctx).Find(&settingsEntries).Error; err != nil {
|
|
return fmt.Errorf("Could not get settings from DB: %v", err)
|
|
}
|
|
|
|
// override with values from settings object
|
|
settingsEntries = settings.UpdateSettingEntries(settingsEntries)
|
|
|
|
// store in database.
|
|
return sr.gormClient.Updates(&settingsEntries).Error
|
|
}
|