Commit 609af1a 1 parent bf45b96 commit 609af1a Copy full SHA for 609af1a
File tree 6 files changed +123
-1
lines changed
App/Features/References/Warehouses
Ws.DeviceControl.Models/Dto/References/Warehouses/Queries
6 files changed +123
-1
lines changed Original file line number Diff line number Diff line change
1
+ using Ws . DeviceControl . Models . Dto . References . Warehouses . Queries ;
2
+
3
+ namespace Ws . DeviceControl . Api . App . Features . References . Warehouses . Common ;
4
+
5
+ public interface IWarehouseService
6
+ {
7
+ #region Queries
8
+
9
+ Task < WarehouseDto > GetByIdAsync ( Guid id ) ;
10
+ Task < List < ProxyDto > > GetProxiesByProductionSiteAsync ( Guid productionSiteId ) ;
11
+ Task < List < WarehouseDto > > GetAllByProductionSiteAsync ( Guid productionSiteId ) ;
12
+
13
+ #endregion
14
+ }
Original file line number Diff line number Diff line change
1
+ using Ws . Database . EntityFramework . Entities . Ref . Warehouses ;
2
+ using Ws . DeviceControl . Models . Dto . References . Warehouses . Queries ;
3
+
4
+ namespace Ws . DeviceControl . Api . App . Features . References . Warehouses . Impl . Expressions ;
5
+
6
+ public static class WarehouseExpressions
7
+ {
8
+ public static Expression < Func < WarehouseEntity , WarehouseDto > > ToDto =>
9
+ warehouse => new ( )
10
+ {
11
+ Id = warehouse . Id ,
12
+ Id1C = warehouse . Uid1C ,
13
+ Name = warehouse . Name ,
14
+ CreateDt = warehouse . CreateDt ,
15
+ ChangeDt = warehouse . ChangeDt
16
+ } ;
17
+
18
+ public static Expression < Func < WarehouseEntity , ProxyDto > > ToProxy =>
19
+ warehouse => new ( )
20
+ {
21
+ Id = warehouse . Id ,
22
+ Name = warehouse . Name ,
23
+ } ;
24
+ }
Original file line number Diff line number Diff line change
1
+ using Ws . Database . EntityFramework . Entities . Ref . Warehouses ;
2
+ using Ws . DeviceControl . Api . App . Features . References . Warehouses . Common ;
3
+ using Ws . DeviceControl . Api . App . Features . References . Warehouses . Impl . Expressions ;
4
+ using Ws . DeviceControl . Models . Dto . References . Warehouses . Queries ;
5
+
6
+ namespace Ws . DeviceControl . Api . App . Features . References . Warehouses . Impl ;
7
+
8
+ public class WarehouseApiService ( WsDbContext dbContext ) : IWarehouseService
9
+ {
10
+ #region Queries
11
+
12
+ public Task < List < WarehouseDto > > GetAllByProductionSiteAsync ( Guid productionSiteId )
13
+ {
14
+ return dbContext . Warehouses
15
+ . AsNoTracking ( )
16
+ . Where ( i => i . ProductionSite . Id == productionSiteId )
17
+ . Select ( WarehouseExpressions . ToDto )
18
+ . OrderBy ( i => i . Name )
19
+ . ToListAsync ( ) ;
20
+ }
21
+
22
+ public Task < List < ProxyDto > > GetProxiesByProductionSiteAsync ( Guid productionSiteId )
23
+ {
24
+ return dbContext . Warehouses
25
+ . Where ( i => i . ProductionSite . Id == productionSiteId )
26
+ . Select ( WarehouseExpressions . ToProxy )
27
+ . OrderBy ( i => i . Name )
28
+ . ToListAsync ( ) ;
29
+ }
30
+
31
+ public async Task < WarehouseDto > GetByIdAsync ( Guid id )
32
+ {
33
+ WarehouseEntity ? warehouse = await dbContext . Warehouses . FindAsync ( id ) ;
34
+ if ( warehouse == null ) throw new KeyNotFoundException ( ) ;
35
+ return WarehouseExpressions . ToDto . Compile ( ) . Invoke ( warehouse ) ;
36
+ }
37
+
38
+ #endregion
39
+ }
Original file line number Diff line number Diff line change
1
+ using Ws . DeviceControl . Api . App . Features . References . Warehouses . Common ;
2
+ using Ws . DeviceControl . Models . Dto . References . Warehouses . Queries ;
3
+
4
+ namespace Ws . DeviceControl . Api . App . Features . References . Warehouses ;
5
+
6
+ [ ApiController ]
7
+ [ Route ( "api/warehouses/" ) ]
8
+ public class WarehouseController ( IWarehouseService 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 < WarehouseDto > > GetAllByProductionSite ( [ FromQuery ( Name = "productionSite" ) ] Guid productionSiteId ) =>
18
+ printerService . GetAllByProductionSiteAsync ( productionSiteId ) ;
19
+
20
+ [ HttpGet ( "{id:guid}" ) ]
21
+ public Task < WarehouseDto > GetById ( [ FromRoute ] Guid id ) => printerService . GetByIdAsync ( id ) ;
22
+
23
+ #endregion
24
+ }
Original file line number Diff line number Diff line change 1
- GET https://localhost:5138/api/printers /?productionSite=ffffffff-ffff-ffff-ffff-ffffffffffff
1
+ GET https://localhost:5138/api/warehouses/proxy /?productionSite=ffffffff-ffff-ffff-ffff-ffffffffffff
2
2
3
3
###
4
4
GET https://localhost:5138/api/production-sites
Original file line number Diff line number Diff line change
1
+ using System . Text . Json . Serialization ;
2
+
3
+ namespace Ws . DeviceControl . Models . Dto . References . Warehouses . Queries ;
4
+
5
+ public class WarehouseDto
6
+ {
7
+ [ JsonPropertyName ( "id" ) ]
8
+ public required Guid Id { get ; set ; }
9
+
10
+ [ JsonPropertyName ( "id1C" ) ]
11
+ public required Guid Id1C { get ; set ; }
12
+
13
+ [ JsonPropertyName ( "name" ) ]
14
+ public required string Name { get ; set ; }
15
+
16
+ [ JsonPropertyName ( "createDt" ) ]
17
+ public required DateTime CreateDt { get ; set ; }
18
+
19
+ [ JsonPropertyName ( "changeDt" ) ]
20
+ public required DateTime ChangeDt { get ; set ; }
21
+ }
You can’t perform that action at this time.
0 commit comments