Initial commit

This commit is contained in:
2020-04-12 20:52:03 -04:00
parent e750d2848a
commit 01e7627293
249 changed files with 9733 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
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)
});
}
}
}