This commit is contained in:
CFOU
2026-09-14 20:50:19 +02:00
commit 3091fb4020
135 changed files with 10262 additions and 0 deletions
@@ -0,0 +1,44 @@
package telegram
import (
"context"
"gorm.io/gorm"
)
type Repository interface {
Get(ctx context.Context) (*Settings, error)
Update(ctx context.Context, s *Settings) error
}
type gormRepository struct {
db *gorm.DB
}
func NewRepository(db *gorm.DB) Repository {
return &gormRepository{db: db}
}
func (r *gormRepository) Get(ctx context.Context) (*Settings, error) {
var s Settings
if err := r.db.WithContext(ctx).First(&s, "id = 1").Error; err != nil {
return nil, err
}
return &s, nil
}
func (r *gormRepository) Update(ctx context.Context, s *Settings) error {
s.ID = 1
updates := map[string]any{
"enabled": s.Enabled,
"chat_id": s.ChatID,
"notify_new_order": s.NotifyNewOrder,
"notify_status_change": s.NotifyStatusChange,
}
// bot_token is only overwritten when explicitly provided (see service.go):
// a blank value in the update request means "keep the existing secret".
if s.BotToken != "" {
updates["bot_token"] = s.BotToken
}
return r.db.WithContext(ctx).Model(&Settings{}).Where("id = 1").Updates(updates).Error
}