use full preferred language names in ui (#137)

This commit is contained in:
Jason Dove
2021-04-04 18:30:42 -05:00
committed by GitHub
parent cead787c55
commit efae005447
7 changed files with 104 additions and 21 deletions
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
@@ -11,10 +13,14 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
{
public class MediaItemRepository : IMediaItemRepository
{
private readonly IDbConnection _dbConnection;
private readonly IDbContextFactory<TvContext> _dbContextFactory;
public MediaItemRepository(IDbContextFactory<TvContext> dbContextFactory) =>
public MediaItemRepository(IDbContextFactory<TvContext> dbContextFactory, IDbConnection dbConnection)
{
_dbContextFactory = dbContextFactory;
_dbConnection = dbConnection;
}
public async Task<Option<MediaItem>> Get(int id)
{
@@ -38,5 +44,16 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
context.MediaItems.Update(mediaItem);
return await context.SaveChangesAsync() > 0;
}
public Task<List<string>> GetAllLanguageCodes() =>
_dbConnection.QueryAsync<string>(
@"SELECT LanguageCode FROM
(SELECT Language AS LanguageCode
FROM MediaStream WHERE Language IS NOT NULL
UNION ALL SELECT PreferredLanguageCode AS LanguageCode
FROM Channel WHERE PreferredLanguageCode IS NOT NULL)
GROUP BY LanguageCode
ORDER BY COUNT(LanguageCode) DESC")
.Map(result => result.ToList());
}
}