chore: update
This commit is contained in:
@@ -19,6 +19,8 @@ type Store interface {
|
||||
UpdatePassword(id, passwordHahs string) (auth.User, error)
|
||||
GetTelegram(id string) (auth.User, error)
|
||||
SetTelegram(id, telegram string) (auth.User, error)
|
||||
GetAlertSettings(id string) (auth.User, error)
|
||||
SetAlertSettings(id string, discordWebhookURL, telegramBotToken, telegramChatID string) (auth.User, error)
|
||||
}
|
||||
|
||||
func (s *GormStore) UpdateUsername(id, newUsername string) (auth.User, error) {
|
||||
@@ -71,3 +73,36 @@ func (s *GormStore) SetTelegram(id, telegram string) (auth.User, error) {
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (s *GormStore) GetAlertSettings(id string) (auth.User, error) {
|
||||
var user auth.User
|
||||
if err := s.db.First(&user, "id = ?", id).Error; err != nil {
|
||||
return auth.User{}, err
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
// SetAlertSettings enregistre les réglages d'alerte de cet admin. Une chaîne
|
||||
// vide efface le champ correspondant (désactive ce canal pour cet admin).
|
||||
func (s *GormStore) SetAlertSettings(id string, discordWebhookURL, telegramBotToken, telegramChatID string) (auth.User, error) {
|
||||
updates := map[string]interface{}{
|
||||
"alert_discord_webhook_url": nullIfEmpty(discordWebhookURL),
|
||||
"alert_telegram_bot_token": nullIfEmpty(telegramBotToken),
|
||||
"alert_telegram_chat_id": nullIfEmpty(telegramChatID),
|
||||
}
|
||||
if err := s.db.Model(&auth.User{}).Where("id = ?", id).Updates(updates).Error; err != nil {
|
||||
return auth.User{}, err
|
||||
}
|
||||
var user auth.User
|
||||
if err := s.db.First(&user, "id = ?", id).Error; err != nil {
|
||||
return auth.User{}, err
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func nullIfEmpty(s string) *string {
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user