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"));
|
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)
|
if (chapter == null)
|
||||||
return BadRequest(_localizationService.Translate(User.GetUserId(), "chapter-doesnt-exist"));
|
return BadRequest(_localizationService.Translate(User.GetUserId(), "chapter-doesnt-exist"));
|
||||||
|
|
||||||
|
|
@ -86,6 +87,15 @@ public class ChapterController : BaseApiController
|
||||||
_unitOfWork.ChapterRepository.Remove(chapter);
|
_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);
|
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);
|
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);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ public class MetadataController(IUnitOfWork unitOfWork, ILocalizationService loc
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PrepareSeriesDetail(List<UserReviewDto> userReviews, SeriesDetailPlusDto ret)
|
private async Task PrepareSeriesDetail(List<UserReviewDto> userReviews, SeriesDetailPlusDto? ret)
|
||||||
{
|
{
|
||||||
var isAdmin = User.IsInRole(PolicyConstants.AdminRole);
|
var isAdmin = User.IsInRole(PolicyConstants.AdminRole);
|
||||||
var user = await unitOfWork.UserRepository.GetUserByIdAsync(User.GetUserId())!;
|
var user = await unitOfWork.UserRepository.GetUserByIdAsync(User.GetUserId())!;
|
||||||
|
|
@ -235,12 +235,12 @@ public class MetadataController(IUnitOfWork unitOfWork, ILocalizationService loc
|
||||||
ret.Recommendations.OwnedSeries =
|
ret.Recommendations.OwnedSeries =
|
||||||
await unitOfWork.SeriesRepository.GetSeriesDtoByIdsAsync(
|
await unitOfWork.SeriesRepository.GetSeriesDtoByIdsAsync(
|
||||||
ret.Recommendations.OwnedSeries.Select(s => s.Id), user);
|
ret.Recommendations.OwnedSeries.Select(s => s.Id), user);
|
||||||
ret.Recommendations.ExternalSeries = new List<ExternalSeriesDto>();
|
ret.Recommendations.ExternalSeries = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret.Recommendations != null && user != null)
|
if (ret.Recommendations != null && user != null)
|
||||||
{
|
{
|
||||||
ret.Recommendations.OwnedSeries ??= new List<SeriesDto>();
|
ret.Recommendations.OwnedSeries ??= [];
|
||||||
await unitOfWork.SeriesRepository.AddSeriesModifiers(user.Id, ret.Recommendations.OwnedSeries);
|
await unitOfWork.SeriesRepository.AddSeriesModifiers(user.Id, ret.Recommendations.OwnedSeries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ public enum ChapterIncludes
|
||||||
Genres = 16,
|
Genres = 16,
|
||||||
Tags = 32,
|
Tags = 32,
|
||||||
ExternalReviews = 1 << 6,
|
ExternalReviews = 1 << 6,
|
||||||
|
ExternalRatings = 1 << 7
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IChapterRepository
|
public interface IChapterRepository
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ public enum SeriesIncludes
|
||||||
ExternalRatings = 128,
|
ExternalRatings = 128,
|
||||||
ExternalRecommendations = 256,
|
ExternalRecommendations = 256,
|
||||||
ExternalMetadata = 512,
|
ExternalMetadata = 512,
|
||||||
|
|
||||||
|
ExternalData = ExternalMetadata | ExternalReviews | ExternalRatings | ExternalRecommendations,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,12 @@ public static class IncludesExtensions
|
||||||
.Include(c => c.ExternalReviews);
|
.Include(c => c.ExternalReviews);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (includes.HasFlag(ChapterIncludes.ExternalRatings))
|
||||||
|
{
|
||||||
|
queryable = queryable
|
||||||
|
.Include(c => c.ExternalRatings);
|
||||||
|
}
|
||||||
|
|
||||||
return queryable.AsSplitQuery();
|
return queryable.AsSplitQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue