Add Update route controller to fetch charts and adapt model to allow for response parsing

This commit is contained in:
Luke Else 2022-02-09 20:19:32 +00:00
parent 21aff4096f
commit b6e5f09c11
2 changed files with 46 additions and 15 deletions

View File

@ -75,21 +75,7 @@ namespace EFB.Controllers
//Make initial Route Request
var requestRoute = API.Post<string>("https://api.autorouter.aero/v1.0/router", headerData, content);
//Prepare data to be send off with request(charts)
headerData = new Dictionary<string, string>();
headerData.Add("referer", "luke-else.co.uk");
Dictionary<string, string> formData = new Dictionary<string, string>();
formData.Add("token", "");
var body = new FormUrlEncodedContent(formData);
//make Charts request
var requestDepartureCharts = API.Post<ChartResponse>($"https://chartfox.org/api/charts/grouped/{departure}", headerData, body);
var requestArrivalCharts = API.Post<ChartResponse>($"https://chartfox.org/api/charts/grouped/{arrival}", headerData, body);
ResponseModel<string> responseRoute = await requestRoute;
ResponseModel<ChartResponse> responseDepartureCharts = await requestDepartureCharts;
ResponseModel<ChartResponse> responseArrivalCharts = await requestArrivalCharts;
if (responseRoute.Error == null)
{//Update User session and add route ID
@ -137,8 +123,25 @@ namespace EFB.Controllers
string routeString = "";
APIInterface API = new APIInterface();
Dictionary<string, string> headerData = new Dictionary<string, string>();
/*-----Chart Fetching Operations--------*/
//Prepare data to be send off with request(charts)
headerData = new Dictionary<string, string>();
headerData.Add("referer", "luke-else.co.uk");
Dictionary<string, string> formData = new Dictionary<string, string>();
formData.Add("token", "");
var body = new FormUrlEncodedContent(formData);
//make Charts request
var requestDepartureCharts = API.Post<ChartResponse>($"https://chartfox.org/api/charts/grouped/{departure}", headerData, body);
var requestArrivalCharts = API.Post<ChartResponse>($"https://chartfox.org/api/charts/grouped/{arrival}", headerData, body);
/*----------------------------------*/
//Run route Polling
headerData.Add("Authorization", $"Bearer {user.UserToken.TokenValue}");
while (collected == false && pollCount < 15)
@ -165,6 +168,13 @@ namespace EFB.Controllers
if (collected)
{
//Get Response from Charts
ResponseModel<ChartResponse> responseDepartureCharts = await requestDepartureCharts;
user.DepartureCharts = new ChartModel(responseDepartureCharts.Result.Response);
ResponseModel<ChartResponse> responseArrivalCharts = await requestArrivalCharts;
user.ArrivalCharts = new ChartModel(responseArrivalCharts.Result.Response);
//fill in route
string finalRoute = RouteModel.ParseRoute(routeString);
user.Route = finalRoute;

View File

@ -16,6 +16,26 @@ namespace EFB.Models
public Chart[] Approach { get; set; }
public Chart[] Transition { get; set; }
public Chart[] PilotBriefing { get; set; }
public ChartModel(ChartList response)
{
General = FillChart(response.General);
TextualData = FillChart(response.TextualData);
GroundLayout = FillChart(response.GroundLayout);
SID = FillChart(response.SID);
STAR = FillChart(response.STAR);
Approach = FillChart(response.Approach);
Transition = FillChart(response.Transition);
PilotBriefing = FillChart(response.PilotBriefing);
}
private Chart[] FillChart(ChartsCollection collection){
if (collection != null)
{
return collection.Charts;
}
return new Chart[]{};
}
}
public class Pinned
@ -33,4 +53,5 @@ namespace EFB.Models
// public string PseudoURL { get; set; }
// public string URL { get; set; }
// }
}