refactor(app): moved all db and log to one intialize spot

This commit is contained in:
2025-08-04 06:54:21 -05:00
parent 486e4fb6b8
commit 0ecbe29ec1
13 changed files with 148 additions and 99 deletions

View File

@@ -3,9 +3,10 @@ package settings
import (
"gorm.io/gorm"
"lst.net/internal/models"
"lst.net/pkg/logger"
)
func UpdateSetting(db *gorm.DB, id string, input SettingUpdateInput) error {
func UpdateSetting(log *logger.CustomLogger, db *gorm.DB, id string, input SettingUpdateInput) error {
var cfg models.Settings
if err := db.Where("setting_id =?", id).First(&cfg).Error; err != nil {
return err
@@ -30,5 +31,18 @@ func UpdateSetting(db *gorm.DB, id string, input SettingUpdateInput) error {
return nil // nothing to update
}
return db.Model(&cfg).Updates(updates).Error
settingUpdate := db.Model(&cfg).Updates(updates)
if settingUpdate.Error != nil {
log.Error("There was an error updating the setting", "settings", map[string]interface{}{
"error": settingUpdate.Error,
})
return settingUpdate.Error
}
log.Info("The setting was just updated", "settings", map[string]interface{}{
"name": settingUpdate.Name,
})
return nil
}