Skip to content

Commit

Permalink
fix: get top level groups for groups matching the filter
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Oct 31, 2024
1 parent 49705f6 commit 62c49b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 38 deletions.
28 changes: 9 additions & 19 deletions Shoko.Server/API/v3/Controllers/FilterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
using Shoko.Commons.Extensions;
using Shoko.Server.API.Annotations;
using Shoko.Server.API.ModelBinders;
using Shoko.Server.API.v3.Helpers;
Expand Down Expand Up @@ -337,16 +338,10 @@ public ActionResult<ListResult<Group>> GetPreviewFilteredGroups([FromBody] Filte
if (!results.Any()) return new ListResult<Group>();

var groups = results
.Select(group => RepoFactory.AnimeGroup.GetByID(group.Key))
.Where(group =>
{
// not top level groups
if (group == null || group.AnimeGroupParentID.HasValue)
return false;

return includeEmpty || group.AllSeries
.Any(s => s.AnimeEpisodes.Any(e => e.VideoLocals.Count > 0));
});
.Select(group => RepoFactory.AnimeGroup.GetByID(group.Key)?.TopLevelAnimeGroup)
.WhereNotNull()
.DistinctBy(group => group.AnimeGroupID)
.Where(group => includeEmpty || group.AllSeries.Any(s => s.AnimeEpisodes.Any(e => e.VideoLocals.Count > 0)));

if (orderByName)
groups = groups.OrderBy(group => group.SortName);
Expand Down Expand Up @@ -378,15 +373,10 @@ public ActionResult<Dictionary<char, int>> GetPreviewGroupNameLettersInFilter([F
return new Dictionary<char, int>();

return results
.Select(group => RepoFactory.AnimeGroup.GetByID(group.Key))
.Where(group =>
{
if (group is not { AnimeGroupParentID: null })
return false;

return includeEmpty || group.AllSeries
.Any(s => s.AnimeEpisodes.Any(e => e.VideoLocals.Count > 0));
})
.Select(group => RepoFactory.AnimeGroup.GetByID(group.Key)?.TopLevelAnimeGroup)
.WhereNotNull()
.DistinctBy(group => group.AnimeGroupID)
.Where(group => includeEmpty || group.AllSeries.Any(s => s.AnimeEpisodes.Any(e => e.VideoLocals.Count > 0)))
.GroupBy(group => group.SortName[0])
.OrderBy(groupList => groupList.Key)
.ToDictionary(groupList => groupList.Key, groupList => groupList.Count());
Expand Down
27 changes: 8 additions & 19 deletions Shoko.Server/API/v3/Controllers/TreeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,10 @@ public ActionResult<ListResult<Group>> GetFilteredGroups([FromRoute, Range(0, in
if (!results.Any()) return new ListResult<Group>();

groups = results
.Select(group => RepoFactory.AnimeGroup.GetByID(group.Key))
.Where(group =>
{
// not top level groups
if (group == null || group.AnimeGroupParentID.HasValue)
return false;

return includeEmpty || group.AllSeries
.Any(s => s.AnimeEpisodes.Any(e => e.VideoLocals.Count > 0));
});
.Select(group => RepoFactory.AnimeGroup.GetByID(group.Key)?.TopLevelAnimeGroup)
.WhereNotNull()
.DistinctBy(group => group.AnimeGroupID)
.Where(group => includeEmpty || group.AllSeries.Any(s => s.AnimeEpisodes.Any(e => e.VideoLocals.Count > 0)));
}

if (orderByName)
Expand Down Expand Up @@ -227,15 +221,10 @@ public ActionResult<Dictionary<char, int>> GetGroupNameLettersInFilter([FromRout
return new Dictionary<char, int>();

return results
.Select(group => RepoFactory.AnimeGroup.GetByID(group.Key))
.Where(group =>
{
if (group is not { AnimeGroupParentID: null })
return false;

return includeEmpty || group.AllSeries
.Any(s => s.AnimeEpisodes.Any(e => e.VideoLocals.Count > 0));
})
.Select(group => RepoFactory.AnimeGroup.GetByID(group.Key)?.TopLevelAnimeGroup)
.WhereNotNull()
.DistinctBy(group => group.AnimeGroupID)
.Where(group => includeEmpty || group.AllSeries.Any(s => s.AnimeEpisodes.Any(e => e.VideoLocals.Count > 0)))
.GroupBy(group => group.SortName[0])
.OrderBy(groupList => groupList.Key)
.ToDictionary(groupList => groupList.Key, groupList => groupList.Count());
Expand Down

0 comments on commit 62c49b1

Please sign in to comment.