diff --git a/CartriX.Api/Controllers/Location/ILocationService.cs b/CartriX.Api/Controllers/Location/ILocationService.cs new file mode 100644 index 0000000..328542e --- /dev/null +++ b/CartriX.Api/Controllers/Location/ILocationService.cs @@ -0,0 +1,7 @@ +namespace CartriX.Api.Controllers.Location +{ + public interface ILocationService + { + public Task> List(); + } +} diff --git a/CartriX.Api/Controllers/Location/LocationController.cs b/CartriX.Api/Controllers/Location/LocationController.cs new file mode 100644 index 0000000..2635f81 --- /dev/null +++ b/CartriX.Api/Controllers/Location/LocationController.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace CartriX.Api.Controllers.Location +{ + [Route("api/[controller]")] + [ApiController] + public class LocationController(ILocationService _locationService) : ControllerBase + { + /// + /// Получить список местоположений + /// + [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] + [HttpGet(nameof(List))] + public async Task List() + { + return Ok((await _locationService.List()).Select(l => l.ToItem())); + } + } +} diff --git a/CartriX.Api/Controllers/Location/LocationMap.cs b/CartriX.Api/Controllers/Location/LocationMap.cs new file mode 100644 index 0000000..47d2a1f --- /dev/null +++ b/CartriX.Api/Controllers/Location/LocationMap.cs @@ -0,0 +1,12 @@ +using CartriX.Api.Controllers.Cartridge; +namespace CartriX.Api.Controllers.Location +{ + public static class LocationMap + { + public static Shared.Models.Location.LocationItem ToItem(this Entities.Location location) => new() + { + Name = location.Name, + Printers = location.Printers.Select(p => p.ToItem()).ToList() + }; + } +} diff --git a/CartriX.Api/Controllers/Location/LocationService.cs b/CartriX.Api/Controllers/Location/LocationService.cs new file mode 100644 index 0000000..7cc3070 --- /dev/null +++ b/CartriX.Api/Controllers/Location/LocationService.cs @@ -0,0 +1,10 @@ +using CartriX.Shared.Models.Location; +using Microsoft.EntityFrameworkCore; + +namespace CartriX.Api.Controllers.Location +{ + public class LocationService(AppDbContext _context) : ILocationService + { + public async Task> List() => await _context.Locations.ToListAsync(); + } +} diff --git a/CartriX.Api/Controllers/Printer/PrinterMap.cs b/CartriX.Api/Controllers/Printer/PrinterMap.cs index 357e665..6a93825 100644 --- a/CartriX.Api/Controllers/Printer/PrinterMap.cs +++ b/CartriX.Api/Controllers/Printer/PrinterMap.cs @@ -22,6 +22,15 @@ namespace CartriX.Api.Controllers.Cartridge Name = model.Name, Manufacturer = model.Manufacturer.ToItem(), }; + public static Shared.Models.Printer.PrinterItemList ToItemList(this Entities.Printer printer) => new() + { + Name = printer.Name, + Model = printer.Model.ToItem(), + StatusId = printer.Status.Name, + ConnetctionTypeName = printer.ConnetctionType.Name, + InstalledCartridgeId = printer.InstalledCartridge.Id, + LocationName = printer.Location.Name, + }; } } diff --git a/CartriX.Api/Entities/Printer.cs b/CartriX.Api/Entities/Printer.cs index df14f69..0c1da6a 100644 --- a/CartriX.Api/Entities/Printer.cs +++ b/CartriX.Api/Entities/Printer.cs @@ -43,7 +43,7 @@ namespace CartriX.Api.Entities /// /// Идентификатор printerStatus /// - public required int PrinterStatusId { get; set; } + public required int StatusId { get; set; } /// /// Статус принтера /// diff --git a/CartriX.Api/Entities/PrinterModel.cs b/CartriX.Api/Entities/PrinterModel.cs index 51ee6b9..e332176 100644 --- a/CartriX.Api/Entities/PrinterModel.cs +++ b/CartriX.Api/Entities/PrinterModel.cs @@ -15,6 +15,10 @@ /// public required Manufacturer Manufacturer { get; set; } /// + /// Путь к картинке + /// + public string? PicturePath { get; set; } + /// /// Идентификатор поддерживамого артикля /// public int SupportedArticleId { get; set; } diff --git a/CartriX.Api/Program.cs b/CartriX.Api/Program.cs index 98686f6..4a247fe 100644 --- a/CartriX.Api/Program.cs +++ b/CartriX.Api/Program.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json.Serialization; using CartriX.Api; using CartriX.Api.Controllers.Cartridge; using CartriX.Api.Controllers.Report; +using CartriX.Api.Controllers.Location; var builder = WebApplication.CreateBuilder(args); @@ -13,6 +14,7 @@ builder.Services.AddControllers().AddNewtonsoftJson(options => }); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/CartriX.Shared/Models/Location/LocationItem.cs b/CartriX.Shared/Models/Location/LocationItem.cs new file mode 100644 index 0000000..02844e1 --- /dev/null +++ b/CartriX.Shared/Models/Location/LocationItem.cs @@ -0,0 +1,8 @@ +namespace CartriX.Shared.Models.Location +{ + public class LocationItem + { + public string Name { get; set; } = default!; + public List Printers { get; set; } = default!; + } +} diff --git a/CartriX.Shared/Models/Printer/PrinterItemList.cs b/CartriX.Shared/Models/Printer/PrinterItemList.cs new file mode 100644 index 0000000..ad4b09e --- /dev/null +++ b/CartriX.Shared/Models/Printer/PrinterItemList.cs @@ -0,0 +1,10 @@ +namespace CartriX.Shared.Models.Printer +{ + public class PrinterItemList + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public PrinterModelItem Model { get; set; } = default!; + public int StatusId { get; set; } + } +} diff --git a/CartriX.Shared/Models/Printer/PrinterModelItem.cs b/CartriX.Shared/Models/Printer/PrinterModelItem.cs index 1e6b9f5..3aba893 100644 --- a/CartriX.Shared/Models/Printer/PrinterModelItem.cs +++ b/CartriX.Shared/Models/Printer/PrinterModelItem.cs @@ -11,6 +11,10 @@ /// public ManufacturerItem Manufacturer { get; set; } = new(); /// + /// Путь к картинке + /// + public string? PicturePath { get; set; } + /// /// Идентификатор поддерживамого артикля /// public int SupportedArticleId { get; set; }