Fixed voice work supported language search. Include supported languages and original circle in the search result item. Several UI style updates.
Some checks failed
ci / build-test (push) Failing after 2m52s
ci / publish-image (push) Has been skipped

This commit is contained in:
2026-03-17 00:07:02 -04:00
parent c8403e0e21
commit 22d5a261c5
14 changed files with 352 additions and 45 deletions

View File

@@ -3,6 +3,7 @@ using JSMR.Application.Enums;
using JSMR.Application.VoiceWorks.Queries.Search;
using JSMR.Domain.Entities;
using JSMR.Domain.Enums;
using JSMR.Domain.ValueObjects;
using JSMR.Infrastructure.Common.Queries;
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;
@@ -60,9 +61,10 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
break;
}
if (criteria.SupportedLanguages.Length > 0)
filteredQuery = filteredQuery.Where(x => criteria.SupportedLanguages.AsEnumerable().Contains((Language)x.VoiceWork.SubtitleLanguage));
//if (criteria.SupportedLanguages.Length > 0)
// filteredQuery = filteredQuery.Where(x => criteria.SupportedLanguages.AsEnumerable().Contains((Language)x.VoiceWork.SubtitleLanguage));
filteredQuery = ApplySupportedLanguageFilter(filteredQuery, criteria);
filteredQuery = ApplyCircleStatusFilter(filteredQuery, criteria);
filteredQuery = ApplyTagStatusFilter(filteredQuery, criteria);
filteredQuery = ApplyCreatorStatusFilter(filteredQuery, criteria);
@@ -118,6 +120,26 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
return query.Where(x => voiceWorkIds.Contains(x.VoiceWork.VoiceWorkId));
}
private IQueryable<VoiceWorkQuery> ApplySupportedLanguageFilter(IQueryable<VoiceWorkQuery> query, VoiceWorkSearchCriteria criteria)
{
if (criteria.SupportedLanguages.Length == 0)
return query;
List<string> languageCodes = [];
foreach (Language language in criteria.SupportedLanguages)
{
if (SupportedLanguage.TryFromLanguage(language, out SupportedLanguage? supportedLanguage))
languageCodes.Add(supportedLanguage.Code);
}
if (languageCodes.Count == 0)
return query;
return query.Where(q => context.VoiceWorkSupportedLanguages.Any(sl => sl.VoiceWorkId == q.VoiceWork.VoiceWorkId && languageCodes.Contains(sl.Language)));
}
private IQueryable<VoiceWorkQuery> ApplyCircleStatusFilter(IQueryable<VoiceWorkQuery> query, VoiceWorkSearchCriteria criteria)
{
if (criteria.CircleStatus is null)
@@ -432,6 +454,7 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
PlannedReleaseDate = voiceWork.PlannedReleaseDate,
Downloads = voiceWork.Downloads,
WishlistCount = voiceWork.WishlistCount,
Rating = (AgeRating)voiceWork.Rating,
Status = voiceWork.Status,
SubtitleLanguage = voiceWork.SubtitleLanguage,
HasTrial = voiceWork.HasTrial,
@@ -449,16 +472,24 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
int[] voiceWorkIds = [.. items.Select(i => i.VoiceWorkId)];
Dictionary<int, VoiceWorkTagItem[]> tagsByVw = await GetTagsAsync(voiceWorkIds, cancellationToken);
Dictionary<int, VoiceWorkCreatorItem[]> creatorsByVw = await GetCreatorsAsync(voiceWorkIds, cancellationToken);
var tagsByVoiceWork = await GetTagsAsync(voiceWorkIds, cancellationToken);
var creatorsByVoiceWork = await GetCreatorsAsync(voiceWorkIds, cancellationToken);
var supportedLanguagesByVoiceWork = await GetSupportedLanguagesAsync(voiceWorkIds, cancellationToken);
var originalCirclesByVoiceWork = await GetOriginalCircles(voiceWorkIds, cancellationToken);
foreach (VoiceWorkSearchResult item in items)
{
if (tagsByVw.TryGetValue(item.VoiceWorkId, out VoiceWorkTagItem[]? tags))
if (tagsByVoiceWork.TryGetValue(item.VoiceWorkId, out VoiceWorkTagItem[]? tags))
item.Tags = tags;
if (creatorsByVw.TryGetValue(item.VoiceWorkId, out VoiceWorkCreatorItem[]? creators))
if (creatorsByVoiceWork.TryGetValue(item.VoiceWorkId, out VoiceWorkCreatorItem[]? creators))
item.Creators = creators;
if (supportedLanguagesByVoiceWork.TryGetValue(item.VoiceWorkId, out string[]? supportedLanguages))
item.SupportedLanguages = supportedLanguages;
if (originalCirclesByVoiceWork.TryGetValue(item.VoiceWorkId, out VoiceWorkCircleItem? voiceWorkCircleItem))
item.OriginalCircle = voiceWorkCircleItem;
}
}
@@ -499,4 +530,51 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
g => g.Select(r => new VoiceWorkCreatorItem { CreatorId = r.CreatorId, Name = r.Name, IsFavorite = r.Favorite, IsBlacklisted = r.Blacklisted }).ToArray()
);
}
private async Task<Dictionary<int, string[]>> GetSupportedLanguagesAsync(int[] voiceWorkIds, CancellationToken cancellationToken)
{
var supportedLanguageRows = await (
from voiceWorkSupportedLanguage in context.VoiceWorkSupportedLanguages.AsNoTracking()
where voiceWorkIds.Contains(voiceWorkSupportedLanguage.VoiceWorkId)
select new { voiceWorkSupportedLanguage.VoiceWorkId, voiceWorkSupportedLanguage.Language }
).ToListAsync(cancellationToken);
return supportedLanguageRows
.GroupBy(r => r.VoiceWorkId)
.ToDictionary(
g => g.Key,
g => g.Select(r => r.Language).ToArray()
);
}
private async Task<Dictionary<int, VoiceWorkCircleItem>> GetOriginalCircles(int[] voiceWorkIds, CancellationToken cancellationToken)
{
var originalCircleRows = await (
from voiceWork in context.VoiceWorks.AsNoTracking()
join orignalVoiceWork in context.VoiceWorks.AsNoTracking() on voiceWork.OriginalProductId equals orignalVoiceWork.ProductId
join originalCircle in context.Circles.AsNoTracking() on orignalVoiceWork.CircleId equals originalCircle.CircleId
where voiceWorkIds.Contains(voiceWork.VoiceWorkId)
select new
{
voiceWork.VoiceWorkId,
originalCircle.Name,
originalCircle.MakerId,
originalCircle.Favorite,
originalCircle.Blacklisted
}
).ToListAsync(cancellationToken);
return originalCircleRows
.GroupBy(r => r.VoiceWorkId)
.ToDictionary(
g => g.Key,
g => g.Select(r => new VoiceWorkCircleItem()
{
Name = r.Name,
MakerId = r.MakerId,
IsFavorite = r.Favorite,
IsBlacklisted = r.Blacklisted
}).First()
);
}
}