Skip to content

Commit 99794fa

Browse files
committed
UPDATE: add prototype of productionSites api - Ws.DeviceControl.Api
1 parent 3a700db commit 99794fa

29 files changed

+301
-60
lines changed

Src/Apps/Web/DeviceControl/Source/Pages/Diagnostics/Migrations/MigrationsPage.razor

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@using DeviceControl.Source.Shared.Services
2-
@using Ws.DeviceControl.Models.Models.Database
2+
@using Ws.DeviceControl.Models.Dto.Database
33
@attribute [Route($"{RouteUtils.SectionMigrations}")]
44
@attribute [Authorize(Policy = PolicyEnum.Admin)]
55
@rendermode InteractiveServer
@@ -13,18 +13,18 @@
1313

1414
<DataGridWrapper>
1515
<DataGridContainer
16-
TItem="MigrationHistoryEntry"
16+
TItem="MigrationHistoryDto"
1717
Items="@(migrationsQuery.HasData ? migrationsQuery.Data : [])"
1818
>
1919
<ColumnsContent>
2020
<DataGridColumn
2121
Caption="@WsDataLocalizer["ColVersion"]"
22-
Field="@nameof(MigrationHistoryEntry.ProductVersion)"
22+
Field="@nameof(MigrationHistoryDto.ProductVersion)"
2323
Width="10%"
2424
/>
2525
<DataGridColumn
2626
Caption="@WsDataLocalizer["ColName"]"
27-
Field="@nameof(MigrationHistoryEntry.MigrationId)"
27+
Field="@nameof(MigrationHistoryDto.MigrationId)"
2828
Width="90%"
2929
/>
3030
</ColumnsContent>

Src/Apps/Web/DeviceControl/Source/Pages/Diagnostics/Tables/TablesPage.razor

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@using DeviceControl.Source.Shared.Services
2-
@using Ws.DeviceControl.Models.Models.Database
2+
@using Ws.DeviceControl.Models.Dto.Database
33
@attribute [Route($"{RouteUtils.SectionTables}")]
44
@attribute [Authorize(Policy = PolicyEnum.Admin)]
55
@rendermode InteractiveServer
@@ -13,14 +13,14 @@
1313

1414
<DataGridWrapper>
1515
<DataGridContainer
16-
TItem="DataBaseTableEntry"
16+
TItem="DataBaseTableDto"
1717
Items="@(tablesQuery.HasData ? tablesQuery.Data : [])"
1818
IsFilterable
1919
>
2020
<ColumnsContent>
2121
<DataGridColumn
2222
Caption="@WsDataLocalizer["ColScheme"]"
23-
Field="@nameof(DataBaseTableEntry.Schema)"
23+
Field="@nameof(DataBaseTableDto.Schema)"
2424
Width="20%"
2525
Sortable="false"
2626
FilterMethod="DataGridColumnFilterMethod.Equals"
@@ -48,19 +48,19 @@
4848

4949
<DataGridColumn
5050
Caption="@WsDataLocalizer["ColName"]"
51-
Field="@nameof(DataBaseTableEntry.Table)"
51+
Field="@nameof(DataBaseTableDto.Table)"
5252
Width="30%"
5353
/>
5454

5555
<DataGridColumn
5656
Caption="Количество записей"
57-
Field="@nameof(DataBaseTableEntry.Rows)"
57+
Field="@nameof(DataBaseTableDto.Rows)"
5858
Width="25%"
5959
Filterable="false"
6060
/>
6161
<DataGridColumn
6262
Caption="@($"{WsDataLocalizer["ColSize"]} ({WsDataLocalizer["MeasureMb"]})")"
63-
Field="@nameof(DataBaseTableEntry.UsedMb)"
63+
Field="@nameof(DataBaseTableDto.UsedMb)"
6464
Width="25%"
6565
Filterable="false"
6666
/>

Src/Apps/Web/DeviceControl/Source/Pages/Operations/Labels/LabelsPage.razor

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<DataGridColumn
3232
Caption="@WsDataLocalizer["ColProductDt"]"
3333
Field="@nameof(Label.ProductDt)"
34+
DisplayFormat="{0:dd.MM.yyyy}"
3435
Filterable="false"
3536
Width="10%"
3637
/>

Src/Apps/Web/DeviceControl/Source/Pages/Operations/Labels/LabelsUpdateForm.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@
6868

6969
<SectionReadOnlyField
7070
Label="@WsDataLocalizer["ColProductDt"]"
71-
Value="@DialogItem.ProductDt"
71+
Value="@DialogItem.ProductDt.ToString("dd.MM.yyyy")"
7272
/>
7373

7474
<SectionReadOnlyField
7575
Label="@WsDataLocalizer["ColExpirationDt"]"
76-
Value="@DialogItem.ExpirationDt"
76+
Value="@DialogItem.ExpirationDt.ToString("dd.MM.yyyy")"
7777
/>
7878

7979
</FieldsContent>

Src/Apps/Web/DeviceControl/Source/Shared/Services/DatabaseApi.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
using Phetch.Core;
22
using Ws.DeviceControl.Models;
3-
using Ws.DeviceControl.Models.Models.Database;
3+
using Ws.DeviceControl.Models.Dto.Database;
44

