version 3
This commit is contained in:
62
src/GreenHome.Api/Controllers/AlertLogsController.cs
Normal file
62
src/GreenHome.Api/Controllers/AlertLogsController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user