extract and simplify BuildEndpoint()

This commit is contained in:
Collin M. Barrett 2019-07-01 11:39:00 -05:00
parent fda39de66b
commit a0e0a0e610

View file

@ -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";
}
}
}