feat: add budget update functionality and enhance budget management UI
- Implemented UpdateAsync method in BudgetController for updating budget details. - Created UpdateBudgetDto for handling budget update requests. - Added BudgetCard component for displaying budget information with progress tracking. - Developed BudgetEditPopup component for creating and editing budget entries. - Introduced BudgetSummary component for summarizing budget statistics by period. - Enhanced budget period display logic in BudgetDto to support various timeframes.
This commit is contained in:
@@ -103,6 +103,38 @@ public class BudgetController(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新预算
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse> UpdateAsync([FromBody] UpdateBudgetDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
var budget = await budgetService.GetByIdAsync(dto.Id);
|
||||
if (budget == null) return "预算不存在".Fail();
|
||||
|
||||
budget.Name = dto.Name;
|
||||
budget.Type = dto.Type;
|
||||
budget.Limit = dto.Limit;
|
||||
budget.Category = dto.Category;
|
||||
budget.SelectedCategories = dto.SelectedCategories != null ? string.Join(",", dto.SelectedCategories) : string.Empty;
|
||||
budget.IsStopped = dto.IsStopped;
|
||||
if (dto.StartDate.HasValue)
|
||||
{
|
||||
budget.StartDate = dto.StartDate.Value;
|
||||
}
|
||||
|
||||
var success = await budgetService.UpdateAsync(budget);
|
||||
return success ? BaseResponse.Done() : "更新预算失败".Fail();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "更新预算失败, Id: {Id}", dto.Id);
|
||||
return $"更新预算失败: {ex.Message}".Fail();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换预算暂停状态
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user