mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
extract and simplify BuildEndpoint()
This commit is contained in:
parent
fda39de66b
commit
a0e0a0e610
1 changed files with 21 additions and 17 deletions
|
|
@ -16,26 +16,30 @@ public EntityUrlsRepository(IFilterListsApiClient apiClient)
|
|||
_apiClient = apiClient;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TEntityUrls>> GetAllAsync<TEntityUrls>()
|
||||
where TEntityUrls : IEntityUrls, new()
|
||||
public async Task<IEnumerable<TEntityUrls>> GetAllAsync<TEntityUrls>() where TEntityUrls : IEntityUrls, new()
|
||||
{
|
||||
string entityEndpoint;
|
||||
switch (typeof(TEntityUrls).Name)
|
||||
{
|
||||
case nameof(SyntaxUrls):
|
||||
entityEndpoint = typeof(TEntityUrls).Name.Replace("Urls", "es").ToLowerInvariant();
|
||||
break;
|
||||
case nameof(SoftwareUrls):
|
||||
entityEndpoint = typeof(TEntityUrls).Name.Replace("Urls", "").ToLowerInvariant();
|
||||
break;
|
||||
default:
|
||||
entityEndpoint = typeof(TEntityUrls).Name.Replace("Urls", "s").ToLowerInvariant();
|
||||
break;
|
||||
}
|
||||
|
||||
var endpoint = $"{entityEndpoint}/seed";
|
||||
var endpoint = BuildEndpoint<TEntityUrls>();
|
||||
var request = new RestRequest(endpoint);
|
||||
return await _apiClient.ExecuteAsync<IEnumerable<TEntityUrls>>(request);
|
||||
}
|
||||
|
||||
private static string BuildEndpoint<TEntityUrls>() where TEntityUrls : IEntityUrls, new()
|
||||
{
|
||||
string endpointSuffix;
|
||||
switch (typeof(TEntityUrls).Name)
|
||||
{
|
||||
case nameof(SyntaxUrls):
|
||||
endpointSuffix = "es";
|
||||
break;
|
||||
case nameof(SoftwareUrls):
|
||||
endpointSuffix = "";
|
||||
break;
|
||||
default:
|
||||
endpointSuffix = "s";
|
||||
break;
|
||||
}
|
||||
|
||||
return $"{typeof(TEntityUrls).Name.Replace("Urls", endpointSuffix).ToLowerInvariant()}/seed";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue