Skip to content

Commit

Permalink
Adding Map View (Azure-Samples#210)
Browse files Browse the repository at this point in the history
* Adding Map View
* Bing Maps Key moved to ENV Variable
* update helm -deployment and values yaml
  • Loading branch information
BSamodien authored and dtzar committed Sep 17, 2018
1 parent b2862e4 commit 884d871
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 180 deletions.
4 changes: 3 additions & 1 deletion tripviewer/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ spec:
protocol: TCP
env:
- name: TEAM_API_ENDPOINT
value: "http://{{ .Values.ingress.rules.endpoint.host }}"
value: "http://{{ .Values.ingress.rules.endpoint.host }}"
- name: BING_MAPS_KEY
value: "{{ .Values.viewer.mapkey}}"
4 changes: 3 additions & 1 deletion tripviewer/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ ingress:
paths:
- path: /
- path: /UserProfile
- path: /Trips
- path: /Trips
viewer:
mapkey: Ar6iuHZYgX1BrfJs6SRJaXWbpU_HKdoe7G-OO9b2kl3rWvcawYx235GGx5FPM76O
50 changes: 49 additions & 1 deletion tripviewer/web/Controllers/TripController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,63 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Simulator.DataObjects;
using Simulator.DataStore.Stores;
using TripViewer.Utility;


namespace TripViewer.Controllers
{
public class TripController : Controller
{
private readonly TripViewerConfiguration _envvars;

public TripController(IOptions<TripViewerConfiguration> EnvVars)
{
_envvars = EnvVars.Value ?? throw new ArgumentNullException(nameof(EnvVars));
}
[HttpGet]
public IActionResult Index()
{
return View();
var teamendpoint = _envvars.TEAM_API_ENDPOINT;
var bingMapsKey = _envvars.BING_MAPS_KEY;

//Get trips
TripStore t = new TripStore(teamendpoint);
List<Trip> trips = t.GetItemsAsync().Result;
//Get Last Trip
var last = trips.Max(trip => trip.RecordedTimeStamp);
var tlast = from Trip latest in trips
where latest.RecordedTimeStamp == last
select latest;
//Get TripPoints
TripPointStore tps = new TripPointStore(teamendpoint);
List<TripPoint> tripPoints = tps.GetItemsAsync(tlast.First()).Result;

ViewData["MapKey"] = bingMapsKey;
return View(tripPoints);
}

public PartialViewResult RenderMap()
{
var teamendpoint = _envvars.TEAM_API_ENDPOINT;
//Get trips
TripStore t = new TripStore(teamendpoint);
List<Trip> trips = t.GetItemsAsync().Result;
//Get Last Trip
var last = trips.Max(trip => trip.RecordedTimeStamp);
var tlast = from Trip latest in trips
where latest.RecordedTimeStamp == last
select latest;
//Get TripPoints
TripPointStore tps = new TripPointStore(teamendpoint);
List<TripPoint> tripPoints = tps.GetItemsAsync(tlast.First()).Result;


return PartialView(tripPoints);
}
}
}
2 changes: 1 addition & 1 deletion tripviewer/web/Models/Stores/TripPointStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Net.Http;
using System.Threading.Tasks;

public class TripPointStore : BaseStore, IBaseStore<TripPoint>
public class TripPointStore : BaseStore//, IBaseStore<TripPoint>
{

public TripPointStore(string EndPoint)
Expand Down
31 changes: 2 additions & 29 deletions tripviewer/web/Models/Stores/TripStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Net.Http;
using System.Threading.Tasks;

public class TripStore : BaseStore, IBaseStore<Trip>
public class TripStore : BaseStore//, IBaseStore<Trip>
{
public TripStore(string EndPoint)
{
Expand Down Expand Up @@ -36,34 +36,7 @@ public async Task<List<Trip>> GetItemsAsync()
return trips;
}

public async Task<Trip> CreateItemAsync(Trip item)
{
HttpResponseMessage response = await Client.PostAsJsonAsync<Trip>("api/trips", item);
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
response.Content.Headers.ContentType.MediaType = "application/json";
item = await response.Content.ReadAsAsync<Trip>();
}
return item;
}


public async Task<bool> UpdateItemAsync(Trip item)
{
HttpResponseMessage response = await Client.PatchAsJsonAsync($"api/trips/{item.Id}", item);
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
response.Content.Headers.ContentType.MediaType = "application/json";
return true;
}

public async Task<bool> DeleteItemAsync(Trip item)
{
HttpResponseMessage response = await Client.DeleteAsync($"api/trips/{item.Id}");
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
response.Content.Headers.ContentType.MediaType = "application/json";
return true;
}
}
}
30 changes: 1 addition & 29 deletions tripviewer/web/Models/Stores/UserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,6 @@ public async Task<List<User>> GetItemsAsync()
return users;
}

//public async Task<User> CreateItemAsync(User item)
//{
// HttpResponseMessage response = await Client.PostAsJsonAsync<User>("api/user-java", item);
// response.EnsureSuccessStatusCode();
// if (response.IsSuccessStatusCode)
// {
// response.Content.Headers.ContentType.MediaType = "application/json";
// item = await response.Content.ReadAsAsync<User>();
// }
// return item;
//}

//public async Task<bool> UpdateItemAsync(User item)
//{
// HttpResponseMessage response = await Client.PatchAsJsonAsync($"api/user-java/{item.UserId}", item);
// response.EnsureSuccessStatusCode();
// if (response.IsSuccessStatusCode)
// response.Content.Headers.ContentType.MediaType = "application/json";
// return true;
//}

//public async Task<bool> DeleteItemAsync(User item)
//{
// HttpResponseMessage response = await Client.DeleteAsync($"api/user-java/{item.UserId}");
// response.EnsureSuccessStatusCode();
// if (response.IsSuccessStatusCode)
// response.Content.Headers.ContentType.MediaType = "application/json";
// return true;
//}

}
}
2 changes: 0 additions & 2 deletions tripviewer/web/TripViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
<ItemGroup>
<Compile Remove="Models\Stores\IBaseStore.cs" />
<Compile Remove="Models\Stores\PoiStore.cs" />
<Compile Remove="Models\Stores\TripPointStore.cs" />
<Compile Remove="Models\Stores\TripStore.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tripviewer/web/Utility/TripViewerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ namespace TripViewer.Utility
public class TripViewerConfiguration
{
public string TEAM_API_ENDPOINT { get; set; }

public string BING_MAPS_KEY { get;set; }
}
}
Loading

0 comments on commit 884d871

Please sign in to comment.