Fixed a bug where when deleting a chapter, if it's the last chapter left, it will now delete the Series as well.
This commit is contained in:
parent
4261b61f0f
commit
1d9084fe49
5 changed files with 29 additions and 4 deletions
|
|
@ -68,7 +68,8 @@ public class ChapterController : BaseApiController
|
|||
{
|
||||
if (User.IsInRole(PolicyConstants.ReadOnlyRole)) return BadRequest(await _localizationService.Translate(User.GetUserId(), "permission-denied"));
|
||||
|
||||
var chapter = await _unitOfWork.ChapterRepository.GetChapterAsync(chapterId);
|
||||
var chapter = await _unitOfWork.ChapterRepository.GetChapterAsync(chapterId,
|
||||
ChapterIncludes.Files | ChapterIncludes.ExternalReviews | ChapterIncludes.ExternalRatings);
|
||||
if (chapter == null)
|
||||
return BadRequest(_localizationService.Translate(User.GetUserId(), "chapter-doesnt-exist"));
|
||||
|
||||
|
|
@ -86,6 +87,15 @@ public class ChapterController : BaseApiController
|
|||
_unitOfWork.ChapterRepository.Remove(chapter);
|
||||
}
|
||||
|
||||
// If we removed the volume, do an additional check if we need to delete the actual series as well or not
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(vol.SeriesId, SeriesIncludes.ExternalData | SeriesIncludes.Volumes);
|
||||
var needToRemoveSeries = needToRemoveVolume && series != null && series.Volumes.Count <= 1;
|
||||
if (needToRemoveSeries)
|
||||
{
|
||||
_unitOfWork.SeriesRepository.Remove(series!);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!await _unitOfWork.CommitAsync()) return Ok(false);
|
||||
|
||||
|
|
@ -95,6 +105,12 @@ public class ChapterController : BaseApiController
|
|||
await _eventHub.SendMessageAsync(MessageFactory.VolumeRemoved, MessageFactory.VolumeRemovedEvent(chapter.VolumeId, vol.SeriesId), false);
|
||||
}
|
||||
|
||||
if (needToRemoveSeries)
|
||||
{
|
||||
await _eventHub.SendMessageAsync(MessageFactory.SeriesRemoved,
|
||||
MessageFactory.SeriesRemovedEvent(series!.Id, series.Name, series.LibraryId), false);
|
||||
}
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue