- Nova tabela user_settings com savings_goal_pct (default 40%) - API GET /api/settings, PUT /api/settings - DashboardService inclui savings_goal_pct no payload - DashboardHandler dispara savings_checked com goal configurado - GameService.NotifyAction: checa pct >= goal (sem hardcode de 40%) - SettingsView: painel META DE POUPANÇA com input configurável - HomeView: widget mostra meta dinâmica (META: X%) e usa savingsGoal - stores/settings.ts: store com fetch e update Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
31 lines
750 B
Go
31 lines
750 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"financeiro-carvalho/internal/model"
|
|
"financeiro-carvalho/internal/repository"
|
|
)
|
|
|
|
var ErrInvalidSavingsGoal = errors.New("savings_goal_pct must be between 1 and 100")
|
|
|
|
type SettingsService struct {
|
|
repo repository.SettingsRepository
|
|
}
|
|
|
|
func NewSettingsService(repo repository.SettingsRepository) *SettingsService {
|
|
return &SettingsService{repo: repo}
|
|
}
|
|
|
|
func (s *SettingsService) Get(ctx context.Context) (*model.UserSettings, error) {
|
|
return s.repo.Get(ctx)
|
|
}
|
|
|
|
func (s *SettingsService) Update(ctx context.Context, in model.UserSettings) (*model.UserSettings, error) {
|
|
if in.SavingsGoalPct < 1 || in.SavingsGoalPct > 100 {
|
|
return nil, ErrInvalidSavingsGoal
|
|
}
|
|
return s.repo.Upsert(ctx, in)
|
|
}
|