35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
![]() |
using Microsoft.AspNetCore.Mvc;
|
|||
|
using RestaurantAPI.Models;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
[Route("api/restaurants")]
|
|||
|
[ApiController]
|
|||
|
public class RestaurantController : ControllerBase
|
|||
|
{
|
|||
|
private readonly GooglePlacesService _googlePlacesService;
|
|||
|
|
|||
|
// Inject GooglePlacesService into the controller
|
|||
|
public RestaurantController(GooglePlacesService googlePlacesService)
|
|||
|
{
|
|||
|
_googlePlacesService = googlePlacesService;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Fetches restaurants from Google Places API based on location.
|
|||
|
/// </summary>
|
|||
|
/// <param name="latitude">Latitude of the location (default: Brickell, Miami)</param>
|
|||
|
/// <param name="longitude">Longitude of the location (default: Brickell, Miamik)</param>
|
|||
|
/// <param name="radius">Search radius in meters (default: 5000m)</param>
|
|||
|
/// <returns>List of restaurants from Google Places API</returns>
|
|||
|
[HttpGet]
|
|||
|
public async Task<ActionResult<IEnumerable<Restaurant>>> GetRestaurants(
|
|||
|
[FromQuery] double latitude = 25.7617,
|
|||
|
[FromQuery] double longitude = -80.1918,
|
|||
|
[FromQuery] int radius = 5000)
|
|||
|
{
|
|||
|
var restaurants = await _googlePlacesService.GetRestaurantsAsync(latitude, longitude, radius);
|
|||
|
return Ok(restaurants);
|
|||
|
}
|
|||
|
}
|