version 3

This commit is contained in:
2025-12-17 00:34:41 +03:30
parent 139924db94
commit 74e8480a68
38 changed files with 5399 additions and 70 deletions

View File

@@ -0,0 +1,62 @@
using Microsoft.AspNetCore.Mvc;
using GreenHome.Application;
namespace GreenHome.Api.Controllers;
[ApiController]
[Route("api/[controller]")]
public class AlertLogsController : ControllerBase
{
private readonly IAlertLogService _alertLogService;
public AlertLogsController(IAlertLogService alertLogService)
{
_alertLogService = alertLogService;
}
/// <summary>
/// دریافت لیست لاگ‌های هشدار با فیلتر و صفحه‌بندی
/// </summary>
[HttpGet]
public async Task<ActionResult<PagedResult<AlertLogDto>>> GetAlertLogs(
[FromQuery] int? deviceId,
[FromQuery] int? userId,
[FromQuery] Domain.AlertType? alertType,
[FromQuery] Domain.AlertStatus? status,
[FromQuery] DateTime? startDate,
[FromQuery] DateTime? endDate,
[FromQuery] int page = 1,
[FromQuery] int pageSize = 20,
CancellationToken cancellationToken = default)
{
var filter = new AlertLogFilter
{
DeviceId = deviceId,
UserId = userId,
AlertType = alertType,
Status = status,
StartDate = startDate,
EndDate = endDate,
Page = page,
PageSize = pageSize
};
var result = await _alertLogService.GetAlertLogsAsync(filter, cancellationToken);
return Ok(result);
}
/// <summary>
/// دریافت جزئیات کامل یک لاگ هشدار
/// </summary>
[HttpGet("{id}")]
public async Task<ActionResult<AlertLogDto>> GetAlertLogById(int id, CancellationToken cancellationToken)
{
var result = await _alertLogService.GetAlertLogByIdAsync(id, cancellationToken);
if (result == null)
{
return NotFound(new { error = $"لاگ هشدار با شناسه {id} یافت نشد" });
}
return Ok(result);
}
}