57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using AmtScanner.Api.Models;
|
|
using AmtScanner.Api.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace AmtScanner.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/hardware-info")]
|
|
public class HardwareInfoController : ControllerBase
|
|
{
|
|
private readonly IHardwareInfoService _hardwareInfoService;
|
|
private readonly ILogger<HardwareInfoController> _logger;
|
|
|
|
public HardwareInfoController(
|
|
IHardwareInfoService hardwareInfoService,
|
|
ILogger<HardwareInfoController> logger)
|
|
{
|
|
_hardwareInfoService = hardwareInfoService;
|
|
_logger = logger;
|
|
}
|
|
|
|
[HttpGet("{deviceId}")]
|
|
public async Task<ActionResult<HardwareInfoDto>> GetHardwareInfo(
|
|
long deviceId,
|
|
[FromQuery] bool refresh = false)
|
|
{
|
|
try
|
|
{
|
|
var result = await _hardwareInfoService.GetHardwareInfoAsync(deviceId, refresh);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error getting hardware info for device {DeviceId}", deviceId);
|
|
return StatusCode(500, new { error = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPost("batch")]
|
|
public async Task<ActionResult<List<BatchHardwareInfoResult>>> GetBatchHardwareInfo(
|
|
[FromBody] BatchHardwareInfoRequest request)
|
|
{
|
|
try
|
|
{
|
|
var results = await _hardwareInfoService.GetBatchHardwareInfoAsync(
|
|
request.DeviceIds,
|
|
request.Refresh);
|
|
return Ok(new { results });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error getting batch hardware info");
|
|
return StatusCode(500, new { error = ex.Message });
|
|
}
|
|
}
|
|
}
|