basic working prototype
This commit is contained in:
parent
d22afb8d4e
commit
432e0939b1
@ -1,9 +1,9 @@
|
||||
using BinaryDad.AacpsBusAlert;
|
||||
using BinaryDad.AacpsBusAlert.Services;
|
||||
using BinaryDad.Extensions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
var host = Host.CreateDefaultBuilder(args)
|
||||
@ -16,16 +16,16 @@ var host = Host.CreateDefaultBuilder(args)
|
||||
builder.AddJsonFile("appsettings.json");
|
||||
builder.AddJsonFile($"appsettings.{env}.json", true);
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddTransient<BusRouteService>();
|
||||
services.AddHttpClient();
|
||||
|
||||
services.Configure<List<User>>(context.Configuration.GetSection("Users"));
|
||||
})
|
||||
.Build();
|
||||
|
||||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
|
||||
var configuration = host.Services.GetService<IConfiguration>();
|
||||
|
||||
var httpClientFactory = host.Services.GetService<IHttpClientFactory>();
|
||||
var httpClient = httpClientFactory.CreateClient();
|
||||
|
||||
@ -33,10 +33,28 @@ var apiBaseUrl = configuration["Urls:Api"];
|
||||
var apiBusRouteUrl = UrlUtility.Combine(apiBaseUrl, "api/routes");
|
||||
var busRoutesRaw = await httpClient.GetStringAsync(apiBusRouteUrl);
|
||||
|
||||
var userRoutes = host.Services.GetService<IOptions<List<User>>>();
|
||||
|
||||
var busRoutes = JsonConvert.DeserializeObject<ICollection<BusRoute>>(busRoutesRaw);
|
||||
|
||||
var busRouteService = host.Services.GetService<BusRouteService>();
|
||||
foreach (var userRoute in userRoutes.Value)
|
||||
{
|
||||
var matchedRoutes = busRoutes
|
||||
.Join(userRoute.Routes, b => b.BusNumber, u => u.BusNumber, (b, u) => new
|
||||
{
|
||||
UserRoute = u,
|
||||
BusRoute = b
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var routes = await busRouteService.GetBusRoutesAsync();
|
||||
// send alert for these buses
|
||||
|
||||
Console.WriteLine($"User {userRoute.Email} has {matchedRoutes.Count} delays:");
|
||||
|
||||
foreach (var matchedRoute in matchedRoutes)
|
||||
{
|
||||
Console.WriteLine($" {matchedRoute.BusRoute.BusNumber} ({matchedRoute.UserRoute.Label}): {matchedRoute.BusRoute.Impact} for {matchedRoute.BusRoute.Schedules}");
|
||||
}
|
||||
}
|
||||
|
||||
Console.ReadLine();
|
@ -1,3 +1,25 @@
|
||||
{
|
||||
|
||||
"Users": [
|
||||
{
|
||||
"Id": "b43f4f45-0f7b-4976-849d-8ad4b271199c",
|
||||
"Email": "ryan@binarydad.com",
|
||||
"Routes": [
|
||||
{
|
||||
"Id": "bfed1017-be53-42f9-bb46-ddbf27d4270f",
|
||||
"BusNumber": 203,
|
||||
"Label": "Cam's bus'"
|
||||
},
|
||||
{
|
||||
"Id": "bfed1017-be53-42f9-bb46-ddbf27d4270f",
|
||||
"BusNumber": 117,
|
||||
"Label": "Test bus"
|
||||
},
|
||||
{
|
||||
"Id": "bfed1017-be53-42f9-bb46-ddbf27d4270f",
|
||||
"BusNumber": 238,
|
||||
"Label": "Yet another test bus"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user