Skip to content

Commit

Permalink
feat: add multi-type filtering for series episode
Browse files Browse the repository at this point in the history
endpoint in api v3
  • Loading branch information
revam committed Apr 1, 2023
1 parent 83ef77d commit e12f34c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Shoko.Server/API/v3/Controllers/TreeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,15 @@ public ActionResult<Series> GetMainSeriesInGroup([FromRoute] int groupID, [FromQ
/// <param name="includeHidden">Include hidden episodes in the list.</param>
/// <param name="includeDataFrom">Include data from selected <see cref="DataSource"/>s.</param>
/// <param name="includeWatched">Include watched episodes in the list.</param>
/// <param name="type">Filter episodes by the specified <see cref="EpisodeType"/>.</param>
/// <param name="type">Filter episodes by the specified <see cref="EpisodeType"/>s.</param>
/// <returns>A list of episodes based on the specified filters.</returns>
[HttpGet("Series/{seriesID}/Episode")]
public ActionResult<ListResult<Episode>> GetEpisodes([FromRoute] int seriesID,
[FromQuery] [Range(0, 1000)] int pageSize = 20, [FromQuery] [Range(1, int.MaxValue)] int page = 1,
[FromQuery] IncludeOnlyFilter includeMissing = IncludeOnlyFilter.False, [FromQuery] IncludeOnlyFilter includeHidden = IncludeOnlyFilter.False,
[FromQuery, ModelBinder(typeof(CommaDelimitedModelBinder))] HashSet<DataSource> includeDataFrom = null,
[FromQuery] IncludeOnlyFilter includeWatched = IncludeOnlyFilter.True, [FromQuery] EpisodeType? type = null)
[FromQuery] IncludeOnlyFilter includeWatched = IncludeOnlyFilter.True,
[FromQuery, ModelBinder(typeof(CommaDelimitedModelBinder))] HashSet<EpisodeType> type = null)
{
var series = RepoFactory.AnimeSeries.GetByID(seriesID);
if (series == null)
Expand All @@ -565,8 +566,12 @@ [FromQuery] [Range(0, 1000)] int pageSize = 20, [FromQuery] [Range(1, int.MaxVal
return false;

// Filter by episode type, if specified
if (type.HasValue && type.Value != Episode.MapAniDBEpisodeType((AniDBEpisodeType)a.AniDB_Episode.EpisodeType))
return false;
if (type != null)
{
var mappedType = Episode.MapAniDBEpisodeType((AniDBEpisodeType)a.AniDB_Episode.EpisodeType);
if (!type.Contains(mappedType))
return false;
}

// Filter by availability, if specified
if (includeMissing != IncludeOnlyFilter.True)
Expand Down

0 comments on commit e12f34c

Please sign in to comment.