add api controller, add basic UI with hard-coded bus numbers
This commit is contained in:
parent
178c171e98
commit
2944f036ca
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@ -6,4 +6,13 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BinaryDad.Extensions" Version="21.4.20.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BinaryDad.AacpsBusAlert.Services\BinaryDad.AacpsBusAlert.Services.csproj" />
|
||||
<ProjectReference Include="..\BinaryDad.AacpsBusAlert\BinaryDad.AacpsBusAlert.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
22
BinaryDad.AacpsBusAlert.Web/Controllers/ApiController.cs
Normal file
22
BinaryDad.AacpsBusAlert.Web/Controllers/ApiController.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using BinaryDad.AacpsBusAlert.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BinaryDad.AacpsBusAlert.Web.Controllers
|
||||
{
|
||||
[Route("api")]
|
||||
public class ApiController : Controller
|
||||
{
|
||||
private readonly BusRouteService busRouteService;
|
||||
|
||||
public ApiController(BusRouteService busRouteService)
|
||||
{
|
||||
this.busRouteService = busRouteService;
|
||||
}
|
||||
|
||||
[Route("routes")]
|
||||
public Task<ICollection<BusRoute>> GetBusRoutesAsync()
|
||||
{
|
||||
return busRouteService.GetBusRoutesAsync();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using BinaryDad.AacpsBusAlert.Web.Models;
|
||||
using BinaryDad.AacpsBusAlert.Services;
|
||||
using BinaryDad.AacpsBusAlert.Web.Models;
|
||||
using BinaryDad.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
|
||||
@ -6,16 +8,25 @@ namespace BinaryDad.AacpsBusAlert.Web.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly ILogger<HomeController> logger;
|
||||
private readonly BusRouteService busRouteService;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
public HomeController(ILogger<HomeController> logger, BusRouteService busRouteService)
|
||||
{
|
||||
_logger = logger;
|
||||
this.logger = logger;
|
||||
this.busRouteService = busRouteService;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
return View();
|
||||
var userRoutes = new[] { 203, 365, 277, 269, 274 };
|
||||
|
||||
//var busRoutes = await CacheHelper.GetAsync("BusRoutes", () => busRouteService.GetBusRoutesAsync());
|
||||
var busRoutes = await busRouteService.GetBusRoutesAsync();
|
||||
|
||||
var matchedBusRoutes = busRoutes.Join(userRoutes, r => r.BusNumber, u => u, (r, u) => r).ToList();
|
||||
|
||||
return View(matchedBusRoutes);
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
|
@ -1,7 +1,10 @@
|
||||
using BinaryDad.AacpsBusAlert.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddTransient<BusRouteService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
@ -1,8 +1,16 @@
|
||||
@{
|
||||
@model ICollection<BusRoute>
|
||||
@{
|
||||
|
||||
ViewData["Title"] = "Home Page";
|
||||
|
||||
var busRoutes = Model.OrderBy(r => r.BusNumber);
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||
</div>
|
||||
@foreach (var busRoute in busRoutes)
|
||||
{
|
||||
<div>
|
||||
<h3>@busRoute.BusNumber - @busRoute.Schools</h3>
|
||||
<p>@busRoute.Impact</p>
|
||||
<p>@busRoute.Schedules</p>
|
||||
</div>
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
@using BinaryDad.AacpsBusAlert.Web
|
||||
@using BinaryDad.AacpsBusAlert
|
||||
@using BinaryDad.AacpsBusAlert.Web
|
||||
@using BinaryDad.AacpsBusAlert.Web.Models
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
Loading…
x
Reference in New Issue
Block a user