implemented interface, cleaned up ApiDataService

This commit is contained in:
Wyatt J. Miller 2022-06-30 17:44:06 -04:00
parent 9e900f983c
commit d2f735b2ef
3 changed files with 33 additions and 38 deletions

View File

@ -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<ObservableCollection<RepoDetail>>(x);
if (deserialized.Count == 0)
{
throw new Exception();
}
else
{
RequestList.repoDetail = deserialized;
}
string? response = client.Execute(requestRepo).Content;
RequestList.repoDetail = JsonConvert.DeserializeObject<ObservableCollection<RepoDetail>>(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<User>(x);
if (deserailized == null)
{
throw new Exception();
}
else
{
RequestList.userDetail = deserailized;
}
string? response = client.Execute(requestUser).Content;
RequestList.userDetail = JsonConvert.DeserializeObject<User>(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<ObservableCollection<Branch>>(x);
RequestList.branchDetail = deserailized;
string? response = client.Execute(requestUser).Content;
RequestList.branchDetail = JsonConvert.DeserializeObject<ObservableCollection<Branch>>(response);
}
catch (NullReferenceException)
{

View File

@ -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();
}
}

View File

@ -0,0 +1,6 @@
namespace DeskHubSharpRevised;
public class SearchWindowViewModel
{
}