Added "Delete Voice Works" functionality.

This commit is contained in:
2026-05-04 01:51:40 -04:00
parent 77a02a543d
commit f6674e0382
7 changed files with 147 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
using JSMR.Application.VoiceWorks.Commands.SetFavorite;
using JSMR.Application.VoiceWorks.Commands.Delete;
using JSMR.Application.VoiceWorks.Commands.SetFavorite;
using JSMR.Application.VoiceWorks.Ports;
using JSMR.Domain.Entities;
using Microsoft.EntityFrameworkCore;
@@ -17,6 +18,32 @@ public class VoiceWorkWriter(AppDbContext dbContext) : IVoiceWorkWriter
return new SetVoiceWorkFavoriteResponse(request.VoiceWorkId, request.IsFavorite);
}
public async Task<DeleteVoiceWorkResponse> DeleteAsync(DeleteVoiceWorkRequest request, CancellationToken cancellationToken)
{
Dictionary<int, bool> isSuccess = [];
VoiceWork[] voiceWorks = [.. dbContext.VoiceWorks.Where(voiceWork => request.VoiceWorkIds.Contains(voiceWork.VoiceWorkId))
.Include(x => x.Circle)];
foreach (VoiceWork voiceWork in voiceWorks)
{
isSuccess.Add(voiceWork.VoiceWorkId, false);
if (voiceWork.Circle is null)
continue;
if (voiceWork.IsValid == true && voiceWork.Circle.Spam == false)
continue;
dbContext.Remove(voiceWork);
isSuccess[voiceWork.VoiceWorkId] = true;
}
dbContext.SaveChanges();
return new DeleteVoiceWorkResponse(isSuccess);
}
private async Task<VoiceWork> GetVoiceWorkAsync(int voiceWorkId, CancellationToken cancellationToken)
{
return await dbContext.VoiceWorks.FirstOrDefaultAsync(voiceWork => voiceWork.VoiceWorkId == voiceWorkId, cancellationToken)