diff --git a/DeskHubSharpRevised/DAL/ApiDataService.cs b/DeskHubSharpRevised/DAL/ApiDataService.cs index f615beb..1eb284f 100644 --- a/DeskHubSharpRevised/DAL/ApiDataService.cs +++ b/DeskHubSharpRevised/DAL/ApiDataService.cs @@ -8,7 +8,7 @@ using RestSharp; namespace DeskHubSharpRevised.DAL; -public class ApiDataService +public class ApiDataService : IDataService { private string _apiEndpoint; private string _query; @@ -33,23 +33,13 @@ public class ApiDataService { try { - var client = new RestClient(_apiEndpoint); + RestClient client = new RestClient(_apiEndpoint); RestRequest requestRepo = new RestRequest($"users/{_query}/repos", Method.Get); - var response = client.Execute(requestRepo); - var x = response.Content; - var deserialized = JsonConvert.DeserializeObject>(x); - - if (deserialized.Count == 0) - { - throw new Exception(); - } - else - { - RequestList.repoDetail = deserialized; - } + string? response = client.Execute(requestRepo).Content; + RequestList.repoDetail = JsonConvert.DeserializeObject>(response); } - catch (Exception) + catch (NullReferenceException) { ErrorWindow err = new ErrorWindow(); err.txtblk_error.Text = "We couldn't gather repository data. Please try again"; @@ -64,23 +54,11 @@ public class ApiDataService { try { - var client = new RestClient(_apiEndpoint); - + RestClient client = new RestClient(_apiEndpoint); RestRequest requestUser = new RestRequest($"users/{_query}", Method.Get); - var response = client.Execute(requestUser); - string x = response.Content; - var deserailized = JsonConvert.DeserializeObject(x); - - if (deserailized == null) - { - throw new Exception(); - } - else - { - RequestList.userDetail = deserailized; - } - + string? response = client.Execute(requestUser).Content; + RequestList.userDetail = JsonConvert.DeserializeObject(response); } catch (NullReferenceException) { @@ -97,15 +75,11 @@ public class ApiDataService { try { - var client = new RestClient(_apiEndpoint); - + RestClient client = new RestClient(_apiEndpoint); RestRequest requestUser = new RestRequest($"/repos/{RequestList.userDetail.login}/{_query}/branches", Method.Get); - var response = client.Execute(requestUser); - string x = response.Content; - var deserailized = JsonConvert.DeserializeObject>(x); - - RequestList.branchDetail = deserailized; + string? response = client.Execute(requestUser).Content; + RequestList.branchDetail = JsonConvert.DeserializeObject>(response); } catch (NullReferenceException) { diff --git a/DeskHubSharpRevised/DAL/JsonDataService.cs b/DeskHubSharpRevised/DAL/JsonDataService.cs index 4e9024f..b9bb616 100644 --- a/DeskHubSharpRevised/DAL/JsonDataService.cs +++ b/DeskHubSharpRevised/DAL/JsonDataService.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json; namespace DeskHubSharpRevised.DAL; -public class JsonDataService +public class JsonDataService : IDataService { private string _dataConfig; @@ -67,4 +67,19 @@ public class JsonDataService { _dataConfig = dataFile; } + + public void SearchRequest() + { + throw new NotImplementedException(); + } + + public void UserRequest() + { + throw new NotImplementedException(); + } + + public void BranchRequest() + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/DeskHubSharpRevised/ViewModels/SearchWindowViewModel.cs b/DeskHubSharpRevised/ViewModels/SearchWindowViewModel.cs new file mode 100644 index 0000000..7da889c --- /dev/null +++ b/DeskHubSharpRevised/ViewModels/SearchWindowViewModel.cs @@ -0,0 +1,6 @@ +namespace DeskHubSharpRevised; + +public class SearchWindowViewModel +{ + +} \ No newline at end of file