diff --git a/PizzaExpress/Controllers/IngredientiController.cs b/PizzaExpress/Controllers/IngredientiController.cs new file mode 100644 index 0000000..2dfe90f --- /dev/null +++ b/PizzaExpress/Controllers/IngredientiController.cs @@ -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 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" + }); + } + } +} diff --git a/PizzaExpress/Program.cs b/PizzaExpress/Program.cs index 03e1f19..a310122 100644 --- a/PizzaExpress/Program.cs +++ b/PizzaExpress/Program.cs @@ -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(opt => opt.UseSqlite("Data Source=pizza.db")); + builder.Services.AddHttpClient(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle