diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-05-26 10:48:43 +0200 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-05-26 10:48:43 +0200 |
| commit | 5ced7f916d94e86e9a7ec164bee56f9a8e3a2a3a (patch) | |
| tree | b1ef5afa17b4a2f9fb2cbd683afc2fb6d905b5e1 /src/Costasdev.Busurbano.Backend/GetStopEstimates.cs | |
| parent | 4637373b50636e78dc2c7b6f99be879edb4ff7dc (diff) | |
Replace Azure SWA with custom server
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/GetStopEstimates.cs')
| -rw-r--r-- | src/Costasdev.Busurbano.Backend/GetStopEstimates.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Costasdev.Busurbano.Backend/GetStopEstimates.cs b/src/Costasdev.Busurbano.Backend/GetStopEstimates.cs new file mode 100644 index 0000000..7fe77e1 --- /dev/null +++ b/src/Costasdev.Busurbano.Backend/GetStopEstimates.cs @@ -0,0 +1,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 new BadRequestObjectResult("Please provide a stop id"); + } + + var argumentNumber = int.TryParse(requestedStopIdString, out var requestedStopId); + if (!argumentNumber) + { + return new BadRequestObjectResult("Please provide a valid stop id"); + } + + try + { + var estimates = await _api.GetStopEstimates(requestedStopId); + return new OkObjectResult(estimates); + } + catch (InvalidOperationException) + { + return new BadRequestObjectResult("Stop not found"); + } + } +} + |
