Skip to content

Commit

Permalink
refactor: fix sort for series soft dup endpoint and add ep count per …
Browse files Browse the repository at this point in the history
…series
  • Loading branch information
revam committed Nov 25, 2023
1 parent c37fc89 commit ad390c8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Shoko.Server/API/v3/Controllers/SeriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@ private static void CheckTitlesStartsWith(SVR_AnimeSeries a, string query,
/// <param name="page">Page number.</param>
/// <returns></returns>
[HttpGet("WithSoftDuplicates")]
public ActionResult<ListResult<Series>> GetSeriesWithSoftDuplicates(
public ActionResult<ListResult<SeriesWithDuplicatesResult>> GetSeriesWithSoftDuplicates(
[FromQuery, ModelBinder(typeof(CommaDelimitedModelBinder))] HashSet<DataSource> includeDataFrom = null,
[FromQuery] bool ignoreVariations = true,
[FromQuery] bool onlyFinishedSeries = false,
Expand All @@ -2127,7 +2127,9 @@ public ActionResult<ListResult<Series>> GetSeriesWithSoftDuplicates(
}

return enumerable
.ToListResult(series => _seriesFactory.GetSeries(series, false, includeDataFrom), page, pageSize);
.OrderBy(series => series.GetSeriesName())
.ThenBy(series => series.AniDB_ID)
.ToListResult(series => _seriesFactory.GetSeriesWithDuplicatesResult(series, false, includeDataFrom, ignoreVariations), page, pageSize);
}

#endregion
Expand Down
26 changes: 26 additions & 0 deletions Shoko.Server/API/v3/Helpers/SeriesFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -866,4 +866,30 @@ public SeriesSearchResult GetSeriesSearchResult(SeriesSearch.SearchResult<SVR_An
};
return searchResult;
}

public SeriesWithDuplicatesResult GetSeriesWithDuplicatesResult(
SVR_AnimeSeries animeSeries,
bool randomiseImages = false,
HashSet<DataSource> includeDataFrom = null,
bool ignoreVariations = true)
{
var series = GetSeries(animeSeries, randomiseImages, includeDataFrom);
var episodesWithSoftDuplicates = RepoFactory.AnimeEpisode.GetWithSoftDuplicates(ignoreVariations, animeSeries.AniDB_ID).Count;
return new()
{
Name = series.Name,
IDs = series.IDs,
Size = series.Size,
Sizes = series.Sizes,
Created = series.Created,
Updated = series.Updated,
AirsOn = series.AirsOn,
UserRating = series.UserRating,
Images = series.Images,
Links = series.Links,
_AniDB = series._AniDB,
_TvDB = series._TvDB,
EpisodesWithSoftDuplicates = episodesWithSoftDuplicates,
};
}
}
11 changes: 11 additions & 0 deletions Shoko.Server/API/v3/Models/Shoko/Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,17 @@ public class SeriesSearchResult : Series
public string Match { get; set; } = string.Empty;
}

/// <summary>
/// An extended model for use with the soft duplicate endpoint.
/// </summary>
public class SeriesWithDuplicatesResult : Series
{
/// <summary>
/// Number of episodes in the series which have soft duplicates.
/// </summary>
public int EpisodesWithSoftDuplicates { get; set; }
}

public enum SeriesType
{
/// <summary>
Expand Down

0 comments on commit ad390c8

Please sign in to comment.