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; } /// /// دریافت لیست لاگ‌های هشدار با فیلتر و صفحه‌بندی /// [HttpGet] public async Task>> 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); } /// /// دریافت جزئیات کامل یک لاگ هشدار /// [HttpGet("{id}")] public async Task> GetAlertLogById(int id, CancellationToken cancellationToken) { var result = await _alertLogService.GetAlertLogByIdAsync(id, cancellationToken); if (result == null) { return NotFound(new { error = $"لاگ هشدار با شناسه {id} یافت نشد" }); } return Ok(result); } }