Skip to content

Commit 4749c4c

Browse files
committed
ADD: PalletMan api - Ws.DeviceControl.Api
1 parent 609af1a commit 4749c4c

File tree

9 files changed

+123
-3
lines changed

9 files changed

+123
-3
lines changed

Src/Apps/Desktop/Ws.Desktop.Models/Features/PalletMen/PalletMan.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Text.Json.Serialization;
2-
using Ws.Desktop.Models.ValueTypes;
2+
using Ws.Shared.Api.ValueTypes;
33

44
namespace Ws.Desktop.Models.Features.PalletMen;
55

Src/Apps/Desktop/Ws.Desktop.Models/Features/Pallets/Output/PalletInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Text.Json.Serialization;
2-
using Ws.Desktop.Models.ValueTypes;
2+
using Ws.Shared.Api.ValueTypes;
33

44
namespace Ws.Desktop.Models.Features.Pallets.Output;
55

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Ws.DeviceControl.Models.Dto.Admins.PalletMen.Queries;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.Admins.PalletMen.Common;
4+
5+
public interface IPalletManService
6+
{
7+
#region Queries
8+
9+
Task<PalletManDto> GetByIdAsync(Guid id);
10+
Task<List<PalletManDto>> GetAllByProductionSiteAsync(Guid productionSiteId);
11+
12+
#endregion
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Ws.Database.EntityFramework.Entities.Ref.PalletMen;
2+
using Ws.DeviceControl.Models.Dto.Admins.PalletMen.Queries;
3+
4+
namespace Ws.DeviceControl.Api.App.Features.Admins.PalletMen.Impl.Expressions;
5+
6+
public static class PalletManExpressions
7+
{
8+
public static Expression<Func<PalletManEntity, PalletManDto>> ToDto =>
9+
palletMan => new()
10+
{
11+
Id = palletMan.Id,
12+
Id1C = palletMan.Uid1C,
13+
Fio = new()
14+
{
15+
Name = palletMan.Name,
16+
Surname = palletMan.Surname,
17+
Patronymic = palletMan.Patronymic
18+
},
19+
Password = palletMan.Password,
20+
Warehouse = new()
21+
{
22+
Id = palletMan.Warehouse.Id,
23+
Name = palletMan.Warehouse.Name
24+
},
25+
CreateDt = palletMan.CreateDt,
26+
ChangeDt = palletMan.ChangeDt
27+
};
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Ws.Database.EntityFramework.Entities.Ref.PalletMen;
2+
using Ws.DeviceControl.Api.App.Features.Admins.PalletMen.Common;
3+
using Ws.DeviceControl.Api.App.Features.Admins.PalletMen.Impl.Expressions;
4+
using Ws.DeviceControl.Models.Dto.Admins.PalletMen.Queries;
5+
6+
namespace Ws.DeviceControl.Api.App.Features.Admins.PalletMen.Impl;
7+
8+
public class PalletManApiService(WsDbContext dbContext) : IPalletManService
9+
{
10+
#region Queries
11+
12+
public Task<List<PalletManDto>> GetAllByProductionSiteAsync(Guid productionSiteId)
13+
{
14+
return dbContext.PalletMen
15+
.AsNoTracking()
16+
.Where(i => i.Warehouse.ProductionSite.Id == productionSiteId)
17+
.Select(PalletManExpressions.ToDto)
18+
.ToListAsync();
19+
}
20+
21+
public async Task<PalletManDto> GetByIdAsync(Guid id)
22+
{
23+
PalletManEntity? palletMan = await dbContext.PalletMen.FindAsync(id);
24+
if (palletMan == null) throw new KeyNotFoundException();
25+
return PalletManExpressions.ToDto.Compile().Invoke(palletMan);
26+
}
27+
28+
#endregion
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Ws.DeviceControl.Api.App.Features.Admins.PalletMen.Common;
2+
using Ws.DeviceControl.Models.Dto.Admins.PalletMen.Queries;
3+
4+
namespace Ws.DeviceControl.Api.App.Features.Admins.PalletMen;
5+
6+
[ApiController]
7+
[Route("api/pallet-men/")]
8+
public class PrinterController(IPalletManService palletManService)
9+
{
10+
#region Queries
11+
12+
[HttpGet]
13+
public Task<List<PalletManDto>> GetAllByProductionSite([FromQuery(Name = "productionSite")] Guid productionSiteId) =>
14+
palletManService.GetAllByProductionSiteAsync(productionSiteId);
15+
16+
[HttpGet("{id:guid}")]
17+
public Task<PalletManDto> GetById([FromRoute] Guid id) => palletManService.GetByIdAsync(id);
18+
19+
#endregion
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Text.Json.Serialization;
2+
using Ws.DeviceControl.Models.Dto.Shared;
3+
using Ws.Shared.Api.ValueTypes;
4+
5+
namespace Ws.DeviceControl.Models.Dto.Admins.PalletMen.Queries;
6+
7+
public class PalletManDto
8+
{
9+
[JsonPropertyName("id")]
10+
public required Guid Id { get; init; }
11+
12+
[JsonPropertyName("id1C")]
13+
public required Guid Id1C { get; init; }
14+
15+
[JsonPropertyName("fio")]
16+
public required Fio Fio { get; init; }
17+
18+
[JsonPropertyName("password")]
19+
public required string Password { get; init; }
20+
21+
[JsonPropertyName("warehouse")]
22+
public required ProxyDto Warehouse { get; init; }
23+
24+
[JsonPropertyName("createDt")]
25+
public required DateTime CreateDt { get; init; }
26+
27+
[JsonPropertyName("changeDt")]
28+
public required DateTime ChangeDt { get; init; }
29+
}

Src/Apps/Web/Ws.DeviceControl.Models/Dto/Devices/Printers/Queries/PrinterDto.cs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public record PrinterDto
1818
public required IPAddress Ip { get; set; }
1919

2020
[JsonPropertyName("type")]
21+
[JsonConverter(typeof(EnumJsonConverter<PrinterTypes>))]
2122
public required PrinterTypes Type { get; set; }
2223

2324
[JsonPropertyName("createDt")]

Src/Apps/Desktop/Ws.Desktop.Models/ValueTypes/Fio.cs Src/Libs/Ws.Shared/Api/ValueTypes/Fio.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Text.Json.Serialization;
22
using Ws.Shared.Extensions;
33

4-
namespace Ws.Desktop.Models.ValueTypes;
4+
namespace Ws.Shared.Api.ValueTypes;
55

66
public sealed record Fio
77
{

0 commit comments

Comments
 (0)