mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-06 13:00:55 +00:00
Сделал модель данных для списка принеров
This commit is contained in:
1 parent
4dfb62e9e8
commit
9cc166e37d
11 files changed
+87
-1
No files matched your search
@@ -0,0 +1,7 @@
|
||||
namespace CartriX.Api.Controllers.Location
|
||||
{
|
||||
public interface ILocationService
|
||||
{
|
||||
public Task<List<Entities.Location>> List();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить список местоположений
|
||||
/// </summary>
|
||||
[ProducesResponseType(typeof(List<Shared.Models.Location.LocationItem>), StatusCodes.Status200OK)]
|
||||
[HttpGet(nameof(List))]
|
||||
public async Task<ActionResult> List()
|
||||
{
|
||||
return Ok((await _locationService.List()).Select(l => l.ToItem()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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<Entities.Location>> List() => await _context.Locations.ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user