Aggiunto controller Ingredienti
This commit is contained in:
33
PizzaExpress/Controllers/IngredientiController.cs
Normal file
33
PizzaExpress/Controllers/IngredientiController.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PizzaExpress.API;
|
||||
|
||||
namespace PizzaExpress.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/ingredienti")]
|
||||
public class IngredientiController : ControllerBase
|
||||
{
|
||||
private readonly SpoonacularApi _spoonacularApi;
|
||||
|
||||
public IngredientiController(SpoonacularApi spoonacularApi)
|
||||
{
|
||||
this._spoonacularApi = spoonacularApi;
|
||||
}
|
||||
|
||||
[HttpGet("da-pizza")]
|
||||
public async Task<IActionResult> GetIngredientiDaPizza([FromQuery] string nome)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(nome))
|
||||
return BadRequest("Nome pizza mancante");
|
||||
|
||||
var ingredienti = await _spoonacularApi.GetIngredientiDaPizzaAsync(nome);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
pizza = nome,
|
||||
ingredienti = ingredienti,
|
||||
fonte = "Spoonacular"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PizzaExpress.Data;
|
||||
using PizzaExpress.API;
|
||||
|
||||
namespace PizzaExpress
|
||||
{
|
||||
@@ -33,6 +34,7 @@ namespace PizzaExpress
|
||||
// Creazione del contesto con DB SQLite
|
||||
builder.Services.AddDbContext<PizzaContext>(opt =>
|
||||
opt.UseSqlite("Data Source=pizza.db"));
|
||||
builder.Services.AddHttpClient<SpoonacularApi>();
|
||||
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
||||
Reference in New Issue
Block a user