using PartSource.Entities.Models; using PartSource.Services; using System.Web.Http; namespace PartSource.Controllers { [RoutePrefix("stores")] public class StoresController : ApiController { private const int Count = 5; private const int Page = 1; private readonly LocationService _service; public StoresController(LocationService service) { this._service = service; } [HttpGet] [Route("nearest/{postal}")] [Route("nearest/{postal}/count/{count}")] [Route("nearest/{postal}/count/{count}/page/{page}")] public IHttpActionResult GetNearestStores(string postal, int count = 5, int page = 1) { PostalCode postalCodeData = this._service.GetPostalCodeData(postal); if (postalCodeData == null) return (IHttpActionResult)this.BadRequest("Invalid postal code"); return (IHttpActionResult)this.Ok(new { Data = this._service.GetClosestLocations(postalCodeData, count, page) }); } [HttpGet] [Route("nearest/{postal}/radius/{radius}")] [Route("nearest/{postal}/radius/{radius}/count/{count}")] [Route("nearest/{postal}/radius/{radius}/count/{count}/page/{page}")] public IHttpActionResult GetNearestStores(string postal, double radius, int count = 5, int page = 1) { return (IHttpActionResult)this.Ok(new { Data = this._service.GetClosestLocations(this._service.GetPostalCodeData(postal), count, page, radius) }); } } }