Added manga data and pipeline.
This commit is contained in:
33
MangaReader.Core/Search/MangaSearchProviderBase.cs
Normal file
33
MangaReader.Core/Search/MangaSearchProviderBase.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using MangaReader.Core.HttpService;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MangaReader.Core.Search;
|
||||
|
||||
public abstract class MangaSearchProviderBase<T>(IHttpService httpService) : IMangaSearchProvider<T>
|
||||
{
|
||||
private static JsonSerializerOptions _jsonSerializerOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public async Task<MangaSearchResult[]> SearchAsync(string keyword)
|
||||
{
|
||||
T? searchResult = await GetSearchResultAsync(keyword);
|
||||
|
||||
if (searchResult == null)
|
||||
return [];
|
||||
|
||||
return GetSearchResult(searchResult);
|
||||
}
|
||||
|
||||
private async Task<T?> GetSearchResultAsync(string keyword)
|
||||
{
|
||||
string url = GetSearchUrl(keyword);
|
||||
string response = await httpService.GetStringAsync(url);
|
||||
|
||||
return JsonSerializer.Deserialize<T>(response, _jsonSerializerOptions);
|
||||
}
|
||||
|
||||
protected abstract string GetSearchUrl(string keyword);
|
||||
protected abstract MangaSearchResult[] GetSearchResult(T searchResult);
|
||||
}
|
||||
Reference in New Issue
Block a user