Add metadata management for shows: implement metadata retrieval, application, and updates in the API and UI. Enhance Show and ShowDto models to include metadata fields, and update the database schema accordingly. Introduce new endpoints for metadata operations and integrate metadata display in the ShowDetail component.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
|
||||
namespace TeleWave.Infrastructure.Metadata;
|
||||
|
||||
/// <summary>Резолвит провайдеры по ключу; доступными считает только те, у кого задан API-ключ.</summary>
|
||||
public sealed class MetadataProviderResolver : IMetadataProviderResolver
|
||||
{
|
||||
private readonly Dictionary<string, IMetadataProvider> _byKey;
|
||||
private readonly List<string> _available = new();
|
||||
|
||||
public MetadataProviderResolver(
|
||||
IEnumerable<IMetadataProvider> providers,
|
||||
IOptions<MetadataOptions> options
|
||||
)
|
||||
{
|
||||
_byKey = providers.ToDictionary(p => p.Key, StringComparer.OrdinalIgnoreCase);
|
||||
var opt = options.Value;
|
||||
if (_byKey.ContainsKey("tmdb") && !string.IsNullOrWhiteSpace(opt.Tmdb.ApiKey))
|
||||
_available.Add("tmdb");
|
||||
if (_byKey.ContainsKey("omdb") && !string.IsNullOrWhiteSpace(opt.Omdb.ApiKey))
|
||||
_available.Add("omdb");
|
||||
}
|
||||
|
||||
public IMetadataProvider? Resolve(string key) =>
|
||||
_available.Contains(key, StringComparer.OrdinalIgnoreCase)
|
||||
&& _byKey.TryGetValue(key, out var provider)
|
||||
? provider
|
||||
: null;
|
||||
|
||||
public IReadOnlyList<string> AvailableKeys => _available;
|
||||
}
|
||||
Reference in New Issue
Block a user