Skip to content

Commit 3f1d19a

Browse files
committed
ADD: delete Pallets api method - Ws.Desktop.Api
1 parent 0c47ebf commit 3f1d19a

File tree

10 files changed

+117
-5
lines changed

10 files changed

+117
-5
lines changed

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

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using System.Globalization
2+
@using Ws.Desktop.Models
23
@using Ws.Desktop.Models.Features.Pallets.Output
34

45
<div class="size-full flex flex-col overflow-x-hidden overflow-y-auto pt-6 pb-8 px-6">
@@ -23,10 +24,18 @@
2324
</div>
2425
@if (Pallet.DeletedAt == null)
2526
{
26-
<Button Variant="ButtonVariant.Destructive">
27-
<TrashIcon class="size-4 mr-2" />
28-
@Localizer["BtnDelete"]
29-
</Button>
27+
<UseParameterlessEndpoint Endpoint="@ArmApi.ArmEndpoint" Context="armQuery">
28+
@if (armQuery.HasData)
29+
{
30+
<Button
31+
Variant="ButtonVariant.Destructive"
32+
OnClick="@(() => DeletePallet(armQuery.Data.Id, Pallet.Id))"
33+
>
34+
<TrashIcon class="size-4 mr-2" />
35+
@Localizer["BtnDelete"]
36+
</Button>
37+
}
38+
</UseParameterlessEndpoint>
3039
}
3140
else
3241
{
@@ -149,8 +158,23 @@
149158
[Inject] private IStringLocalizer<WsDataResources> WsDataLocalizer { get; set; } = default!;
150159
[Inject] private IStringLocalizer<ApplicationResources> Localizer { get; set; } = default!;
151160
[Inject] private IToastService ToastService { get; set; } = default!;
161+
[Inject] private IDesktopApi DesktopApi { get; set; } = default!;
162+
[Inject] private ArmApi ArmApi { get; set; } = default!;
152163

153164
# endregion
154165

155166
[Parameter, EditorRequired] public PalletInfo Pallet { get; set; } = default!;
167+
168+
private async void DeletePallet(Guid armUid, Guid palletUid)
169+
{
170+
try
171+
{
172+
await DesktopApi.DeletePallet(armUid, palletUid);
173+
ToastService.ShowSuccess("Good");
174+
}
175+
catch
176+
{
177+
ToastService.ShowError("Bad");
178+
}
179+
}
156180
}

Src/Apps/Desktop/Ws.Desktop.Api/App/Features/Pallets/Common/IPalletApiService.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IPalletApiService
1515

1616
#region Commands
1717

18+
public Task Delete(Guid id);
1819
public Task<PalletInfo> CreatePiecePallet(Guid armId, PalletPieceCreateDto dto);
1920

2021
#endregion

Src/Apps/Desktop/Ws.Desktop.Api/App/Features/Pallets/Impl/PalletApiService.cs

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.EntityFrameworkCore;
22
using Ws.Database.EntityFramework;
3+
using Ws.Database.EntityFramework.Entities.Print.Pallets;
34
using Ws.Desktop.Api.App.Features.Pallets.Common;
45
using Ws.Desktop.Api.App.Features.Pallets.Extensions;
56
using Ws.Desktop.Models.Features.Pallets.Input;
@@ -49,6 +50,18 @@ public List<PalletInfo> GetAllByDate(Guid armId, DateTime startTime, DateTime en
4950
.ToPalletInfo(dbContext.Labels).ToList();
5051
}
5152

