Skip to content

Commit 9083885

Browse files
committed
ADD: Arm api - Ws.DeviceControl.Api
1 parent eb8f714 commit 9083885

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Ws.DeviceControl.Api.App.Features.Devices.Arms.Common;
2+
using Ws.DeviceControl.Models.Dto.Devices.Arms.Queries;
3+
4+
namespace Ws.DeviceControl.Api.App.Features.Devices.Arms;
5+
6+
[ApiController]
7+
[Route("api/arms/")]
8+
public class ArmController(IArmService armService)
9+
{
10+
#region Queries
11+
12+
[HttpGet]
13+
public Task<List<ArmDto>> GetAllByProductionSite([FromQuery(Name = "productionSite")] Guid productionSiteId) =>
14+
armService.GetAllByProductionSiteAsync(productionSiteId);
15+
16+
[HttpGet("{id:guid}")]
17+
public Task<ArmDto> GetById([FromRoute] Guid id) => armService.GetByIdAsync(id);
18+
19+
#endregion
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Ws.DeviceControl.Models.Dto.Devices.Arms.Queries;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.Devices.Arms.Common;
4+
5+
public interface IArmService
6+
{
7+
#region Queries
8+
9+
Task<List<ArmDto>> GetAllByProductionSiteAsync(Guid productionSiteId);
10+
Task<ArmDto> GetByIdAsync(Guid id);
11+
12+
#endregion
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Ws.Database.EntityFramework.Entities.Ref.Lines;
2+
using Ws.DeviceControl.Api.App.Features.Devices.Arms.Common;
3+
using Ws.DeviceControl.Api.App.Features.Devices.Arms.Impl.Expressions;
4+
using Ws.DeviceControl.Models.Dto.Devices.Arms.Queries;
5+
6+
namespace Ws.DeviceControl.Api.App.Features.Devices.Arms.Impl;
7+
8+
public class ArmApiService(WsDbContext dbContext) : IArmService
9+
{
10+
#region Queries
11+
12+
public Task<List<ArmDto>> GetAllByProductionSiteAsync(Guid productionSiteId)
13+
{
14+
return dbContext.Lines
15+
.AsNoTracking()
16+
.Where(i => i.Warehouse.ProductionSite.Id == productionSiteId)
17+
.Select(ArmExpressions.ToDto)
18+
.OrderBy(i => i.Name)
19+
.ToListAsync();
20+
}
21+
22+
public async Task<ArmDto> GetByIdAsync(Guid id)
23+
{
24+
LineEntity? line = await dbContext.Lines.FindAsync(id);
25+
if (line == null) throw new KeyNotFoundException();
26+
return ArmExpressions.ToDto.Compile().Invoke(line);
27+
}
28+
29+
#endregion
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Ws.Database.EntityFramework.Entities.Ref.Lines;
2+
using Ws.DeviceControl.Models.Dto.Devices.Arms.Queries;
3+
4+
namespace Ws.DeviceControl.Api.App.Features.Devices.Arms.Impl.Expressions;
5+
6+
public static class ArmExpressions
7+
{
8+
public static Expression<Func<LineEntity, ArmDto>> ToDto =>
9+
arm => new()
10+
{
11+
Id = arm.Id,
12+
Name = arm.Name,
13+
Version = arm.Version,
14+
Type = arm.Type,
15+
Number = arm.Number,
16+
Counter = (uint)arm.Counter,
17+
PcName = arm.PcName,
18+
Printer = new()
19+
{
20+
Id = arm.Printer.Id,
21+
Name = arm.Printer.Name
22+
},
23+
Warehouse = new()
24+
{
25+
Id = arm.Warehouse.Id,
26+
Name = arm.Warehouse.Name
27+
},
28+
CreateDt = arm.CreateDt,
29+
ChangeDt = arm.ChangeDt
30+
};
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Text.Json.Serialization;
2+
using Ws.DeviceControl.Models.Dto.Shared;
3+
using Ws.Shared.Converters.Json;
4+
using Ws.Shared.Enums;
5+
6+
namespace Ws.DeviceControl.Models.Dto.Devices.Arms.Queries;
7+
8+
public record ArmDto
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 string Version { get; set; }
19+
20+
[JsonPropertyName("type")]
21+
[JsonConverter(typeof(EnumJsonConverter<ArmType>))]
22+
public required ArmType Type { get; set; }
23+
24+
[JsonPropertyName("number")]
25+
public required int Number { get; set; }
26+
27+
[JsonPropertyName("counter")]
28+
public required uint Counter { get; set; }
29+
30+
[JsonPropertyName("pc")]
31+
public required string PcName { get; set; }
32+
33+
[JsonPropertyName("printer")]
34+
public required ProxyDto Printer { get; set; }
35+
36+
[JsonPropertyName("warehouse")]
37+
public required ProxyDto Warehouse { get; set; }
38+
39+
[JsonPropertyName("createDt")]
40+
public required DateTime CreateDt { get; set; }
41+
42+
[JsonPropertyName("changeDt")]
43+
public required DateTime ChangeDt { get; set; }
44+
}

0 commit comments

Comments
 (0)