Skip to content

Commit 1b89444

Browse files
committed
ADD: PluApi - Ws.DeviceControl.Api
1 parent 865741c commit 1b89444

File tree

9 files changed

+161
-4
lines changed

9 files changed

+161
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using Ws.DeviceControl.Models.Dto.References1C.Plus.Queries;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.References1C.Plus.Common;
4+
5+
public interface IPluService : IGetApiService<PluDto>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Plus;
2+
using Ws.DeviceControl.Models.Dto.References1C.Plus.Queries;
3+
4+
namespace Ws.DeviceControl.Api.App.Features.References1C.Plus.Impl.Expressions;
5+
6+
public static class PluExpressions
7+
{
8+
public static Expression<Func<PluEntity, PluDto>> ToDto =>
9+
plu => new()
10+
{
11+
Id = plu.Id,
12+
Number = (ushort) plu.Number,
13+
IsWeight = plu.IsWeight,
14+
Weight = plu.Weight,
15+
Brand = new()
16+
{
17+
Id = plu.Brand.Id,
18+
Name = plu.Brand.Name
19+
},
20+
ShelfLifeDays = (ushort) plu.ShelfLifeDays,
21+
Template = plu.TemplateId != null ? new()
22+
{
23+
Id = plu.Template.Id,
24+
Name = plu.Template.Name
25+
} : null ,
26+
StorageMethod = plu.StorageMethod,
27+
Name = plu.Name,
28+
FullName = string.Empty,
29+
Description = string.Empty,
30+
Ean13 = plu.Ean13,
31+
Gtin = plu.Ean13,
32+
Clip = new()
33+
{
34+
Id = plu.Clip.Id,
35+
Name = plu.Clip.Name
36+
},
37+
Bundle = new()
38+
{
39+
Id = plu.Bundle.Id,
40+
Name = plu.Bundle.Name
41+
},
42+
CreateDt = plu.CreateDt,
43+
ChangeDt = plu.ChangeDt
44+
};
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Plus;
2+
using Ws.DeviceControl.Api.App.Features.References1C.Plus.Common;
3+
using Ws.DeviceControl.Api.App.Features.References1C.Plus.Impl.Expressions;
4+
using Ws.DeviceControl.Models.Dto.References1C.Plus.Queries;
5+
6+
namespace Ws.DeviceControl.Api.App.Features.References1C.Plus.Impl;
7+
8+
public class PluApiService(WsDbContext dbContext) : IPluService
9+
{
10+
#region Queries
11+
12+
public async Task<PluDto> GetByIdAsync(Guid id)
13+
{
14+
PluEntity? plu = await dbContext.Plus.FindAsync(id);
15+
if (plu == null) throw new KeyNotFoundException();
16+
return PluExpressions.ToDto.Compile().Invoke(plu);
17+
}
18+
19+
public Task<List<PluDto>> GetAllAsync()
20+
{
21+
return dbContext.Plus
22+
.AsNoTracking()
23+
.Select(PluExpressions.ToDto)
24+
.ToListAsync();
25+
}
26+
27+
#endregion
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Ws.DeviceControl.Api.App.Features.References1C.Plus.Common;
2+
using Ws.DeviceControl.Models.Dto.References1C.Plus.Queries;
3+
4+
namespace Ws.DeviceControl.Api.App.Features.References1C.Plus;
5+
6+
[ApiController]
7+
[Route("api/plu/")]
8+
public class PluController(IPluService pluService)
9+
{
10+
#region Queries
11+
12+
[HttpGet]
13+
public Task<List<PluDto>> GetAll() => pluService.GetAllAsync();
14+
15+
[HttpGet("{id:guid}")]
16+
public Task<PluDto> GetById([FromRoute] Guid id) => pluService.GetByIdAsync(id);
17+
18+
#endregion
19+
}

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/boxes/
1+
GET https://localhost:5138/api/plu/
22

33
###
44
GET https://localhost:5138/api/production-sites
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Text.Json.Serialization;
2+
using Ws.DeviceControl.Models.Dto.Shared;
3+
4+
namespace Ws.DeviceControl.Models.Dto.References1C.Plus.Queries;
5+
6+
public record PluDto
7+
{
8+
[JsonPropertyName("id")]
9+
public required Guid Id { get; set; }
10+
11+
[JsonPropertyName("number")]
12+
public required ushort Number { get; set; }
13+
14+
[JsonPropertyName("type")]
15+
public required bool IsWeight { get; set; }
16+
17+
[JsonPropertyName("weight")]
18+
public required decimal Weight { get; set; }
19+
20+
[JsonPropertyName("brand")]
21+
public required ProxyDto Brand { get; set; }
22+
23+
[JsonPropertyName("shelfLifeDays")]
24+
public required ushort ShelfLifeDays { get; set; }
25+
26+
[JsonPropertyName("template")]
27+
public required ProxyDto? Template { get; set; }
28+
29+
[JsonPropertyName("storageMethods")]
30+
public required string StorageMethod { get; set; }
31+
32+
[JsonPropertyName("name")]
33+
public required string Name { get; set; }
34+
35+
[JsonPropertyName("fullName")]
36+
public required string FullName { get; set; }
37+
38+
[JsonPropertyName("description")]
39+
public required string Description { get; set; }
40+
41+
[JsonPropertyName("ean13")]
42+
public required string Ean13 { get; set; }
43+
44+
[JsonPropertyName("gtin")]
45+
public required string Gtin { get; set; }
46+
47+
[JsonPropertyName("clip")]
48+
public required ProxyDto? Clip { get; set; }
49+
50+
[JsonPropertyName("bundle")]
51+
public required ProxyDto? Bundle { get; set; }
52+
53+
[JsonPropertyName("createDt")]
54+
public required DateTime CreateDt { get; set; }
55+
56+
[JsonPropertyName("changeDt")]
57+
public required DateTime ChangeDt { get; set; }
58+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.7" />
1212
<PackageReference Include="Refit" Version="7.1.2" />
1313
</ItemGroup>
14-
14+
1515
<ItemGroup>
1616
<ProjectReference Include="..\..\..\Libs\Ws.Shared\Ws.Shared.csproj" />
1717
</ItemGroup>

Src/Infrastructure/Ws.Database.EntityFramework/Entities/Ref1C/Plus/PluEntity.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Ws.Database.EntityFramework.Entities.Ref1C.Brands;
22
using Ws.Database.EntityFramework.Entities.Ref1C.Bundles;
33
using Ws.Database.EntityFramework.Entities.Ref1C.Clips;
4+
using Ws.Database.EntityFramework.Entities.Zpl.Templates;
45

56
namespace Ws.Database.EntityFramework.Entities.Ref1C.Plus;
67

@@ -34,9 +35,10 @@ public sealed class PluEntity : EfEntityBase
3435

3536
//
3637

37-
[ForeignKey("TEMPLATE_UID"), Column("TEMPLATE_UID")]
3838
public Guid? TemplateId { get; set; }
3939

40+
public TemplateEntity Template { get; set; } = new();
41+
4042
#region Date
4143

4244
public DateTime CreateDt { get; init; }

Src/Infrastructure/Ws.Database.EntityFramework/Entities/Ref1C/Plus/PluMapConfig.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Configure(EntityTypeBuilder<PluEntity> builder)
5454
builder.Property(e => e.TemplateId)
5555
.HasColumnName("TEMPLATE_UID");
5656

57-
builder.HasOne<TemplateEntity>()
57+
builder.HasOne(e => e.Template)
5858
.WithMany()
5959
.HasForeignKey(e => e.TemplateId)
6060
.HasConstraintName($"FK_{SqlTables.Plus}__TEMPLATE")

0 commit comments

Comments
 (0)