Skip to content

Commit

Permalink
fix: fix getting series for group
Browse files Browse the repository at this point in the history
returning series not in the group or any sub-groups.
  • Loading branch information
revam committed Oct 5, 2023
1 parent 3a53cd9 commit d7b0655
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions Shoko.Server/Models/SVR_AnimeGroup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -292,23 +292,35 @@ public void SetMainSeries(SVR_AnimeSeries series)
RepoFactory.AnimeGroup.Save(this, false, false);
}

public List<SVR_AnimeSeries> GetSeries()
public List<SVR_AnimeSeries> GetSeries(bool skipSorting = false)
{
// Make sure the default/main series is the first, if it's directly within the group
if (DefaultAnimeSeriesID == null && MainAniDBAnimeID == null)
return RepoFactory.AnimeSeries.GetByGroupID(AnimeGroupID).OrderBy(a => a.AirDate).ToList();
if (skipSorting)
return RepoFactory.AnimeSeries.GetByGroupID(AnimeGroupID);

SVR_AnimeSeries mainSeries = null;
if (DefaultAnimeSeriesID.HasValue) mainSeries = RepoFactory.AnimeSeries.GetByID(DefaultAnimeSeriesID.Value);
if (mainSeries == null && MainAniDBAnimeID.HasValue) mainSeries = RepoFactory.AnimeSeries.GetByAnimeID(MainAniDBAnimeID.Value);
var seriesList = RepoFactory.AnimeSeries
.GetByGroupID(AnimeGroupID)
.OrderBy(a => a.AirDate)
.ToList();

var seriesList = RepoFactory.AnimeSeries.GetByGroupID(AnimeGroupID).OrderBy(a => a.AirDate).ToList();
if (mainSeries == null) return seriesList;
// Make sure the default/main series is the first, if it's directly
// within the group.
if (DefaultAnimeSeriesID.HasValue || MainAniDBAnimeID.HasValue)
{
SVR_AnimeSeries mainSeries = null;
if (DefaultAnimeSeriesID.HasValue)
mainSeries = seriesList.Find(series => series.AnimeSeriesID == DefaultAnimeSeriesID.Value);

seriesList.Remove(mainSeries);
seriesList.Insert(0, mainSeries);
return seriesList;
if (mainSeries == null && MainAniDBAnimeID.HasValue)
mainSeries = seriesList.Find(series => series.AniDB_ID == MainAniDBAnimeID.Value);

if (mainSeries != null)
{
seriesList.Remove(mainSeries);
seriesList.Insert(0, mainSeries);
}
}

return seriesList;
}

public List<SVR_AnimeSeries> GetAllSeries(bool skipSorting = false)
Expand Down Expand Up @@ -1266,7 +1278,7 @@ public static void GetAnimeSeriesRecursive(int animeGroupID, ref List<SVR_AnimeS
}

// get the series for this group
var thisSeries = grp.GetSeries();
var thisSeries = grp.GetSeries(true);
seriesList.AddRange(thisSeries);

foreach (var childGroup in grp.GetChildGroups())
Expand Down

0 comments on commit d7b0655

Please sign in to comment.