Skip to content

Commit 4393f5b

Browse files
committed
UPDATE: refactor Ws.Shared
1 parent 1c1872a commit 4393f5b

File tree

45 files changed

+130
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+130
-120
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
135135
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
136136

137137
# Roslynator
138+
dotnet_diagnostic.rcs1194.severity = none
138139
dotnet_diagnostic.rcs1123.severity = none
139140
dotnet_diagnostic.rcs1001.severity = none
140141
dotnet_diagnostic.rcs1003.severity = none

Src/Apps/Desktop/ScalesDesktop/GlobalUsings.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222
// 5. Modules
2323
global using Ws.Desktop.Models;
2424
global using Ws.Shared.Resources;
25-
global using Ws.Shared.Utils;
26-
global using Ws.Shared.Api.ApiException;
25+
global using Ws.Shared.Utils;

Src/Apps/Desktop/ScalesDesktop/Source/Features/LabelPrint.razor.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Ws.Desktop.Models.Features.Arms.Output;
77
using Ws.Desktop.Models.Features.Labels.Input;
88
using Ws.Desktop.Models.Features.Labels.Output;
9+
using Ws.Shared.Extensions;
910

1011
namespace ScalesDesktop.Source.Features;
1112

@@ -89,7 +90,7 @@ private async Task PrintLabelAsync()
8990
}
9091
catch (ApiException ex)
9192
{
92-
ToastService.ShowError(ApiExceptionSerialization.GetMessage(ex, Localizer["UnknownError"]));
93+
ToastService.ShowError(ex.GetMessage(Localizer["UnknownError"]));
9394
}
9495
catch
9596
{

Src/Apps/Desktop/ScalesDesktop/Source/Features/PalletCreate/PalletResultStageForm.razor.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Ws.Desktop.Models.Features.Pallets.Input;
22
using Ws.Desktop.Models.Features.Pallets.Output;
3+
using Ws.Shared.Extensions;
34

45
namespace ScalesDesktop.Source.Features.PalletCreate;
56

@@ -57,7 +58,7 @@ private async Task CreatePallet()
5758
}
5859
catch (ApiException ex)
5960
{
60-
ToastService.ShowError(ApiExceptionSerialization.GetMessage(ex, Localizer["ToastPalletCreateError"]));
61+
ToastService.ShowError(ex.GetMessage(Localizer["ToastPalletCreateError"]));
6162
}
6263
catch (Exception)
6364
{

Src/Apps/Desktop/ScalesDesktop/Source/Features/PalletOverview/DeletePalletButton.razor

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@using ScalesDesktop.Source.Shared.Services.Stores
44
@using Ws.Desktop.Models
55
@using Ws.Desktop.Models.Features.Pallets.Output
6+
@using Ws.Shared.Extensions
67
@inherits Fluxor.Blazor.Web.Components.FluxorComponent
78

89
@if (PalletState.Value.Pallet != null)
@@ -60,7 +61,7 @@ else
6061
}
6162
catch (ApiException ex)
6263
{
63-
ToastService.ShowError(ApiExceptionSerialization.GetMessage(ex, Localizer["UnknownError"]));
64+
ToastService.ShowError(ex.GetMessage(Localizer["UnknownError"]));
6465
}
6566
catch
6667
{

Src/Apps/Desktop/ScalesDesktop/Source/Shared/Services/Devices/PrinterService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ScalesDesktop.Source.Shared.Services.Devices;
1111
public class PrinterService(IDispatcher dispatcher) : IPrinterService, IDisposable
1212
{
1313
public bool IsMock() => false;
14-
private IZplPrinter Printer { get; set; } = PrinterFactory.Create(DefaultConsts.IpLocal, 9100, PrinterTypes.Tsc);
14+
private IZplPrinter Printer { get; set; } = PrinterFactory.Create(DefaultTypes.IpLocal, 9100, PrinterTypes.Tsc);
1515

1616
public void Setup(IPAddress ip, int port, PrinterTypes types)
1717
{

Src/Apps/Desktop/Ws.Desktop.Api/App/Features/PalletMen/Expressions/PalletManExpressions.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@
33

44
namespace Ws.Desktop.Api.App.Features.PalletMen.Expressions;
55

6-
76
internal static class PalletManExpressions
87
{
98
public static Expression<Func<PalletManEntity, PalletMan>> ToDto => palletMan =>
109
new()
1110
{
1211
Id = palletMan.Id,
13-
Fio = new()
14-
{
15-
Name = palletMan.Name,
16-
Surname = palletMan.Surname,
17-
Patronymic = palletMan.Patronymic
18-
},
12+
Fio = new(palletMan.Name, palletMan.Surname, palletMan.Patronymic),
1913
Password = palletMan.Password
2014
};
2115
}

Src/Apps/Desktop/Ws.Desktop.Api/App/Features/Pallets/Expressions/PalletExpressions.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ public static IQueryable<PalletInfo> ToPalletInfo(this IQueryable<PalletEntity>
3333
WeightNet = group.Sum(label => label.WeightNet),
3434
})
3535
.ToHashSet(),
36-
PalletMan = new()
37-
{
38-
Name = result.Pallet.PalletMan.Name,
39-
Surname = result.Pallet.PalletMan.Surname,
40-
Patronymic = result.Pallet.PalletMan.Patronymic
41-
},
36+
PalletMan = new(
37+
result.Pallet.PalletMan.Name,
38+
result.Pallet.PalletMan.Surname,
39+
result.Pallet.PalletMan.Patronymic
40+
),
4241
WeightTray = result.Pallet.TrayWeight,
4342
Barcode = result.Pallet.Barcode,
4443
ProdDt = result.Pallet.ProductDt,

Src/Apps/Desktop/Ws.Desktop.Api/App/Shared/Middlewares/GenerateLabelExceptionHandlingMiddleware.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text.Json;
2-
using Ws.Shared.Api.ApiException;
2+
using Ws.Shared.Exceptions;
3+
using Ws.Shared.ValueTypes;
34

45
namespace Ws.Desktop.Api.App.Shared.Middlewares;
56

@@ -11,13 +12,13 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
1112
{
1213
await next(context);
1314
}
14-
catch (ApiExceptionServer e)
15+
catch (ApiInternalException e)
1516
{
1617
logger.LogWarning(e, "{EMessage}\n{EInternal}", e.ErrorDisplayMessage, e.ErrorInternalMessage);
1718

1819
context.Response.StatusCode = (int)e.StatusCode;
1920

20-
ApiExceptionClient problem = new()
21+
ApiFailedResponse problem = new()
2122
{
2223
LocalizeMessage = e.ErrorDisplayMessage,
2324
};

Src/Apps/Desktop/Ws.Desktop.Models/Features/PalletMen/PalletMan.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Ws.Shared.ValueTypes;
2+
13
namespace Ws.Desktop.Models.Features.PalletMen;
24

35
public sealed record PalletMan
@@ -6,6 +8,7 @@ public sealed record PalletMan
68
public required Guid Id { get; init; }
79

810
[JsonPropertyName("fio")]
11+
[JsonConverter(typeof(FioJsonConverter))]
912
public required Fio Fio { get; init; }
1013

1114
[JsonPropertyName("password")]

Src/Apps/Desktop/Ws.Desktop.Models/Features/Pallets/Output/PalletInfo.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Ws.Shared.ValueTypes;
2+
13
namespace Ws.Desktop.Models.Features.Pallets.Output;
24

35
public sealed record PalletInfo

Src/Apps/Desktop/Ws.Desktop.Models/GlobalUsings.cs

-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
// pass
1212

1313
// 5. Modules
14-
global using Ws.Shared.Api.ValueTypes;
1514
global using Ws.Shared.Converters.Json;

Src/Apps/Exchange/Ws.PalychExchange.Api/App/Features/Plus/Impl/PluApiService.private.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ private static void SetDefaultFk(HashSet<PluDto> validDtos)
3737
{
3838
foreach (PluDto i in validDtos)
3939
{
40-
i.ClipUid = i.ClipUid == Guid.Empty ? DefaultConsts.GuidMax : i.ClipUid;
41-
i.BundleUid = i.BundleUid == Guid.Empty ? DefaultConsts.GuidMax : i.BundleUid;
40+
i.ClipUid = i.ClipUid == Guid.Empty ? DefaultTypes.GuidMax : i.ClipUid;
41+
i.BundleUid = i.BundleUid == Guid.Empty ? DefaultTypes.GuidMax : i.BundleUid;
4242
}
4343
}
4444

Src/Apps/Web/DeviceControl/Source/Pages/Devices/Arms/ArmPluDataGrid.razor

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
}
184184
catch (ApiException ex)
185185
{
186-
ToastService.ShowError(ApiExceptionSerialization.GetMessage(ex, string.Format(Localizer["ArmPluRemovedUnsuccessfully"], item.Number)));
186+
ToastService.ShowError(ex.GetMessage(string.Format(Localizer["ArmPluRemovedUnsuccessfully"], item.Number)));
187187
}
188188
}
189189

@@ -197,7 +197,7 @@
197197
}
198198
catch (ApiException ex)
199199
{
200-
ToastService.ShowError(ApiExceptionSerialization.GetMessage(ex, string.Format(Localizer["ArmPluAddedUnsuccessfully"], item.Number)));
200+
ToastService.ShowError(ex.GetMessage(string.Format(Localizer["ArmPluAddedUnsuccessfully"], item.Number)));
201201
}
202202
catch
203203
{

Src/Apps/Web/DeviceControl/Source/Shared/UI/DataGrid/SectionDataGridBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private async Task DeleteItemCallback(TItem item)
6464
}
6565
catch (ApiException ex)
6666
{
67-
ToastService.ShowError(ApiExceptionSerialization.GetMessage(ex, Localizer["ToastDeleteItemError"]));
67+
ToastService.ShowError(ex.GetMessage(Localizer["ToastDeleteItemError"]));
6868
}
6969
catch
7070
{

Src/Apps/Web/DeviceControl/Source/Shared/UI/Form/SectionFormBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private async Task ExecuteAction(Func<Task> action, string successMessage)
5353
}
5454
catch (ApiException ex)
5555
{
56-
ToastService.ShowError(ApiExceptionSerialization.GetMessage(ex, Localizer["UnknownError"]));
56+
ToastService.ShowError(ex.GetMessage(Localizer["UnknownError"]));
5757
}
5858
catch
5959
{

Src/Apps/Web/Ws.DeviceControl.Api/App/Common/ApiService.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Net;
22
using FluentValidation;
3+
using Ws.Shared.Exceptions;
34

45
namespace Ws.DeviceControl.Api.App.Common;
56

@@ -9,7 +10,7 @@ protected static async Task ValidateAsync<T>(T dto, AbstractValidator<T> validat
910
{
1011
ValidationResult result = await validator.ValidateAsync(dto);
1112
if (!result.IsValid)
12-
throw new ApiExceptionServer
13+
throw new ApiInternalException
1314
{
1415
ErrorDisplayMessage = result.Errors.FirstOrDefault()?.ToString() ?? string.Empty,
1516
StatusCode = HttpStatusCode.UnprocessableEntity

Src/Apps/Web/Ws.DeviceControl.Api/App/Features/Admins/PalletMen/Impl/Expressions/PalletManExpressions.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ public static class PalletManExpressions
1010
{
1111
Id = palletMan.Id,
1212
Id1C = palletMan.Uid1C,
13-
Fio = new()
14-
{
15-
Name = palletMan.Name,
16-
Surname = palletMan.Surname,
17-
Patronymic = palletMan.Patronymic
18-
},
13+
Fio = new(palletMan.Name, palletMan.Surname, palletMan.Patronymic),
1914
Password = palletMan.Password,
2015
Warehouse = new()
2116
{

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Ws.DeviceControl.Models.Features.References.ProductionSites.Commands.Create;
77
using Ws.DeviceControl.Models.Features.References.ProductionSites.Commands.Update;
88
using Ws.DeviceControl.Models.Features.References.ProductionSites.Queries;
9+
using Ws.Shared.Exceptions;
910

1011
namespace Ws.DeviceControl.Api.App.Features.References.ProductionSites.Impl;
1112

@@ -21,7 +22,7 @@ ProductionSiteUpdateValidator updateValidator
2122
public async Task<ProxyDto> GetProxyByUser()
2223
{
2324
ProxyDto? data = await userHelper.GetUserProductionSiteAsync();
24-
if (data == null) throw new ApiExceptionServer
25+
if (data == null) throw new ApiInternalException
2526
{
2627
ErrorDisplayMessage = "Площадка не установлена",
2728
StatusCode = HttpStatusCode.NotFound
@@ -37,7 +38,7 @@ public async Task<List<ProxyDto>> GetProxiesAsync()
3738
bool developer = await userHelper.ValidatePolicyAsync(PolicyEnum.Developer);
3839
return await dbContext.ProductionSites
3940
.AsNoTracking()
40-
.IfWhere(!developer, entity => entity.Id != DefaultConsts.GuidMax)
41+
.IfWhere(!developer, entity => entity.Id != DefaultTypes.GuidMax)
4142
.Select(ProductionSiteCommonExpressions.ToProxy)
4243
.OrderBy(i => i.Name)
4344
.ToListAsync();

Src/Apps/Web/Ws.DeviceControl.Api/App/Features/References/TemplateResources/Impl/TemplateResourceApiService.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Ws.DeviceControl.Models.Features.References.TemplateResources.Commands.Create;
88
using Ws.DeviceControl.Models.Features.References.TemplateResources.Commands.Update;
99
using Ws.DeviceControl.Models.Features.References.TemplateResources.Queries;
10+
using Ws.Shared.Exceptions;
1011

1112
namespace Ws.DeviceControl.Api.App.Features.References.TemplateResources.Impl;
1213

@@ -80,7 +81,7 @@ private static void ValidateSvg(string svg, ZplResourceType type)
8081
}
8182
catch
8283
{
83-
throw new ApiExceptionServer
84+
throw new ApiInternalException
8485
{
8586
ErrorDisplayMessage = "zpl error",
8687
StatusCode = HttpStatusCode.UnprocessableEntity

Src/Apps/Web/Ws.DeviceControl.Api/App/Shared/Extensions/DbContextExtensions.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Net;
22
using Microsoft.Data.SqlClient;
3+
using Ws.Shared.Exceptions;
34

45
namespace Ws.DeviceControl.Api.App.Shared.Extensions;
56

@@ -9,7 +10,7 @@ public static async Task ThrowIfExistAsync<T>(this DbSet<T> dbSet, Expression<Fu
910
{
1011
bool isExist = await dbSet.AnyAsync(predicate);
1112
if (isExist)
12-
throw new ApiExceptionServer
13+
throw new ApiInternalException
1314
{
1415
ErrorDisplayMessage = message,
1516
StatusCode = HttpStatusCode.Conflict
@@ -20,7 +21,7 @@ public static async Task SafeExistAsync<T>(this DbSet<T> dbSet, Expression<Func<
2021
{
2122
bool isExist = await dbSet.AnyAsync(predicate);
2223
if (!isExist)
23-
throw new ApiExceptionServer
24+
throw new ApiInternalException
2425
{
2526
ErrorDisplayMessage = message,
2627
StatusCode = HttpStatusCode.Conflict
@@ -35,7 +36,7 @@ public static async Task SafeDeleteAsync<T>(this DbSet<T> dbSet, Expression<Func
3536
}
3637
catch (SqlException)
3738
{
38-
throw new ApiExceptionServer
39+
throw new ApiInternalException
3940
{
4041
ErrorDisplayMessage = "Запись используются",
4142
StatusCode = HttpStatusCode.Conflict
@@ -47,7 +48,7 @@ public static async Task<T> SafeGetById<T>(this DbSet<T> dbSet, Guid id, string
4748
{
4849
T? entity = await dbSet.FindAsync(id);
4950
if (entity == null)
50-
throw new ApiExceptionServer
51+
throw new ApiInternalException
5152
{
5253
ErrorDisplayMessage = message,
5354
StatusCode = HttpStatusCode.NotFound

Src/Apps/Web/Ws.DeviceControl.Api/App/Shared/Helpers/UserHelper.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net;
2+
using Ws.Shared.Exceptions;
23

34
namespace Ws.DeviceControl.Api.App.Shared.Helpers;
45

@@ -29,21 +30,21 @@ public async Task<bool> ValidatePolicyAsync(string policy) =>
2930

3031
public async Task CanUserWorkWithProductionSiteAsync(Guid productionSiteId)
3132
{
32-
if (productionSiteId == DefaultConsts.GuidMax)
33+
if (productionSiteId == DefaultTypes.GuidMax)
3334
{
3435
bool isDeveloper = await ValidatePolicyAsync(PolicyEnum.Developer);
3536
if (isDeveloper) return;
3637
}
3738

3839
bool isSenior = await ValidatePolicyAsync(PolicyEnum.SeniorSupport);
3940

40-
if (isSenior && productionSiteId != DefaultConsts.GuidMax) return;
41+
if (isSenior && productionSiteId != DefaultTypes.GuidMax) return;
4142

4243
bool canWork =
4344
await dbContext.Users.AnyAsync(i => i.Id == UserId && i.ProductionSite.Id == productionSiteId);
4445

4546
if (!canWork)
46-
throw new ApiExceptionServer
47+
throw new ApiInternalException
4748
{
4849
ErrorDisplayMessage = "Пользователь не может работать с выбранной площадкой",
4950
StatusCode = HttpStatusCode.Conflict

Src/Apps/Web/Ws.DeviceControl.Api/App/Shared/Middlewares/ExceptionHandlingMiddleware.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System.Text.Json;
2+
using Ws.Shared.Exceptions;
3+
using Ws.Shared.ValueTypes;
24

35
namespace Ws.DeviceControl.Api.App.Shared.Middlewares;
46

@@ -10,14 +12,14 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
1012
{
1113
await next(context);
1214
}
13-
catch (ApiExceptionServer e)
15+
catch (ApiInternalException e)
1416
{
1517
logger.LogWarning(e, "{EMessage}\n{EInternal}",
1618
e.ErrorDisplayMessage, e.ErrorInternalMessage);
1719

1820
context.Response.StatusCode = (int)e.StatusCode;
1921

20-
ApiExceptionClient problem = new()
22+
ApiFailedResponse problem = new()
2123
{
2224
LocalizeMessage = e.ErrorDisplayMessage,
2325
};

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

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
global using Ws.DeviceControl.Models.Auth;
2222
global using Ws.DeviceControl.Models.Shared;
2323
global using Ws.Database.EntityFramework;
24-
global using Ws.Shared.Api.ApiException;
2524
global using Ws.Shared.Constants;
2625
global using Ws.Shared.Enums;
2726
global using Ws.Shared.Extensions;

0 commit comments

Comments
 (0)