mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 04:20:55 +00:00
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using CartriX.Api.Services;
|
|
using CartriX.Shared.DTOs.Printer;
|
|
using CartriX.Shared.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CartriX.Api.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/Printer")]
|
|
public class PrinterController : ControllerBase
|
|
{
|
|
private readonly AppDbContext _context;
|
|
private readonly PrinterNetworkService _printerNetworkService;
|
|
|
|
public PrinterController(AppDbContext context, PrinterNetworkService printerNetworkService)
|
|
{
|
|
_context = context;
|
|
_printerNetworkService = printerNetworkService;
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public ActionResult GetPrinter(int id)
|
|
{
|
|
Printer printer = _context.Printers.Find(id)!;
|
|
return printer == null ? NotFound() : Ok(printer);
|
|
}
|
|
|
|
[HttpGet("GetSNMP/{IpAddressOrHostname}")]
|
|
public async Task<IActionResult> GetSNMPQueryResult(string IpAddressOrHostname)
|
|
{
|
|
try
|
|
{
|
|
QueryPrinterToAdd? printerData = await _printerNetworkService.GetPrinterListParametersAsync(IpAddressOrHostname);
|
|
|
|
return Ok(printerData);
|
|
}
|
|
catch (ArgumentException ex)
|
|
{
|
|
return BadRequest(ex.Message);
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
return Problem(detail: ex.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Problem(detail: ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|