blob: 7d4a5e81d1b940ca34766ab548cd5e74457e79af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
using Microsoft.AspNetCore.Mvc;
using Costasdev.VigoTransitApi;
namespace Costasdev.Busurbano.Backend;
[ApiController]
[Route("api")]
public class ApiController : ControllerBase
{
private readonly VigoTransitApiClient _api;
public ApiController(HttpClient http)
{
_api = new VigoTransitApiClient(http);
}
[HttpGet("GetStopEstimates")]
public async Task<IActionResult> Run()
{
var argumentAvailable = Request.Query.TryGetValue("id", out var requestedStopIdString);
if (!argumentAvailable)
{
return BadRequest("Please provide a stop id as a query parameter with the name 'id'.");
}
var argumentNumber = int.TryParse(requestedStopIdString, out var requestedStopId);
if (!argumentNumber)
{
return BadRequest("The provided stop id is not a valid number.");
}
try
{
var estimates = await _api.GetStopEstimates(requestedStopId);
return new OkObjectResult(estimates);
}
catch (InvalidOperationException)
{
return new BadRequestObjectResult("Stop not found");
}
}
}
|