all tests works...
This commit is contained in:
@@ -108,19 +108,51 @@ func (r *BudgetRepo) Create(ctx context.Context, req model.CreateBudgetRequest)
|
||||
}
|
||||
|
||||
func (r *BudgetRepo) Update(ctx context.Context, req model.UpdateBudgetRequest) (*model.Budget, error) {
|
||||
_, err := r.db.ExecContext(ctx, `
|
||||
UPDATE budgets
|
||||
SET version=?, amount=?, notes=?,
|
||||
updated_at=strftime('%Y-%m-%dT%H:%M:%SZ','now')
|
||||
WHERE id=?`,
|
||||
req.Version, req.Amount, req.Notes, req.ID,
|
||||
)
|
||||
if err != nil {
|
||||
q := `UPDATE budgets SET updated_at = strftime('%Y-%m-%dT%H:%M:%SZ','now')`
|
||||
args := []any{}
|
||||
|
||||
if req.Amount != nil {
|
||||
q += `, amount = ?`
|
||||
args = append(args, *req.Amount)
|
||||
}
|
||||
if req.Notes != nil {
|
||||
q += `, notes = ?`
|
||||
args = append(args, *req.Notes)
|
||||
}
|
||||
if req.Version != nil {
|
||||
q += `, version = ?`
|
||||
args = append(args, *req.Version)
|
||||
}
|
||||
if req.Currency != nil {
|
||||
q += `, currency = ?`
|
||||
args = append(args, *req.Currency)
|
||||
}
|
||||
if req.FiscalYear != nil {
|
||||
q += `, fiscal_year = ?`
|
||||
args = append(args, *req.FiscalYear)
|
||||
}
|
||||
if req.FiscalPeriod != nil {
|
||||
q += `, fiscal_period = ?`
|
||||
args = append(args, *req.FiscalPeriod)
|
||||
}
|
||||
if req.DepartmentID != nil {
|
||||
q += `, department_id = ?`
|
||||
args = append(args, *req.DepartmentID)
|
||||
}
|
||||
if req.GLAccountID != nil {
|
||||
q += `, gl_account_id = ?`
|
||||
args = append(args, *req.GLAccountID)
|
||||
}
|
||||
|
||||
q += ` WHERE id = ?`
|
||||
args = append(args, req.ID)
|
||||
|
||||
if _, err := r.db.ExecContext(ctx, q, args...); err != nil {
|
||||
return nil, fmt.Errorf("update budget: %w", err)
|
||||
}
|
||||
|
||||
row := r.db.QueryRowContext(ctx,
|
||||
`SELECT`+budgetSelectCols+`FROM budgets WHERE id = ?`, req.ID)
|
||||
`SELECT `+budgetSelectCols+` FROM budgets WHERE id = ?`, req.ID)
|
||||
b, err := scanBudget(row)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fetch updated budget: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user