better ui
This commit is contained in:
1 parent
e0b0ca48f2
commit
84abee712d
6 files changed
+66
-17
No files matched your search
@@ -17,9 +17,16 @@ public class ApiController: Controller
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public JsonResult Roads(string city, int year=2025)
|
||||
public ActionResult Roads(string city, string date="")
|
||||
{
|
||||
return Json(_dataService.GetRoads(city, year));
|
||||
var extractDate = Util.ParseDateOnly(date);
|
||||
if (!extractDate.HasValue)
|
||||
{
|
||||
return BadRequest($"Cannot parse provided date {date}. The date must be in the format yyyy-MM-dd.");
|
||||
}
|
||||
return Json(_dataService.GetRoads(city, extractDate.Value));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using YongeStreet.Services;
|
||||
|
||||
namespace YongeStreet.Controllers;
|
||||
|
||||
public record CityModel(string City, IList<CityRoadLengthStats> CityRoadLengthStats);
|
||||
public record CityModel(string City, IList<CityRoadLengthStats> CityRoadLengthStats, DateOnly Date);
|
||||
|
||||
public record IndexModel(IList<CityOverview> Cities);
|
||||
|
||||
@@ -20,10 +20,11 @@ public class HomeController : Controller
|
||||
_dataService = dataService;
|
||||
}
|
||||
|
||||
public IActionResult City(string city)
|
||||
public IActionResult City(string city, string date)
|
||||
{
|
||||
var cityRoadLengthStats = _dataService.GetCityRoadLengthStats(city);
|
||||
return View(new CityModel(city, cityRoadLengthStats));
|
||||
var parsedDate = Util.ParseDateOnly(date) ?? new DateOnly(2025, 1, 1);
|
||||
return View(new CityModel(city, cityRoadLengthStats, parsedDate ));
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace YongeStreet.Controllers;
|
||||
|
||||
public static class Util
|
||||
{
|
||||
public static DateOnly? ParseDateOnly(string? date)
|
||||
{
|
||||
if (string.IsNullOrEmpty(date))
|
||||
{
|
||||
return new DateOnly(2025, 1, 1);
|
||||
}
|
||||
try
|
||||
{
|
||||
return DateOnly.ParseExact(date, "yyyy-MM-dd");
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user