mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 12:30:55 +00:00
Добавил маршрут в API для изменения статуса принтера
This commit is contained in:
1 parent
5faa4c6359
commit
286beabf89
8 files changed
+69
-8
No files matched your search
@@ -65,6 +65,10 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Media\pictures\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
@@ -9,6 +9,7 @@ namespace CartriX.Api.Controllers.Cartridge
|
||||
public Task<List<PrinterConnetctionType>> GetListConnectionTypeAsync();
|
||||
public Task<List<PrinterPrintType>> GetListPrintTypeAsync();
|
||||
public Task<List<AddressOID>> GetOIDAddresses();
|
||||
public Task ChangeStatusAsync(int PrinterId, int StatusId);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace CartriX.Api.Controllers.Printer
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class PrinterController(IPrinterService _printerService) : ControllerBase
|
||||
public class PrinterController(IPrinterService _service) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавить принтер
|
||||
@@ -19,7 +19,7 @@ namespace CartriX.Api.Controllers.Printer
|
||||
[HttpPost(nameof(AddPrinter))]
|
||||
public async Task<ActionResult> AddPrinter([FromBody] Shared.Models.Printer.PrinterAdd printer)
|
||||
{
|
||||
await _printerService.PrinterAddAsync(printer);
|
||||
await _service.PrinterAddAsync(printer);
|
||||
return StatusCode(200, "Принтер успешно добавлен.");
|
||||
}
|
||||
/// <summary>
|
||||
@@ -33,7 +33,7 @@ namespace CartriX.Api.Controllers.Printer
|
||||
[HttpGet(nameof(Item))]
|
||||
public async Task<ActionResult> Item([FromQuery] int Id)
|
||||
{
|
||||
var cartridge = await _printerService.GetPrinterAsync(Id);
|
||||
var cartridge = await _service.GetPrinterAsync(Id);
|
||||
return (cartridge is not null) ? StatusCode(200, cartridge.ToItem())
|
||||
: StatusCode(404, $"Принтер с идентификатором \"{Id}\" не найден.");
|
||||
}
|
||||
@@ -44,7 +44,7 @@ namespace CartriX.Api.Controllers.Printer
|
||||
[HttpGet(nameof(ListConnectionType))]
|
||||
public async Task<ActionResult> ListConnectionType()
|
||||
{
|
||||
var result = await _printerService.GetListConnectionTypeAsync();
|
||||
var result = await _service.GetListConnectionTypeAsync();
|
||||
return Ok(result.Select(t => t.ToItem()));
|
||||
}
|
||||
/// <summary>
|
||||
@@ -54,7 +54,7 @@ namespace CartriX.Api.Controllers.Printer
|
||||
[HttpGet(nameof(ListPrintType))]
|
||||
public async Task<ActionResult> ListPrintType()
|
||||
{
|
||||
var result = await _printerService.GetListPrintTypeAsync();
|
||||
var result = await _service.GetListPrintTypeAsync();
|
||||
return Ok(result.Select(t => t.ToItem()));
|
||||
}
|
||||
/// <summary>
|
||||
@@ -64,8 +64,25 @@ namespace CartriX.Api.Controllers.Printer
|
||||
[HttpGet(nameof(GetAddressOIDs))]
|
||||
public async Task<ActionResult> GetAddressOIDs()
|
||||
{
|
||||
var result = await _printerService.GetOIDAddresses();
|
||||
var result = await _service.GetOIDAddresses();
|
||||
return Ok(result.Select(a => a.OIDAddress));
|
||||
}
|
||||
/// <summary>
|
||||
/// Поменять статус принтера
|
||||
/// </summary>
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[HttpPut(nameof(ChangeStatus))]
|
||||
public async Task<ActionResult> ChangeStatus([FromQuery] int PrinterId, [FromQuery] int StatusId)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _service.ChangeStatusAsync(PrinterId, StatusId);
|
||||
return StatusCode(200);
|
||||
}
|
||||
catch (NullReferenceException ex)
|
||||
{
|
||||
return StatusCode(404, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
OidForQueryCountPrintedAllTime = printer.OidForQueryCountPrintedAllTime,
|
||||
PrintTypeName = printer.PrintType.Name,
|
||||
Model = printer.Model.ToItem(),
|
||||
StatusId = printer.StatusId,
|
||||
StatusName = printer.Status.Name,
|
||||
ConnetctionTypeName = printer.PrinterConnetctionType.Name,
|
||||
InstalledCartridgeId = printer.InstalledCartridge.Id,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using CartriX.Api.Entities;
|
||||
using CartriX.Shared.Models.Printer;
|
||||
using CartriX.Web.Pages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CartriX.Api.Controllers.Cartridge
|
||||
@@ -62,5 +63,19 @@ namespace CartriX.Api.Controllers.Cartridge
|
||||
public async Task<List<PrinterPrintType>> GetListPrintTypeAsync() => await _context.PrinterPrintTypes.ToListAsync();
|
||||
|
||||
public async Task<List<AddressOID>> GetOIDAddresses() => await _context.AddressOIDs.ToListAsync();
|
||||
|
||||
public async Task ChangeStatusAsync(int PrinterId, int StatusId)
|
||||
{
|
||||
var printer = await _context.Printers.FindAsync(PrinterId);
|
||||
if (printer is not null)
|
||||
{
|
||||
if (await _context.PrinterStatuses.FindAsync(StatusId) is not null) printer.StatusId = StatusId;
|
||||
else throw new NullReferenceException($"Нету статуса под идентификатором {StatusId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NullReferenceException($"Нету принтера под идентификатором {PrinterId}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user