53+
public async Task Delete(Guid id)
54+
{
55+
PalletEntity? pallet = await dbContext.Pallets.FindAsync(id);
56+
if (pallet != null)
57+
{
58+
bool isDelete = !(pallet.DeletedAt != null);
59+
await printLabelService.DeletePallet(pallet.Number, isDelete);
60+
pallet.DeletedAt = isDelete ? DateTime.Now : null;
61+
await dbContext.SaveChangesAsync();
62+
}
63+
}
64+
5265
public List<PalletInfo> GetByNumber(string number)
5366
{
5467
return dbContext.Pallets

Src/Apps/Desktop/Ws.Desktop.Api/App/Features/Pallets/PalletController.cs

+4
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,9 @@ public List<LabelInfo> GetLabelsByPallet(Guid palletId) =>
3535
public async Task<PalletInfo> Create([FromRoute] Guid armId, [FromBody] PalletPieceCreateDto dto) =>
3636
await palletApiService.CreatePiecePallet(armId, dto);
3737

38+
[HttpDelete("{palletId:guid}")]
39+
public async Task Delete(Guid palletId) =>
40+
await palletApiService.Delete(palletId);
41+
3842
#endregion
3943
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public interface IDesktopApi
5151
[Post("/arms/{armUid}/pallets")]
5252
Task<PalletInfo> CreatePiecePallet(Guid armUid, [Body] PalletPieceCreateDto createDto);
5353

54+
[Delete("/arms/{armUid}/pallets/{palletId}")]
55+
Task DeletePallet(Guid armUid, Guid palletId);
56+
5457
#endregion
5558

5659
#region Plus Weight
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Xml.Serialization;
2+
3+
namespace Ws.Labels.Service.Api.Pallet.Input;
4+
5+
[XmlRoot(ElementName = "PalletType")]
6+
public class PalletDeleteWrapper
7+
{
8+
[XmlElement(ElementName = "Record")]
9+
public PalletDeleteDto Pallet { get; set; }
10+
}
11+
12+
public class PalletDeleteDto
13+
{
14+
[XmlAttribute(AttributeName = "Number")]
15+
public string Number { get; set; } = string.Empty;
16+
17+
[XmlAttribute(AttributeName = "IsDelete")]
18+
public bool IsDelete { get; set; }
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Xml.Serialization;
2+
3+
namespace Ws.Labels.Service.Api.Pallet.Output;
4+
5+
[XmlRoot(ElementName = "ResponseType", Namespace = "http://www.kolbasa-vs.ru/scales/ResponseVesovaya2_0_Status")]
6+
public class PalletDeleteWrapperMsg
7+
{
8+
[XmlElement(ElementName = "Status")]
9+
public PalletDeleteMsg Status { get; set; } = new();
10+
}
11+
12+
13+
public class PalletDeleteMsg
14+
{
15+
[XmlAttribute(AttributeName = "IsSuccess")]
16+
public bool IsSuccess { get; set; }
17+
18+
[XmlAttribute(AttributeName = "Message")]
19+
public string Message { get; set; } = string.Empty;
20+
}

Src/Services/Ws.Labels.Service/Api/PalychApi.cs

+3
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ internal interface IPalychApi
88
{
99
[Post("/ExchangeVesovayaPalletCard")]
1010
Task<PalletResponseDto> CreatePallet([Body] PalletCreateApiDto dto);
11+
12+
[Post("/ExchangeVesovayaPalletCardStatus/")]
13+
Task<PalletDeleteWrapperMsg> Delete([Body] PalletDeleteWrapper dto);
1114
}

Src/Services/Ws.Labels.Service/Generate/IPrintLabelService.cs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public interface IPrintLabelService
1212
/// <exception cref="LabelGenerateException">Ошибка формирования.</exception>
1313
(Label, LabelZpl) GenerateWeightLabel(GenerateWeightLabelDto weightLabelDto);
1414

15+
Task<bool> DeletePallet(string palletNumber, bool isDelete);
16+
1517

1618
/// <summary>
1719
/// Создает паллету
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
using Ws.Domain.Models.Entities.Print;
2+
using Ws.Labels.Service.Api;
3+
using Ws.Labels.Service.Api.Pallet.Output;
4+
using Ws.Labels.Service.Generate.Exceptions;
25
using Ws.Labels.Service.Generate.Features.Piece;
36
using Ws.Labels.Service.Generate.Features.Piece.Dto;
47
using Ws.Labels.Service.Generate.Features.Weight;
58
using Ws.Labels.Service.Generate.Features.Weight.Dto;
9+
using Ws.Shared.Api.ApiException;
610

711
namespace Ws.Labels.Service.Generate;
812

9-
internal class PrintLabelService(LabelPieceGenerator labelPieceGenerator, LabelWeightGenerator labelWeightGenerator)
13+
internal class PrintLabelService(
14+
LabelPieceGenerator labelPieceGenerator,
15+
LabelWeightGenerator labelWeightGenerator,
16+
IPalychApi palychApi
17+
)
1018
: IPrintLabelService
1119
{
1220
public (Label, LabelZpl) GenerateWeightLabel(GenerateWeightLabelDto weightLabelDto) =>
1321
labelWeightGenerator.GenerateLabel(weightLabelDto);
1422

23+
public async Task<bool> DeletePallet(string palletNumber, bool isDelete)
24+
{
25+
PalletDeleteWrapperMsg ans =
26+
await palychApi.Delete(new() { Pallet = new() { IsDelete = isDelete, Number = palletNumber }});
27+
28+
if (ans.Status.IsSuccess)
29+
return true;
30+
31+
throw new ApiExceptionServer
32+
{
33+
ExceptionType = LabelGenExceptions.ExchangeFailed,
34+
ErrorInternalMessage = ans.Status.Message
35+
};
36+
}
37+
1538
public Task<Guid> GeneratePiecePallet(GeneratePiecePalletDto piecePalletDto, int labelCount, uint counter) =>
1639
labelPieceGenerator.GeneratePiecePallet(piecePalletDto, labelCount, counter);
1740
}

0 commit comments

Comments
 (0)