mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 04:20:55 +00:00
90 lines
3.8 KiB
C#
90 lines
3.8 KiB
C#
using CartriX.Api.Controllers.Cartridge;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CartriX.Api.Controllers.Printer
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class PrinterController(IPrinterService _service) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Добавить принтер
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Маршрут который позволяет добавить принтер в базу данных
|
|
/// </remarks>
|
|
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
|
[HttpPost(nameof(AddPrinter))]
|
|
public async Task<ActionResult> AddPrinter([FromBody] Shared.Models.Printer.PrinterAdd printer)
|
|
{
|
|
await _service.PrinterAddAsync(printer);
|
|
return StatusCode(200, "Принтер успешно добавлен.");
|
|
}
|
|
/// <summary>
|
|
/// Получить информацию о принтере
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Маршрут который позволяет получить информацию о принтере
|
|
/// </remarks>
|
|
[ProducesResponseType(typeof(Shared.Models.Printer.PrinterItem), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)]
|
|
[HttpGet(nameof(Item))]
|
|
public async Task<ActionResult> Item([FromQuery] int Id)
|
|
{
|
|
var cartridge = await _service.GetPrinterAsync(Id);
|
|
return (cartridge is not null) ? StatusCode(200, cartridge.ToItem())
|
|
: StatusCode(404, $"Принтер с идентификатором \"{Id}\" не найден.");
|
|
}
|
|
/// <summary>
|
|
/// Получить список типов подключения принтеров
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(List<Shared.Models.Printer.PrinterConnectionTypeItem>), StatusCodes.Status200OK)]
|
|
[HttpGet(nameof(ListConnectionType))]
|
|
public async Task<ActionResult> ListConnectionType()
|
|
{
|
|
var result = await _service.GetListConnectionTypeAsync();
|
|
return Ok(result.Select(t => t.ToItem()));
|
|
}
|
|
/// <summary>
|
|
/// Получить список типов печати принтеров
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(List<Shared.Models.Printer.PrinterPrintTypeItem>), StatusCodes.Status200OK)]
|
|
[HttpGet(nameof(ListPrintType))]
|
|
public async Task<ActionResult> ListPrintType()
|
|
{
|
|
var result = await _service.GetListPrintTypeAsync();
|
|
return Ok(result.Select(t => t.ToItem()));
|
|
}
|
|
/// <summary>
|
|
/// Получить список адресов OID для полученяи счетчика печати страниц принтера
|
|
/// </summary>
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[HttpGet(nameof(GetAddressOIDs))]
|
|
public async Task<ActionResult> GetAddressOIDs()
|
|
{
|
|
var result = await _service.GetOIDAddresses();
|
|
return Ok(result.Select(a => a.OIDAddress));
|
|
}
|
|
/// <summary>
|
|
/// Поменять статус принтера
|
|
/// </summary>
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[HttpPatch(nameof(ChangeStatus))]
|
|
public async Task<ActionResult> ChangeStatus([FromQuery] int PrinterId, [FromBody] int StatusId)
|
|
{
|
|
try
|
|
{
|
|
await _service.ChangeStatusAsync(PrinterId, StatusId);
|
|
return StatusCode(200);
|
|
}
|
|
catch (NullReferenceException ex)
|
|
{
|
|
return StatusCode(404, ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|