migrate forecasts sample to filterlists api controller

This commit is contained in:
Collin M. Barrett 2017-10-29 14:11:59 -05:00
parent b7e493ce8e
commit d7e5dfd16c
3 changed files with 30 additions and 39 deletions

View file

@ -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<WeatherForecast> 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);
}
}
}

View file

@ -12,7 +12,7 @@ export class Home extends React.Component<RouteComponentProps<{}>, 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<IWeatherForecast[]>)
.then(data => {
this.setState({ forecasts: data, loading: false });

View file

@ -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<WeatherForecast> 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);
}
}
}