Aggiunto controller Ingredienti

This commit is contained in:
2026-02-26 09:20:44 +01:00
parent cb5bfa94f9
commit b28c9cbb85
2 changed files with 35 additions and 0 deletions

View 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"
});
}
}
}

View File

@@ -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