Support deleting multiple volumes, fixes #3737

The UI doesn't seem to update while the VolumeDeleteEvent is send out
This commit is contained in:
Amelia 2025-04-16 21:24:47 +02:00
parent 4c3dd48147
commit 48e6b5a080
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
6 changed files with 79 additions and 8 deletions

View file

@ -1,4 +1,6 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using API.Constants;
using API.Data;
using API.Data.Repositories;
using API.DTOs;
@ -54,4 +56,29 @@ public class VolumeController : BaseApiController
return Ok(false);
}
[Authorize(Policy = "RequireAdminRole")]
[HttpPost("multiple")]
public async Task<ActionResult<bool>> DeleteMultipleVolumes(int[] volumesIds)
{
var volumes = (await _unitOfWork.VolumeRepository.GetVolumesById(volumesIds)).ToList();
if (volumes.Count != volumesIds.Length)
{
return BadRequest(_localizationService.Translate(User.GetUserId(), "volume-doesnt-exist"));
}
_unitOfWork.VolumeRepository.Remove(volumes);
if (!await _unitOfWork.CommitAsync())
{
return Ok(false);
}
foreach (var volume in volumes)
{
await _eventHub.SendMessageAsync(MessageFactory.VolumeRemoved, MessageFactory.VolumeRemovedEvent(volume.Id, volume.SeriesId), false);
}
return Ok(true);
}
}