From a0e0a0e610f096bbb3b382932f5dc546e3255e16 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Mon, 1 Jul 2019 11:39:00 -0500 Subject: [PATCH] extract and simplify BuildEndpoint() --- .../Repositories/EntityUrlsRepository.cs | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/FilterLists.Agent/Infrastructure/Repositories/EntityUrlsRepository.cs b/src/FilterLists.Agent/Infrastructure/Repositories/EntityUrlsRepository.cs index c6c491ff4..c6e1565bc 100644 --- a/src/FilterLists.Agent/Infrastructure/Repositories/EntityUrlsRepository.cs +++ b/src/FilterLists.Agent/Infrastructure/Repositories/EntityUrlsRepository.cs @@ -16,26 +16,30 @@ public EntityUrlsRepository(IFilterListsApiClient apiClient) _apiClient = apiClient; } - public async Task> GetAllAsync() - where TEntityUrls : IEntityUrls, new() + public async Task> GetAllAsync() 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(); var request = new RestRequest(endpoint); return await _apiClient.ExecuteAsync>(request); } + + private static string BuildEndpoint() 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"; + } } } \ No newline at end of file