Skip to content

Commit 865741c

Browse files
committed
ADD: Box, Clip, Bundle, Brand services - Ws.DeviceControl.Api
1 parent 99794fa commit 865741c

30 files changed

+351
-39
lines changed

Src/Apps/Web/Ws.DeviceControl.Api/App/Features/Diag/Database/DatabaseController.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Microsoft.AspNetCore.Mvc;
21
using Ws.DeviceControl.Api.App.Features.Diag.Database.Common;
32
using Ws.DeviceControl.Models.Dto.Database;
43

Src/Apps/Web/Ws.DeviceControl.Api/App/Features/Diag/Database/Impl/DatabaseService.cs Src/Apps/Web/Ws.DeviceControl.Api/App/Features/Diag/Database/Impl/DatabaseApiService.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using System.Runtime.CompilerServices;
2-
using Microsoft.EntityFrameworkCore;
3-
using Ws.Database.EntityFramework;
42
using Ws.DeviceControl.Api.App.Features.Diag.Database.Common;
53
using Ws.DeviceControl.Models.Dto.Database;
64

75
namespace Ws.DeviceControl.Api.App.Features.Diag.Database.Impl;
86

9-
public class DatabaseService(WsDbContext dbContext) : IDatabaseService
7+
public class DatabaseApiService(WsDbContext dbContext) : IDatabaseService
108
{
119
public List<MigrationHistoryDto> GetAllMigrations()
1210
{

Src/Apps/Web/Ws.DeviceControl.Api/App/Features/References/ProductionSites/Common/IProductionSiteService.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
namespace Ws.DeviceControl.Api.App.Features.References.ProductionSites.Common;
66

7-
public interface IProductionSiteService
7+
public interface IProductionSiteService : IGetApiService<ProductionSiteDto>
88
{
9-
#region Queries
10-
11-
Task<List<ProductionSiteDto>> GetAllAsync();
12-
13-
#endregion
14-
159
#region Commands
1610

1711
Task<ProductionSiteDto> CreateAsync(ProductionSiteCreateDto dto);

Src/Apps/Web/Ws.DeviceControl.Api/App/Features/References/ProductionSites/Impl/Expressions/ProductionSiteExpressions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Linq.Expressions;
21
using Ws.Database.EntityFramework.Entities.Ref.ProductionSites;
32
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Queries;
43

Src/Apps/Web/Ws.DeviceControl.Api/App/Features/References/ProductionSites/Impl/ProductionSiteService.cs Src/Apps/Web/Ws.DeviceControl.Api/App/Features/References/ProductionSites/Impl/ProductionSiteApiService.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using Microsoft.EntityFrameworkCore;
2-
using Microsoft.EntityFrameworkCore.ChangeTracking;
3-
using Ws.Database.EntityFramework;
41
using Ws.Database.EntityFramework.Entities.Ref.ProductionSites;
52
using Ws.DeviceControl.Api.App.Features.References.ProductionSites.Common;
63
using Ws.DeviceControl.Api.App.Features.References.ProductionSites.Impl.Expressions;
@@ -10,10 +7,17 @@
107

118
namespace Ws.DeviceControl.Api.App.Features.References.ProductionSites.Impl;
129

13-
public class ProductionSiteService(WsDbContext dbContext): IProductionSiteService
10+
public class ProductionSiteApiService(WsDbContext dbContext): IProductionSiteService
1411
{
1512
#region Queries
1613

14+
public async Task<ProductionSiteDto> GetByIdAsync(Guid id)
15+
{
16+
ProductionSiteEntity? site = await dbContext.ProductionSites.FindAsync(id);
17+
if (site == null) throw new KeyNotFoundException();
18+
return ProductionSiteExpressions.ToDto.Compile().Invoke(site);
19+
}
20+
1721
public Task<List<ProductionSiteDto>> GetAllAsync() => dbContext.ProductionSites
1822
.AsNoTracking().Select(ProductionSiteExpressions.ToDto)
1923
.OrderBy(i => i.Name)

Src/Apps/Web/Ws.DeviceControl.Api/App/Features/References/ProductionSites/ProductionSiteController.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Microsoft.AspNetCore.Mvc;
21
using Ws.DeviceControl.Api.App.Features.References.ProductionSites.Common;
32
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Commands.Create;
43
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Commands.Update;
@@ -13,7 +12,10 @@ public class ProductionSiteController(IProductionSiteService productionSiteServi
1312
#region Queries
1413

1514
[HttpGet]
16-
public Task<List<ProductionSiteDto>> GetAllMigrations() => productionSiteService.GetAllAsync();
15+
public Task<List<ProductionSiteDto>> GetAll() => productionSiteService.GetAllAsync();
16+
17+
[HttpGet("{id:guid}")]
18+
public Task<ProductionSiteDto> GetById([FromRoute] Guid id) => productionSiteService.GetByIdAsync(id);
1719

1820
#endregion
1921

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Ws.DeviceControl.Api.App.Features.References1C.Boxes.Common;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.References1C.Boxes;
4+
5+
[ApiController]
6+
[Route("api/boxes/")]
7+
public class BoxController(IBoxService boxService)
8+
{
9+
#region Queries
10+
11+
[HttpGet]
12+
public Task<List<PackageDto>> GetAll() => boxService.GetAllAsync();
13+
14+
[HttpGet("{id:guid}")]
15+
public Task<PackageDto> GetById([FromRoute] Guid id) => boxService.GetByIdAsync(id);
16+
17+
#endregion
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Ws.DeviceControl.Api.App.Features.References1C.Boxes.Common;
2+
3+
public interface IBoxService : IGetApiService<PackageDto>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Boxes;
2+
using Ws.DeviceControl.Api.App.Features.References1C.Boxes.Common;
3+
using Ws.DeviceControl.Api.App.Features.References1C.Boxes.Impl.Expressions;
4+
5+
namespace Ws.DeviceControl.Api.App.Features.References1C.Boxes.Impl;
6+
7+
public class BoxApiService(WsDbContext dbContext) : IBoxService
8+
{
9+
#region Queries
10+
11+
public async Task<PackageDto> GetByIdAsync(Guid id)
12+
{
13+
BoxEntity? box = await dbContext.Boxes.FindAsync(id);
14+
if (box == null) throw new KeyNotFoundException();
15+
return BoxExpressions.ToDto.Compile().Invoke(box);
16+
}
17+
18+
public Task<List<PackageDto>> GetAllAsync()
19+
{
20+
return dbContext.Boxes
21+
.AsNoTracking().Select(BoxExpressions.ToDto)
22+
.OrderBy(i => i.Weight).ThenBy(i => i.Name)
23+
.ToListAsync();
24+
}
25+
26+
#endregion
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Boxes;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.References1C.Boxes.Impl.Expressions;
4+
5+
public static class BoxExpressions
6+
{
7+
public static Expression<Func<BoxEntity, PackageDto>> ToDto =>
8+
box => new()
9+
{
10+
Id = box.Id,
11+
Name = box.Name,
12+
Weight = box.Weight,
13+
CreateDt = box.CreateDt,
14+
ChangeDt = box.ChangeDt
15+
};
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Ws.DeviceControl.Api.App.Features.References1C.Brands.Common;
2+
using Ws.DeviceControl.Models.Dto.References1C.Brands;
3+
4+
namespace Ws.DeviceControl.Api.App.Features.References1C.Brands;
5+
6+
7+
[ApiController]
8+
[Route("api/brands/")]
9+
public class BrandController(IBrandService brandService)
10+
{
11+
#region Queries
12+
13+
[HttpGet]
14+
public Task<List<BrandDto>> GetAll() => brandService.GetAllAsync();
15+
16+
[HttpGet("{id:guid}")]
17+
public Task<BrandDto> GetById([FromRoute] Guid id) => brandService.GetByIdAsync(id);
18+
19+
#endregion
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using Ws.DeviceControl.Models.Dto.References1C.Brands;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.References1C.Brands.Common;
4+
5+
public interface IBrandService : IGetApiService<BrandDto>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Brands;
2+
using Ws.DeviceControl.Api.App.Features.References1C.Brands.Common;
3+
using Ws.DeviceControl.Api.App.Features.References1C.Brands.Impl.Expressions;
4+
using Ws.DeviceControl.Models.Dto.References1C.Brands;
5+
6+
namespace Ws.DeviceControl.Api.App.Features.References1C.Brands.Impl;
7+
8+
public class BrandApiService(WsDbContext dbContext) : IBrandService
9+
{
10+
#region Queries
11+
12+
public async Task<BrandDto> GetByIdAsync(Guid id)
13+
{
14+
BrandEntity? brand = await dbContext.Brands.FindAsync(id);
15+
if (brand == null) throw new KeyNotFoundException();
16+
return BrandExpressions.ToDto.Compile().Invoke(brand);
17+
}
18+
19+
public Task<List<BrandDto>> GetAllAsync()
20+
{
21+
return dbContext.Brands
22+
.AsNoTracking().Select(BrandExpressions.ToDto)
23+
.OrderBy(i => i.Name)
24+
.ToListAsync();
25+
}
26+
27+
#endregion
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Brands;
2+
using Ws.DeviceControl.Models.Dto.References1C.Brands;
3+
4+
namespace Ws.DeviceControl.Api.App.Features.References1C.Brands.Impl.Expressions;
5+
6+
public static class BrandExpressions
7+
{
8+
public static Expression<Func<BrandEntity, BrandDto>> ToDto =>
9+
brand => new()
10+
{
11+
Id = brand.Id,
12+
Name = brand.Name,
13+
CreateDt = brand.CreateDt,
14+
ChangeDt = brand.ChangeDt
15+
};
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Ws.DeviceControl.Api.App.Features.References1C.Bundles.Common;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.References1C.Bundles;
4+
5+
[ApiController]
6+
[Route("api/bundles/")]
7+
public class BundleController(IBundleService bundleService)
8+
{
9+
#region Queries
10+
11+
[HttpGet]
12+
public Task<List<PackageDto>> GetAll() => bundleService.GetAllAsync();
13+
14+
[HttpGet("{id:guid}")]
15+
public Task<PackageDto> GetById([FromRoute] Guid id) => bundleService.GetByIdAsync(id);
16+
17+
#endregion
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Ws.DeviceControl.Api.App.Features.References1C.Bundles.Common;
2+
3+
public interface IBundleService : IGetApiService<PackageDto>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Bundles;
2+
using Ws.DeviceControl.Api.App.Features.References1C.Bundles.Common;
3+
using Ws.DeviceControl.Api.App.Features.References1C.Bundles.Impl.Expressions;
4+
5+
namespace Ws.DeviceControl.Api.App.Features.References1C.Bundles.Impl;
6+
7+
public class BundleApiService(WsDbContext dbContext) : IBundleService
8+
{
9+
#region Queries
10+
11+
public async Task<PackageDto> GetByIdAsync(Guid id)
12+
{
13+
BundleEntity? bundle = await dbContext.Bundles.FindAsync(id);
14+
if (bundle == null) throw new KeyNotFoundException();
15+
return BundleExpressions.ToDto.Compile().Invoke(bundle);
16+
}
17+
18+
public Task<List<PackageDto>> GetAllAsync()
19+
{
20+
return dbContext.Bundles
21+
.AsNoTracking().Select(BundleExpressions.ToDto)
22+
.OrderBy(i => i.Weight).ThenBy(i => i.Name)
23+
.ToListAsync();
24+
}
25+
26+
#endregion
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Bundles;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.References1C.Bundles.Impl.Expressions;
4+
5+
public static class BundleExpressions
6+
{
7+
public static Expression<Func<BundleEntity, PackageDto>> ToDto =>
8+
bundle => new()
9+
{
10+
Id = bundle.Id,
11+
Name = bundle.Name,
12+
Weight = bundle.Weight,
13+
CreateDt = bundle.CreateDt,
14+
ChangeDt = bundle.ChangeDt
15+
};
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Ws.DeviceControl.Api.App.Features.References1C.Clips.Common;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.References1C.Clips;
4+
5+
[ApiController]
6+
[Route("api/clips/")]
7+
public class ClipController(IClipService clipService)
8+
{
9+
#region Queries
10+
11+
[HttpGet]
12+
public Task<List<PackageDto>> GetAll() => clipService.GetAllAsync();
13+
14+
[HttpGet("{id:guid}")]
15+
public Task<PackageDto> GetById([FromRoute] Guid id) => clipService.GetByIdAsync(id);
16+
17+
#endregion
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Ws.DeviceControl.Api.App.Features.References1C.Clips.Common;
2+
3+
public interface IClipService : IGetApiService<PackageDto>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Clips;
2+
using Ws.DeviceControl.Api.App.Features.References1C.Clips.Common;
3+
using Ws.DeviceControl.Api.App.Features.References1C.Clips.Impl.Expressions;
4+
5+
namespace Ws.DeviceControl.Api.App.Features.References1C.Clips.Impl;
6+
7+
public class ClipApiService(WsDbContext dbContext) : IClipService
8+
{
9+
#region Queries
10+
11+
public async Task<PackageDto> GetByIdAsync(Guid id)
12+
{
13+
ClipEntity? clip = await dbContext.Clips.FindAsync(id);
14+
if (clip == null) throw new KeyNotFoundException();
15+
return ClipExpressions.ToDto.Compile().Invoke(clip);
16+
}
17+
18+
public Task<List<PackageDto>> GetAllAsync()
19+
{
20+
return dbContext.Clips
21+
.AsNoTracking().Select(ClipExpressions.ToDto)
22+
.OrderBy(i => i.Weight).ThenBy(i => i.Name)
23+
.ToListAsync();
24+
}
25+
26+
#endregion
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Ws.Database.EntityFramework.Entities.Ref1C.Clips;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.References1C.Clips.Impl.Expressions;
4+
5+
public static class ClipExpressions
6+
{
7+
public static Expression<Func<ClipEntity, PackageDto>> ToDto =>
8+
clip => new()
9+
{
10+
Id = clip.Id,
11+
Name = clip.Name,
12+
Weight = clip.Weight,
13+
CreateDt = clip.CreateDt,
14+
ChangeDt = clip.ChangeDt
15+
};
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Ws.DeviceControl.Api.App.Shared;
2+
3+
public interface IGetApiService<T>
4+
{
5+
public Task<T> GetByIdAsync(Guid id);
6+
public Task<List<T>> GetAllAsync();
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
global using System.Linq.Expressions;
2+
global using Ws.DeviceControl.Models.Dto.Shared;
3+
4+
global using Microsoft.AspNetCore.Mvc;
5+
global using Ws.Database.EntityFramework;
6+
7+
global using Microsoft.EntityFrameworkCore;
8+
global using Ws.Database.EntityFramework;
9+
10+
global using Ws.DeviceControl.Api.App.Shared;

0 commit comments

Comments
 (0)