Finalized delete voice work logic.
All checks were successful
ci / build-test (push) Successful in 2m45s
ci / publish-image (push) Successful in 1m54s

This commit is contained in:
2026-05-09 22:19:44 -04:00
parent 5eecba7eec
commit 06d5aa345d
7 changed files with 72 additions and 9 deletions

View File

@@ -26,6 +26,8 @@ public class VoiceWorkWriter(AppDbContext dbContext) : IVoiceWorkWriter
VoiceWork[] voiceWorks = [.. dbContext.VoiceWorks.Where(voiceWork => request.VoiceWorkIds.Contains(voiceWork.VoiceWorkId))
.Include(x => x.Circle)];
List<VoiceWork> voiceWorksToDelete = [];
foreach (VoiceWork voiceWork in voiceWorks)
{
if (results.ContainsKey(voiceWork.VoiceWorkId) == false)
@@ -46,12 +48,22 @@ public class VoiceWorkWriter(AppDbContext dbContext) : IVoiceWorkWriter
continue;
}
dbContext.Remove(voiceWork);
voiceWorksToDelete.Add(voiceWork);
results[voiceWork.VoiceWorkId] = DeleteVoiceWorkStatus.Deleted;
}
int[] voiceWorkIdsToDelete = [.. voiceWorksToDelete.Select(x => x.VoiceWorkId)];
if (voiceWorkIdsToDelete.Length > 0)
{
dbContext.VoiceWorks.RemoveRange(voiceWorksToDelete);
await dbContext.SaveChangesAsync(cancellationToken);
await dbContext.VoiceWorkSearches
.Where(x => voiceWorkIdsToDelete.Contains(x.VoiceWorkId))
.ExecuteDeleteAsync(cancellationToken);
}
return new DeleteVoiceWorkResponse(results);
}

View File

@@ -17,10 +17,16 @@ public class Delete_Voice_Work_Tests(MariaDbContainerFixture container) : VoiceW
int voiceWorkId = 3;
DeleteVoiceWorkRequest request = new([voiceWorkId]);
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
DeleteVoiceWorkResponse response = await writer.DeleteAsync(request, TestContext.Current.CancellationToken);
response.Results.Count.ShouldBe(1);
response.Results.ShouldContainKey(voiceWorkId);
response.Results[voiceWorkId].ShouldBe(DeleteVoiceWorkStatus.Deleted);
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull();
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull();
}
[Fact]
@@ -32,9 +38,15 @@ public class Delete_Voice_Work_Tests(MariaDbContainerFixture container) : VoiceW
int voiceWorkId = 1;
DeleteVoiceWorkRequest request = new([voiceWorkId]);
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
DeleteVoiceWorkResponse response = await writer.DeleteAsync(request, TestContext.Current.CancellationToken);
response.Results.Count.ShouldBe(1);
response.Results.ShouldContainKey(voiceWorkId);
response.Results[voiceWorkId].ShouldBe(DeleteVoiceWorkStatus.NotAllowed);
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
}
}

View File

@@ -8,10 +8,10 @@
<BitPivot Size="BitSize.Medium">
<BitPivotItem HeaderText="@($"Available ({availableVoiceWorks?.Length ?? 0})")">
<JProductCollection Products="availableVoiceWorks"></JProductCollection>
<JProductCollection Products="availableVoiceWorks" ProductDeleted="OnAvailableProductDeleted"></JProductCollection>
</BitPivotItem>
<BitPivotItem HeaderText="@($"Upcoming ({upcomingVoiceWorks?.Length ?? 0})")">
<JProductCollection Products="upcomingVoiceWorks"></JProductCollection>
<JProductCollection Products="upcomingVoiceWorks" ProductDeleted="OnUpcomingProductDeleted"></JProductCollection>
</BitPivotItem>
<BitPivotItem HeaderText="@($"Announcements ({announcedVoiceWorks?.Length ?? 0})")">
<JProductCollection Products="announcedVoiceWorks" ProductDeleted="OnAnnouncedProductDeleted"></JProductCollection>
@@ -106,8 +106,20 @@
await InvokeAsync(StateHasChanged);
}
private async Task OnAvailableProductDeleted()
{
_ = LoadAvailableVoiceWorksAsync();
}
private async Task OnUpcomingProductDeleted()
{
_ = LoadUpcomingVoiceWorksAsync();
_ = LoadAnnouncedVoiceWorksAsync();
}
private async Task OnAnnouncedProductDeleted()
{
_ = LoadUpcomingVoiceWorksAsync();
_ = LoadAnnouncedVoiceWorksAsync();
}
}

View File

@@ -17,7 +17,7 @@
<h3>Voice Works</h3>
<VoiceWorkFilters Value="@State" ValueChanged="UpdateAsync" />
<JProductCollection Products="Result?.Items"></JProductCollection>
<JProductCollection Products="Result?.Items" ProductDeleted="OnProductDeleted"></JProductCollection>
@if (Result is not null)
{
@@ -69,4 +69,9 @@
protected override Task<SearchResult<VoiceWorkSearchResult>> ExecuteSearchAsync(VoiceWorkFilterState state, CancellationToken ct)
=> Client.SearchAsync(state.ToSearchRequest(), ct).ContinueWith(t => t.Result?.Results ?? new SearchResult<VoiceWorkSearchResult>(), ct);
private async Task OnProductDeleted()
{
_ = RunSearchAsync(false);
}
}

View File

@@ -41,6 +41,19 @@ public abstract class SearchPageBase<TState, TItem> : ComponentBase, IAsyncDispo
_ = RunSearchAsync();
}
//protected async Task Update2Async(TState next, bool scrollToTop)
//{
// if (Equals(next, State))
// return;
// Console.WriteLine("Got here");
// State = next;
// NavigateToState(next);
// _ = RunSearchAsync(scrollToTop);
//}
private void NavigateToState(TState next)
{
string uri = BuildUri(next);
@@ -73,10 +86,13 @@ public abstract class SearchPageBase<TState, TItem> : ComponentBase, IAsyncDispo
_ = RunSearchAsync();
}
private async Task RunSearchAsync()
protected async Task RunSearchAsync(bool scrollTotop = true)
{
if (scrollTotop)
await JS.InvokeVoidAsync("pageHelpers.scrollToTop");
Console.WriteLine("Got here 2");
try
{
IsLoading = true;

View File

@@ -21,10 +21,13 @@
/* Buttons */
.ant-btn {
font-weight: var(--ant-button-font-weight);
border: var(--ant-btn-border-width) var(--ant-btn-border-style) var(--ant-btn-border-color);
/*font-weight: var(--ant-button-font-weight);
border-width: var(--ant-btn-border-width);
border-style: var(--ant-btn-border-style);
border-color: var(--ant-btn-border-color);
color: var(--ant-btn-text-color);
background-color: var(--ant-btn-bg-color);
border-radius: var(--ant-border-radius);*/
}
/*

View File

@@ -75,6 +75,9 @@
--surface-container-outline-high: rgb(83, 99, 109);
--surface-container-outline: rgb(72, 88, 99);
--surface-container-outline-low: rgb(63, 78, 88);
/* Ant Design - Core */
--ant-border-radius: 12px;
--ant-line-width: 1px;
/* Ant Design - Modals */
--ant-color-text: #b4c8d6;
--ant-modal-content-bg: #273f50;