using Microsoft.AspNetCore.Mvc;
using BoredCareers.Services.DatabaseService;
using BoredCareers.Entities;

namespace BoredCareers.Controllers {
    [ApiController]
    [Route("api/location")]
    public class LocationController : MistoxControllerBase {

        public LocationController(DatabaseService db) : base(db) {}

        [HttpGet]
        public async Task<IActionResult> GetCompany(string PostalCode, string CountryCode, float MaxDistanceKm) {
            if (isLoggedIn()) {
                Location[] places = await _databaseService.GetNearbyLocations(PostalCode, CountryCode, MaxDistanceKm);
                return Ok(places.ToArray());
            }
            return NotFound("Not logged in");
        }

    }
}