55
namespace DeviceControl.Source.Shared.Services;
66

77
public class DatabaseApi(IWebApi webApi)
88
{
9-
public ParameterlessEndpoint<MigrationHistoryEntry[]> MigrationsEndpoint { get; } = new(
9+
public ParameterlessEndpoint<MigrationHistoryDto[]> MigrationsEndpoint { get; } = new(
1010
webApi.GetMigrations,
1111
options: new()
1212
{
1313
DefaultStaleTime = TimeSpan.FromMinutes(5),
1414
});
1515

16-
public ParameterlessEndpoint<DataBaseTableEntry[]> TablesEndpoint { get; } = new(
16+
public ParameterlessEndpoint<DataBaseTableDto[]> TablesEndpoint { get; } = new(
1717
webApi.GetTables,
1818
options: new()
1919
{

Src/Apps/Web/Ws.DeviceControl.Api/App/Features/Database/Common/IDatabaseService.cs

-9
This file was deleted.

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

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Ws.DeviceControl.Models.Dto.Database;
2+
3+
namespace Ws.DeviceControl.Api.App.Features.Diag.Database.Common;
4+
5+
public interface IDatabaseService
6+
{
7+
List<MigrationHistoryDto> GetAllMigrations();
8+
List<DataBaseTableDto> GetAllTables();
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Ws.DeviceControl.Api.App.Features.Diag.Database.Common;
3+
using Ws.DeviceControl.Models.Dto.Database;
4+
5+
namespace Ws.DeviceControl.Api.App.Features.Diag.Database;
6+
7+
[ApiController]
8+
[Route("api/database/")]
9+
public class DatabaseController(IDatabaseService databaseService)
10+
{
11+
#region Queries
12+
13+
[HttpGet("migrations")]
14+
public List<MigrationHistoryDto> GetAllMigrations() => databaseService.GetAllMigrations();
15+
16+
[HttpGet("tables")]
17+
public List<DataBaseTableDto> GetAllTables() => databaseService.GetAllTables();
18+
19+
#endregion
20+
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
using System.Runtime.CompilerServices;
22
using Microsoft.EntityFrameworkCore;
33
using Ws.Database.EntityFramework;
4-
using Ws.DeviceControl.Api.App.Features.Database.Common;
5-
using Ws.DeviceControl.Models.Models.Database;
4+
using Ws.DeviceControl.Api.App.Features.Diag.Database.Common;
5+
using Ws.DeviceControl.Models.Dto.Database;
66

7-
namespace Ws.DeviceControl.Api.App.Features.Database.Impl;
7+
namespace Ws.DeviceControl.Api.App.Features.Diag.Database.Impl;
88

99
public class DatabaseService(WsDbContext dbContext) : IDatabaseService
1010
{
11-
public List<MigrationHistoryEntry> GetAllMigrations()
11+
public List<MigrationHistoryDto> GetAllMigrations()
1212
{
1313
FormattableString getMigrationSql = FormattableStringFactory.Create("SELECT * FROM dbo.__EFMigrationsHistory");
14-
List<MigrationHistoryEntry> data = dbContext.Database.SqlQuery<MigrationHistoryEntry>(getMigrationSql).ToList();
14+
List<MigrationHistoryDto> data = dbContext.Database.SqlQuery<MigrationHistoryDto>(getMigrationSql).ToList();
1515
data.Reverse();
1616
return data;
1717
}
1818

19-
public List<DataBaseTableEntry> GetAllTables()
19+
public List<DataBaseTableDto> GetAllTables()
2020
{
21-
return dbContext.DatabaseTables.Select(i => new DataBaseTableEntry
21+
return dbContext.DatabaseTables.Select(i => new DataBaseTableDto
2222
{
2323
Schema = i.Schema,
2424
Table = i.Table,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Commands.Create;
2+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Commands.Update;
3+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Queries;
4+
5+
namespace Ws.DeviceControl.Api.App.Features.References.ProductionSites.Common;
6+
7+
public interface IProductionSiteService
8+
{
9+
#region Queries
10+
11+
Task<List<ProductionSiteDto>> GetAllAsync();
12+
13+
#endregion
14+
15+
#region Commands
16+
17+
Task<ProductionSiteDto> CreateAsync(ProductionSiteCreateDto dto);
18+
Task<ProductionSiteDto> UpdateAsync(Guid id, ProductionSiteUpdateDto dto);
19+
20+
#endregion
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Linq.Expressions;
2+
using Ws.Database.EntityFramework.Entities.Ref.ProductionSites;
3+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Queries;
4+
5+
namespace Ws.DeviceControl.Api.App.Features.References.ProductionSites.Impl.Expressions;
6+
7+
public static class ProductionSiteExpressions
8+
{
9+
public static Expression<Func<ProductionSiteEntity, ProductionSiteDto>> ToDto =>
10+
productionSite => new()
11+
{
12+
Id = productionSite.Id,
13+
Name = productionSite.Name,
14+
Address = productionSite.Address,
15+
CreateDt = productionSite.CreateDt,
16+
ChangeDt = productionSite.ChangeDt
17+
};
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.ChangeTracking;
3+
using Ws.Database.EntityFramework;
4+
using Ws.Database.EntityFramework.Entities.Ref.ProductionSites;
5+
using Ws.DeviceControl.Api.App.Features.References.ProductionSites.Common;
6+
using Ws.DeviceControl.Api.App.Features.References.ProductionSites.Impl.Expressions;
7+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Queries;
8+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Commands.Create;
9+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Commands.Update;
10+
11+
namespace Ws.DeviceControl.Api.App.Features.References.ProductionSites.Impl;
12+
13+
public class ProductionSiteService(WsDbContext dbContext): IProductionSiteService
14+
{
15+
#region Queries
16+
17+
public Task<List<ProductionSiteDto>> GetAllAsync() => dbContext.ProductionSites
18+
.AsNoTracking().Select(ProductionSiteExpressions.ToDto)
19+
.OrderBy(i => i.Name)
20+
.ToListAsync();
21+
22+
#endregion
23+
24+
#region Commands
25+
26+
public async Task<ProductionSiteDto> CreateAsync(ProductionSiteCreateDto dto)
27+
{
28+
ProductionSiteEntity item = new()
29+
{
30+
Name = dto.Name,
31+
Address = dto.Address,
32+
};
33+
await dbContext.ProductionSites.AddAsync(item);
34+
35+
await dbContext.SaveChangesAsync();
36+
37+
return ProductionSiteExpressions.ToDto.Compile().Invoke(item);
38+
}
39+
40+
public Task<ProductionSiteDto> UpdateAsync(Guid id, ProductionSiteUpdateDto dto)
41+
{
42+
return Task.FromResult<ProductionSiteDto>(new()
43+
{
44+
Id = default,
45+
Name = string.Empty,
46+
Address = string.Empty,
47+
CreateDt = default,
48+
ChangeDt = default
49+
});
50+
}
51+
52+
#endregion
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Ws.DeviceControl.Api.App.Features.References.ProductionSites.Common;
3+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Commands.Create;
4+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Commands.Update;
5+
using Ws.DeviceControl.Models.Dto.References.ProductionSites.Queries;
6+
7+
namespace Ws.DeviceControl.Api.App.Features.References.ProductionSites;
8+
9+
[ApiController]
10+
[Route("api/production-sites/")]
11+
public class ProductionSiteController(IProductionSiteService productionSiteService)
12+
{
13+
#region Queries
14+
15+
[HttpGet]
16+
public Task<List<ProductionSiteDto>> GetAllMigrations() => productionSiteService.GetAllAsync();
17+
18+
#endregion
19+
20+
#region Commamnds
21+
22+
[HttpPost]
23+
public Task<ProductionSiteDto> Create([FromBody] ProductionSiteCreateDto dto) =>
24+
productionSiteService.CreateAsync(dto);
25+
26+
[HttpPut("{id:guid}")]
27+
public Task<ProductionSiteDto> Update([FromRoute] Guid id, [FromBody] ProductionSiteUpdateDto dto) =>
28+
productionSiteService.UpdateAsync(id, dto);
29+
30+
#endregion
31+
}

Src/Apps/Web/Ws.DeviceControl.Api/Program.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
using Microsoft.AspNetCore.Mvc;
44
using Microsoft.AspNetCore.Mvc.Authorization;
55
using Ws.Database.EntityFramework;
6-
using Ws.DeviceControl.Api.App.Features.Database.Common;
7-
using Ws.DeviceControl.Api.App.Features.Database.Impl;
6+
using Ws.DeviceControl.Api.App.Features.Diag.Database.Common;
7+
using Ws.DeviceControl.Api.App.Features.Diag.Database.Impl;
8+
using Ws.DeviceControl.Api.App.Features.References.ProductionSites.Common;
9+
using Ws.DeviceControl.Api.App.Features.References.ProductionSites.Impl;
810

911
var builder = WebApplication.CreateBuilder(args);
1012

@@ -13,6 +15,7 @@
1315
#region Internal services
1416

1517
builder.Services.AddScoped<IDatabaseService, DatabaseService>();
18+
builder.Services.AddScoped<IProductionSiteService, ProductionSiteService>();
1619

1720
#endregion
1821

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
GET https://localhost:5138/api/production-sites
2+
3+
###
4+
5+
6+
POST https://localhost:5138/api/production-sites
7+
Content-Type: application/json
8+
9+
{
10+
"name": "Tets",
11+
"address": "dawdadwdaw"
12+
}

Src/Apps/Web/Ws.DeviceControl.Models/Models/Database/DataBaseTableEntry.cs Src/Apps/Web/Ws.DeviceControl.Models/Dto/Database/DataBaseTableDto.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.Text.Json.Serialization;
22

3-
namespace Ws.DeviceControl.Models.Models.Database;
3+
namespace Ws.DeviceControl.Models.Dto.Database;
44

5-
public sealed record DataBaseTableEntry
5+
public sealed record DataBaseTableDto
66
{
77
[JsonPropertyName("rows")]
88
public required int Rows { get; init; }

0 commit comments

Comments
 (0)