Files
EmailBill/WebApi/Controllers/TransactionPeriodicController.cs

84 lines
2.3 KiB
C#
Raw Permalink Normal View History

2026-02-10 17:49:19 +08:00
using Application.Dto.Periodic;
using Application;
namespace WebApi.Controllers;
2025-12-29 15:20:32 +08:00
/// <summary>
/// 周期性账单控制器
/// </summary>
[ApiController]
[Route("api/[controller]/[action]")]
public class TransactionPeriodicController(
2026-02-10 17:49:19 +08:00
ITransactionPeriodicApplication periodicApplication
2025-12-29 15:20:32 +08:00
) : ControllerBase
{
/// <summary>
/// 获取周期性账单列表(分页)
/// </summary>
[HttpGet]
2026-02-10 17:49:19 +08:00
public async Task<PagedResponse<PeriodicResponse>> GetListAsync(
2025-12-29 15:20:32 +08:00
[FromQuery] int pageIndex = 1,
[FromQuery] int pageSize = 20,
[FromQuery] string? searchKeyword = null
)
{
2026-02-10 17:49:19 +08:00
var result = await periodicApplication.GetListAsync(pageIndex, pageSize, searchKeyword);
return new PagedResponse<PeriodicResponse>
2025-12-29 15:20:32 +08:00
{
2026-02-10 17:49:19 +08:00
Success = true,
Data = result.Data,
Total = result.Total
};
2025-12-29 15:20:32 +08:00
}
/// <summary>
/// 根据ID获取周期性账单详情
/// </summary>
[HttpGet("{id}")]
2026-02-10 17:49:19 +08:00
public async Task<BaseResponse<PeriodicResponse>> GetByIdAsync(long id)
2025-12-29 15:20:32 +08:00
{
2026-02-10 17:49:19 +08:00
var periodic = await periodicApplication.GetByIdAsync(id);
return periodic.Ok();
2025-12-29 15:20:32 +08:00
}
/// <summary>
/// 创建周期性账单
/// </summary>
[HttpPost]
2026-02-10 17:49:19 +08:00
public async Task<BaseResponse<PeriodicResponse>> CreateAsync([FromBody] CreatePeriodicRequest request)
2025-12-29 15:20:32 +08:00
{
2026-02-10 17:49:19 +08:00
var periodic = await periodicApplication.CreateAsync(request);
return periodic.Ok("创建成功");
2025-12-29 15:20:32 +08:00
}
/// <summary>
/// 更新周期性账单
/// </summary>
[HttpPost]
2026-01-04 16:43:32 +08:00
public async Task<BaseResponse> UpdateAsync([FromBody] UpdatePeriodicRequest request)
2025-12-29 15:20:32 +08:00
{
2026-02-10 17:49:19 +08:00
await periodicApplication.UpdateAsync(request);
return "更新成功".Ok();
2025-12-29 15:20:32 +08:00
}
/// <summary>
/// 删除周期性账单
/// </summary>
[HttpPost]
2026-01-04 16:43:32 +08:00
public async Task<BaseResponse> DeleteByIdAsync([FromQuery] long id)
2025-12-29 15:20:32 +08:00
{
2026-02-10 17:49:19 +08:00
await periodicApplication.DeleteByIdAsync(id);
return "删除成功".Ok();
2025-12-29 15:20:32 +08:00
}
/// <summary>
/// 启用/禁用周期性账单
/// </summary>
[HttpPost]
2026-01-04 16:43:32 +08:00
public async Task<BaseResponse> ToggleEnabledAsync([FromQuery] long id, [FromQuery] bool enabled)
2025-12-29 15:20:32 +08:00
{
2026-02-10 17:49:19 +08:00
await periodicApplication.ToggleEnabledAsync(id, enabled);
return (enabled ? "已启用" : "已禁用").Ok();
2025-12-29 15:20:32 +08:00
}
}