Skip to content

Commit bf45b96

Browse files
committed
ADD: PrinterApi - Ws.Desktop.Api
1 parent 1b89444 commit bf45b96

File tree

9 files changed

+136
-3
lines changed

9 files changed

+136
-3
lines changed

Src/Apps/Desktop/Ws.Desktop.Api/App/Features/Pallets/Impl/PalletApiService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public async Task<PalletInfo> CreatePiecePallet(Guid armId, PalletPieceCreateDto
7171
var plu = pluService.GetItemByUid(dto.PluId);
7272
List<PluCharacteristic> characteristic = plu.CharacteristicsWithNesting.ToList();
7373

74-
var data = new GeneratePiecePalletDto
74+
GeneratePiecePalletDto data = new()
7575
{
7676
Plu = pluService.GetItemByUid(dto.PluId),
7777
Line = armService.GetItemByUid(armId),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Ws.DeviceControl.Models.Dto.Devices.Printers.Queries;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.Devices.Printers.Common;
4+
5+
public interface IPrinterService
6+
{
7+
#region Queries
8+
9+
Task<List<PrinterDto>> GetAllByProductionSiteAsync(Guid productionSiteId);
10+
Task<List<ProxyDto>> GetProxiesByProductionSiteAsync(Guid productionSiteId);
11+
12+
Task<PrinterDto> GetByIdAsync(Guid id);
13+
14+
#endregion
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using TscZebra.Plugin.Abstractions.Enums;
2+
using Ws.Database.EntityFramework.Entities.Ref.Printers;
3+
using Ws.DeviceControl.Models.Dto.Devices.Printers.Queries;
4+
5+
namespace Ws.DeviceControl.Api.App.Features.Devices.Printers.Impl.Expressions;
6+
7+
public static class PrinterExpressions
8+
{
9+
public static Expression<Func<PrinterEntity, PrinterDto>> ToDto =>
10+
printer => new()
11+
{
12+
Id = printer.Id,
13+
Name = printer.Name,
14+
Ip = printer.Ip,
15+
Type = printer.Type,
16+
CreateDt = printer.CreateDt,
17+
ChangeDt = printer.ChangeDt
18+
};
19+
20+
public static Expression<Func<PrinterEntity, ProxyDto>> ToProxy =>
21+
printer => new()
22+
{
23+
Id = printer.Id,
24+
Name = printer.Name + " | " + printer.Ip
25+
};
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Ws.Database.EntityFramework.Entities.Ref.Printers;
2+
using Ws.DeviceControl.Api.App.Features.Devices.Printers.Common;
3+
using Ws.DeviceControl.Api.App.Features.Devices.Printers.Impl.Expressions;
4+
using Ws.DeviceControl.Models.Dto.Devices.Printers.Queries;
5+
6+
namespace Ws.DeviceControl.Api.App.Features.Devices.Printers.Impl;
7+
8+
public class PrinterApiService(WsDbContext dbContext) : IPrinterService
9+
{
10+
#region Queries
11+
12+
public Task<List<PrinterDto>> GetAllByProductionSiteAsync(Guid productionSiteId)
13+
{
14+
return dbContext.Printers
15+
.AsNoTracking()
16+
.Where(i => i.ProductionSite.Id == productionSiteId)
17+
.Select(PrinterExpressions.ToDto)
18+
.OrderBy(i => i.Type).ThenBy(i => i.Name)
19+
.ToListAsync();
20+
}
21+
22+
public Task<List<ProxyDto>> GetProxiesByProductionSiteAsync(Guid productionSiteId)
23+
{
24+
return dbContext.Printers
25+
.Where(i => i.ProductionSite.Id == productionSiteId)
26+
.Select(PrinterExpressions.ToProxy)
27+
.OrderBy(i => i.Name)
28+
.ToListAsync();
29+
}
30+
31+
public async Task<PrinterDto> GetByIdAsync(Guid id)
32+
{
33+
PrinterEntity? printer = await dbContext.Printers.FindAsync(id);
34+
if (printer == null) throw new KeyNotFoundException();
35+
return PrinterExpressions.ToDto.Compile().Invoke(printer);
36+
}
37+
38+
#endregion
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Ws.DeviceControl.Api.App.Features.Devices.Printers.Common;
2+
using Ws.DeviceControl.Models.Dto.Devices.Printers.Queries;
3+
4+
namespace Ws.DeviceControl.Api.App.Features.Devices.Printers;
5+
6+
[ApiController]
7+
[Route("api/printers/")]
8+
public class PrinterController(IPrinterService printerService)
9+
{
10+
#region Queries
11+
12+
[HttpGet("proxy")]
13+
public Task<List<ProxyDto>> GetProxiesByProductionSite([FromQuery(Name = "productionSite")] Guid productionSiteId) =>
14+
printerService.GetProxiesByProductionSiteAsync(productionSiteId);
15+
16+
[HttpGet]
17+
public Task<List<PrinterDto>> GetAllByProductionSite([FromQuery(Name = "productionSite")] Guid productionSiteId) =>
18+
printerService.GetAllByProductionSiteAsync(productionSiteId);
19+
20+
[HttpGet("{id:guid}")]
21+
public Task<PrinterDto> GetById([FromRoute] Guid id) => printerService.GetByIdAsync(id);
22+
23+
#endregion
24+
}

Src/Apps/Web/Ws.DeviceControl.Api/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
});
3838

3939

40-
var app = builder.Build();
40+
WebApplication app = builder.Build();
4141

4242
app.UseHttpsRedirection();
4343
app.MapControllers();

Src/Apps/Web/Ws.DeviceControl.Api/Rest/References1C.http

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GET https://localhost:5138/api/plu/
1+
GET https://localhost:5138/api/printers/?productionSite=ffffffff-ffff-ffff-ffff-ffffffffffff
22

33
###
44
GET https://localhost:5138/api/production-sites
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Net;
2+
using System.Text.Json.Serialization;
3+
using TscZebra.Plugin.Abstractions.Enums;
4+
using Ws.Shared.Converters.Json;
5+
6+
namespace Ws.DeviceControl.Models.Dto.Devices.Printers.Queries;
7+
8+
public record PrinterDto
9+
{
10+
[JsonPropertyName("id")]
11+
public required Guid Id { get; set; }
12+
13+
[JsonPropertyName("name")]
14+
public required string Name { get; set; }
15+
16+
[JsonPropertyName("ip")]
17+
[JsonConverter(typeof(IpAddressJsonConverter))]
18+
public required IPAddress Ip { get; set; }
19+
20+
[JsonPropertyName("type")]
21+
public required PrinterTypes Type { get; set; }
22+
23+
[JsonPropertyName("createDt")]
24+
public required DateTime CreateDt { get; set; }
25+
26+
[JsonPropertyName("changeDt")]
27+
public required DateTime ChangeDt { get; set; }
28+
}

Src/Apps/Web/Ws.DeviceControl.Models/Ws.DeviceControl.Models.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<PackageReference Include="FluentValidation" Version="11.9.2" />
1111
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.7" />
1212
<PackageReference Include="Refit" Version="7.1.2" />
13+
<PackageReference Include="TscZebra.Plugin.Abstractions" Version="1.0.4" />
1314
</ItemGroup>
1415

1516
<ItemGroup>

0 commit comments

Comments
 (0)