diff --git a/src/FilterLists.Api/Controllers/ListsController.cs b/src/FilterLists.Api/Controllers/ListsController.cs index e81b2c09d..bdf9694ed 100644 --- a/src/FilterLists.Api/Controllers/ListsController.cs +++ b/src/FilterLists.Api/Controllers/ListsController.cs @@ -1,4 +1,7 @@ -using FilterLists.Services.Contracts; +using System; +using System.Collections.Generic; +using System.Linq; +using FilterLists.Services.Contracts; using Microsoft.AspNetCore.Mvc; namespace FilterLists.Api.Controllers @@ -7,6 +10,11 @@ namespace FilterLists.Api.Controllers [Produces("application/json")] public class ListsController : Controller { + private static readonly string[] Summaries = + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + private readonly IFilterListService filterListService; public ListsController(IFilterListService filterListService) @@ -19,5 +27,25 @@ public IActionResult Get() { return Json(filterListService.GetAll()); } + + [HttpGet("[action]")] + public IEnumerable WeatherForecasts() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + DateFormatted = DateTime.Now.AddDays(index).ToString("d"), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }); + } + + public class WeatherForecast + { + public string DateFormatted { get; set; } + public int TemperatureC { get; set; } + public string Summary { get; set; } + public int TemperatureF => 32 + (int) (TemperatureC / 0.5556); + } } } \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/components/Home.tsx b/src/FilterLists.Web/ClientApp/components/Home.tsx index ca45e6978..668a4a44e 100644 --- a/src/FilterLists.Web/ClientApp/components/Home.tsx +++ b/src/FilterLists.Web/ClientApp/components/Home.tsx @@ -12,7 +12,7 @@ export class Home extends React.Component, IFetchDataExa super(); this.state = { forecasts: [], loading: true }; - fetch("api/SampleData/WeatherForecasts") + fetch("https://api.filterlists.com/v1/lists/WeatherForecasts") .then(response => response.json() as Promise) .then(data => { this.setState({ forecasts: data, loading: false }); diff --git a/src/FilterLists.Web/Controllers/SampleDataController.cs b/src/FilterLists.Web/Controllers/SampleDataController.cs deleted file mode 100644 index 24b6de753..000000000 --- a/src/FilterLists.Web/Controllers/SampleDataController.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Mvc; - -namespace FilterLists.Web.Controllers -{ - [Route("api/[controller]")] - public class SampleDataController : Controller - { - private static readonly string[] Summaries = - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - [HttpGet("[action]")] - public IEnumerable WeatherForecasts() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - DateFormatted = DateTime.Now.AddDays(index).ToString("d"), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }); - } - - public class WeatherForecast - { - public string DateFormatted { get; set; } - public int TemperatureC { get; set; } - public string Summary { get; set; } - - public int TemperatureF => 32 + (int) (TemperatureC / 0.5556); - } - } -} \ No newline at end of file