implemented interface, cleaned up ApiDataService
This commit is contained in:
parent
9e900f983c
commit
d2f735b2ef
@ -8,7 +8,7 @@ using RestSharp;
|
|||||||
|
|
||||||
namespace DeskHubSharpRevised.DAL;
|
namespace DeskHubSharpRevised.DAL;
|
||||||
|
|
||||||
public class ApiDataService
|
public class ApiDataService : IDataService
|
||||||
{
|
{
|
||||||
private string _apiEndpoint;
|
private string _apiEndpoint;
|
||||||
private string _query;
|
private string _query;
|
||||||
@ -33,23 +33,13 @@ public class ApiDataService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var client = new RestClient(_apiEndpoint);
|
RestClient client = new RestClient(_apiEndpoint);
|
||||||
RestRequest requestRepo = new RestRequest($"users/{_query}/repos", Method.Get);
|
RestRequest requestRepo = new RestRequest($"users/{_query}/repos", Method.Get);
|
||||||
|
|
||||||
var response = client.Execute(requestRepo);
|
string? response = client.Execute(requestRepo).Content;
|
||||||
var x = response.Content;
|
RequestList.repoDetail = JsonConvert.DeserializeObject<ObservableCollection<RepoDetail>>(response);
|
||||||
var deserialized = JsonConvert.DeserializeObject<ObservableCollection<RepoDetail>>(x);
|
|
||||||
|
|
||||||
if (deserialized.Count == 0)
|
|
||||||
{
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RequestList.repoDetail = deserialized;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
ErrorWindow err = new ErrorWindow();
|
ErrorWindow err = new ErrorWindow();
|
||||||
err.txtblk_error.Text = "We couldn't gather repository data. Please try again";
|
err.txtblk_error.Text = "We couldn't gather repository data. Please try again";
|
||||||
@ -64,23 +54,11 @@ public class ApiDataService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var client = new RestClient(_apiEndpoint);
|
RestClient client = new RestClient(_apiEndpoint);
|
||||||
|
|
||||||
RestRequest requestUser = new RestRequest($"users/{_query}", Method.Get);
|
RestRequest requestUser = new RestRequest($"users/{_query}", Method.Get);
|
||||||
|
|
||||||
var response = client.Execute(requestUser);
|
string? response = client.Execute(requestUser).Content;
|
||||||
string x = response.Content;
|
RequestList.userDetail = JsonConvert.DeserializeObject<User>(response);
|
||||||
var deserailized = JsonConvert.DeserializeObject<User>(x);
|
|
||||||
|
|
||||||
if (deserailized == null)
|
|
||||||
{
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RequestList.userDetail = deserailized;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
@ -97,15 +75,11 @@ public class ApiDataService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var client = new RestClient(_apiEndpoint);
|
RestClient client = new RestClient(_apiEndpoint);
|
||||||
|
|
||||||
RestRequest requestUser = new RestRequest($"/repos/{RequestList.userDetail.login}/{_query}/branches", Method.Get);
|
RestRequest requestUser = new RestRequest($"/repos/{RequestList.userDetail.login}/{_query}/branches", Method.Get);
|
||||||
|
|
||||||
var response = client.Execute(requestUser);
|
string? response = client.Execute(requestUser).Content;
|
||||||
string x = response.Content;
|
RequestList.branchDetail = JsonConvert.DeserializeObject<ObservableCollection<Branch>>(response);
|
||||||
var deserailized = JsonConvert.DeserializeObject<ObservableCollection<Branch>>(x);
|
|
||||||
|
|
||||||
RequestList.branchDetail = deserailized;
|
|
||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@ using Newtonsoft.Json;
|
|||||||
|
|
||||||
namespace DeskHubSharpRevised.DAL;
|
namespace DeskHubSharpRevised.DAL;
|
||||||
|
|
||||||
public class JsonDataService
|
public class JsonDataService : IDataService
|
||||||
{
|
{
|
||||||
private string _dataConfig;
|
private string _dataConfig;
|
||||||
|
|
||||||
@ -67,4 +67,19 @@ public class JsonDataService
|
|||||||
{
|
{
|
||||||
_dataConfig = dataFile;
|
_dataConfig = dataFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SearchRequest()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UserRequest()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BranchRequest()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
6
DeskHubSharpRevised/ViewModels/SearchWindowViewModel.cs
Normal file
6
DeskHubSharpRevised/ViewModels/SearchWindowViewModel.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace DeskHubSharpRevised;
|
||||||
|
|
||||||
|
public class SearchWindowViewModel
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user