feat: 添加预算管理功能,包括其handler、service和repository层。

This commit is contained in:
2026-02-02 13:55:41 +08:00
parent d08f7902c9
commit 4b2355deee
3 changed files with 75 additions and 3 deletions

View File

@@ -66,8 +66,19 @@ func (r *BudgetRepository) Update(budget *models.Budget) error {
return fmt.Errorf("failed to check budget existence: %w", err)
}
// Update the budget
if err := r.db.Save(budget).Error; err != nil {
// Update the budget using Select to explicitly specify fields to update
// This ensures that nil/NULL values for CategoryID and AccountID are properly saved
if err := r.db.Model(budget).Select(
"name",
"amount",
"period_type",
"category_id", // Explicitly include to allow setting to NULL
"account_id", // Explicitly include to allow setting to NULL
"is_rolling",
"start_date",
"end_date",
"updated_at",
).Updates(budget).Error; err != nil {
return fmt.Errorf("failed to update budget: %w", err)
}
return nil