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 _logger; public HardwareInfoController( IHardwareInfoService hardwareInfoService, ILogger logger) { _hardwareInfoService = hardwareInfoService; _logger = logger; } [HttpGet("{deviceId}")] public async Task>> GetHardwareInfo( long deviceId, [FromQuery] bool refresh = false) { try { var result = await _hardwareInfoService.GetHardwareInfoAsync(deviceId, refresh); return Ok(ApiResponse.Success(result)); } catch (Exception ex) { _logger.LogError(ex, "Error getting hardware info for device {DeviceId}", deviceId); return Ok(ApiResponse.Fail(500, ex.Message)); } } [HttpPost("batch")] public async Task>> GetBatchHardwareInfo( [FromBody] BatchHardwareInfoRequest request) { try { var results = await _hardwareInfoService.GetBatchHardwareInfoAsync( request.DeviceIds, request.Refresh); return Ok(ApiResponse.Success(new BatchHardwareInfoResponse { Results = results })); } catch (Exception ex) { _logger.LogError(ex, "Error getting batch hardware info"); return Ok(ApiResponse.Fail(500, ex.Message)); } } } public class BatchHardwareInfoResponse { public List Results { get; set; } = new(); }