mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
migrate forecasts sample to filterlists api controller
This commit is contained in:
parent
b7e493ce8e
commit
d7e5dfd16c
3 changed files with 30 additions and 39 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue