Implemented ability to delete a series. Refactored some operations to remove unneeded parameters.
This commit is contained in:
parent
83076f02ad
commit
56e8a0059e
9 changed files with 50 additions and 16 deletions
|
@ -159,13 +159,13 @@ namespace API.Controllers
|
|||
var username = User.GetUsername();
|
||||
_logger.LogInformation($"Library {libraryId} is being deleted by {username}.");
|
||||
var series = await _seriesRepository.GetSeriesDtoForLibraryIdAsync(libraryId);
|
||||
var volumes = (await _seriesRepository.GetVolumesForSeriesAsync(series.Select(x => x.Id).ToArray())).ToList();
|
||||
var volumes = (await _seriesRepository.GetVolumesForSeriesAsync(series.Select(x => x.Id).ToArray()))
|
||||
.Select(x => x.Id).ToArray();
|
||||
var result = await _libraryRepository.DeleteLibrary(libraryId);
|
||||
|
||||
|
||||
if (result && volumes.Any())
|
||||
{
|
||||
BackgroundJob.Enqueue(() => _cacheService.CleanupLibrary(libraryId, volumes.Select(x => x.Id).ToArray()));
|
||||
BackgroundJob.Enqueue(() => _cacheService.CleanupVolumes(volumes));
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Extensions;
|
||||
using API.Interfaces;
|
||||
using AutoMapper;
|
||||
using Hangfire;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
@ -14,14 +18,17 @@ namespace API.Controllers
|
|||
private readonly IMapper _mapper;
|
||||
private readonly ITaskScheduler _taskScheduler;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
private readonly ICacheService _cacheService;
|
||||
|
||||
public SeriesController(ILogger<SeriesController> logger, IMapper mapper,
|
||||
ITaskScheduler taskScheduler, ISeriesRepository seriesRepository)
|
||||
ITaskScheduler taskScheduler, ISeriesRepository seriesRepository,
|
||||
ICacheService cacheService)
|
||||
{
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
_taskScheduler = taskScheduler;
|
||||
_seriesRepository = seriesRepository;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
[HttpGet("{seriesId}")]
|
||||
|
@ -30,6 +37,22 @@ namespace API.Controllers
|
|||
return Ok(await _seriesRepository.GetSeriesDtoByIdAsync(seriesId));
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpDelete("{seriesId}")]
|
||||
public async Task<ActionResult<bool>> DeleteSeries(int seriesId)
|
||||
{
|
||||
var username = User.GetUsername();
|
||||
var volumes = (await _seriesRepository.GetVolumesForSeriesAsync(new []{seriesId})).Select(x => x.Id).ToArray();
|
||||
_logger.LogInformation($"Series {seriesId} is being deleted by {username}.");
|
||||
var result = await _seriesRepository.DeleteSeriesAsync(seriesId);
|
||||
|
||||
if (result)
|
||||
{
|
||||
BackgroundJob.Enqueue(() => _cacheService.CleanupVolumes(volumes));
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("volumes")]
|
||||
public async Task<ActionResult<IEnumerable<VolumeDto>>> GetVolumes(int seriesId)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue