feat: CDI % configurável por conta + fix mocks de teste

- Adiciona campo cdi_percentage (default 100%) na tabela accounts
- Cálculo CDI aplica proporção: balance × (compound-1) × (pct/100)
- Frontend exibe input de % quando yield_type=cdi e badge mostra valor
- Corrige mocks de teste desatualizados (DeleteByMonth, isTax)
- Corrige ConfirmIncome para rejeitar tipo expense (ErrRecurringNotIncome)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
2026-05-28 22:20:32 -03:00
co-authored by Claude Sonnet 4.6
parent 433c4f42a5
commit 6292858970
10 changed files with 73 additions and 37 deletions
+22 -14
View File
@@ -33,7 +33,7 @@ func (r *AccountRepository) List(ctx context.Context) ([]model.Account, error) {
rows, err := r.pool.Query(ctx, `
SELECT
a.id, a.name, a.type, a.initial_balance,
a.yield_type, a.last_yield_date::text,
a.yield_type, a.cdi_percentage, a.last_yield_date::text,
a.closing_day, a.due_day,
a.created_at::text, a.updated_at::text,
a.initial_balance
@@ -54,7 +54,7 @@ func (r *AccountRepository) List(ctx context.Context) ([]model.Account, error) {
var out []model.Account
for rows.Next() {
var a model.Account
if err := rows.Scan(&a.ID, &a.Name, &a.Type, &a.InitialBalance, &a.YieldType, &a.LastYieldDate, &a.ClosingDay, &a.DueDay, &a.CreatedAt, &a.UpdatedAt, &a.Balance); err != nil {
if err := rows.Scan(&a.ID, &a.Name, &a.Type, &a.InitialBalance, &a.YieldType, &a.CDIPercentage, &a.LastYieldDate, &a.ClosingDay, &a.DueDay, &a.CreatedAt, &a.UpdatedAt, &a.Balance); err != nil {
return nil, err
}
out = append(out, a)
@@ -68,7 +68,7 @@ func (r *AccountRepository) GetByID(ctx context.Context, id int) (*model.Account
err := r.pool.QueryRow(ctx, `
SELECT
a.id, a.name, a.type, a.initial_balance,
a.yield_type, a.last_yield_date::text,
a.yield_type, a.cdi_percentage, a.last_yield_date::text,
a.closing_day, a.due_day,
a.created_at::text, a.updated_at::text,
a.initial_balance
@@ -79,7 +79,7 @@ func (r *AccountRepository) GetByID(ctx context.Context, id int) (*model.Account
LEFT JOIN transactions t ON t.account_id = a.id
WHERE a.id = $1 AND a.profile_id = $2
GROUP BY a.id
`, id, pid).Scan(&a.ID, &a.Name, &a.Type, &a.InitialBalance, &a.YieldType, &a.LastYieldDate, &a.ClosingDay, &a.DueDay, &a.CreatedAt, &a.UpdatedAt, &a.Balance)
`, id, pid).Scan(&a.ID, &a.Name, &a.Type, &a.InitialBalance, &a.YieldType, &a.CDIPercentage, &a.LastYieldDate, &a.ClosingDay, &a.DueDay, &a.CreatedAt, &a.UpdatedAt, &a.Balance)
if err != nil {
return nil, err
}
@@ -92,13 +92,17 @@ func (r *AccountRepository) Create(ctx context.Context, in model.AccountInput) (
if yt == "" {
yt = "none"
}
cdiPct := in.CDIPercentage
if cdiPct <= 0 {
cdiPct = 100
}
var a model.Account
err := r.pool.QueryRow(ctx, `
INSERT INTO accounts (name, type, initial_balance, yield_type, closing_day, due_day, profile_id)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, name, type, initial_balance, yield_type, last_yield_date::text, closing_day, due_day, created_at::text, updated_at::text
`, in.Name, in.Type, in.InitialBalance, yt, in.ClosingDay, in.DueDay, pid).
Scan(&a.ID, &a.Name, &a.Type, &a.InitialBalance, &a.YieldType, &a.LastYieldDate, &a.ClosingDay, &a.DueDay, &a.CreatedAt, &a.UpdatedAt)
INSERT INTO accounts (name, type, initial_balance, yield_type, cdi_percentage, closing_day, due_day, profile_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, name, type, initial_balance, yield_type, cdi_percentage, last_yield_date::text, closing_day, due_day, created_at::text, updated_at::text
`, in.Name, in.Type, in.InitialBalance, yt, cdiPct, in.ClosingDay, in.DueDay, pid).
Scan(&a.ID, &a.Name, &a.Type, &a.InitialBalance, &a.YieldType, &a.CDIPercentage, &a.LastYieldDate, &a.ClosingDay, &a.DueDay, &a.CreatedAt, &a.UpdatedAt)
if err != nil {
return nil, err
}
@@ -112,13 +116,17 @@ func (r *AccountRepository) Update(ctx context.Context, id int, in model.Account
if yt == "" {
yt = "none"
}
cdiPct := in.CDIPercentage
if cdiPct <= 0 {
cdiPct = 100
}
row := r.pool.QueryRow(ctx, `
UPDATE accounts SET name=$1, type=$2, initial_balance=$3, yield_type=$4, closing_day=$5, due_day=$6, updated_at=NOW()
WHERE id=$7 AND profile_id=$8
RETURNING id, name, type, initial_balance, yield_type, last_yield_date::text, closing_day, due_day, created_at::text, updated_at::text
`, in.Name, in.Type, in.InitialBalance, yt, in.ClosingDay, in.DueDay, id, pid)
UPDATE accounts SET name=$1, type=$2, initial_balance=$3, yield_type=$4, cdi_percentage=$5, closing_day=$6, due_day=$7, updated_at=NOW()
WHERE id=$8 AND profile_id=$9
RETURNING id, name, type, initial_balance, yield_type, cdi_percentage, last_yield_date::text, closing_day, due_day, created_at::text, updated_at::text
`, in.Name, in.Type, in.InitialBalance, yt, cdiPct, in.ClosingDay, in.DueDay, id, pid)
var a model.Account
if err := row.Scan(&a.ID, &a.Name, &a.Type, &a.InitialBalance, &a.YieldType, &a.LastYieldDate, &a.ClosingDay, &a.DueDay, &a.CreatedAt, &a.UpdatedAt); err != nil {
if err := row.Scan(&a.ID, &a.Name, &a.Type, &a.InitialBalance, &a.YieldType, &a.CDIPercentage, &a.LastYieldDate, &a.ClosingDay, &a.DueDay, &a.CreatedAt, &a.UpdatedAt); err != nil {
return nil, err
}
full, err := r.GetByID(ctx, a.ID)