23 Commits
0.1.2 ... 1.0.1

Author SHA1 Message Date
b28c9cbb85 Aggiunto controller Ingredienti 2026-02-26 09:20:44 +01:00
cb5bfa94f9 Aggiunta classe SpoonacularApi 2026-02-26 09:08:08 +01:00
2912745a21 Fix appsettings JSON 2026-02-18 10:07:28 +01:00
69196518cf Aggiunto indirizzo di ascolto in appsettings predefinito (problemi di lettura da fixare) 2026-02-18 08:56:03 +01:00
5e0d1cce20 Cambio porta server Kestrel in configurazione debug HTTP a 5000 2026-02-05 09:16:15 +01:00
069b503339 Fix funzione PUT (modifica altri campi oltre al prezzo) 2026-02-05 08:54:38 +01:00
829cfeefcf Fix funzione get pizze per implementazione su client winforms vibecodato da Di Campi 2026-01-22 09:24:26 +01:00
1f95c0d0b6 Fix database d'esempio 2026-01-22 08:53:05 +01:00
94d1796213 Aggiornamento DB di esempio 2026-01-15 09:33:08 +01:00
9ebc82fe62 Aggiunta campi nel modello Pizza 2026-01-15 09:24:01 +01:00
f41b2ae005 Modifiche database di esempio per compatibilità 2025-12-04 09:23:17 +01:00
64fa9e1823 Aggiunta campo "Note" 2025-12-04 09:22:47 +01:00
cf175649a0 Passaggio a profilo HTTPS in ambiente dev 2025-12-04 09:22:00 +01:00
bc3a05ebf9 Merge del branch di implementazione SQLite
Reviewed-on: SmerdoRepository/PizzaExpress#1
2025-11-26 07:52:32 +00:00
e5a6e81881 Aggiunta database di esempio 2025-11-26 08:50:11 +01:00
c8e5c403fb Rimozione creazione entry automatica all'esecuzione (può creare problemi) 2025-11-26 08:47:00 +01:00
07044d6156 Aggiustamento ignore database in gitignore 2025-11-26 08:45:45 +01:00
366fad3241 Implementazione database SQLite in Program.cs 2025-11-26 08:38:11 +01:00
0eecf829e1 Aggiunta database a gitignore 2025-11-26 08:37:53 +01:00
e04b85fa30 Rimozione libreria InMemory e cambio versione libreria Sqlite 2025-11-26 08:24:00 +01:00
6dcdbea46b Replaced Microsoft.Data.Sqlite with Microsoft.EntityFrameworkCore.Sqlite 2025-11-26 08:19:54 +01:00
c69cc287b6 Aggiornamento librerie 2025-11-26 08:05:05 +01:00
d258ea4615 Installazione libreria SQLite 2025-11-26 08:03:47 +01:00
13 changed files with 138 additions and 22 deletions

1
.gitignore vendored
View File

@@ -54,3 +54,4 @@ TestResult.xml
nunit-*.xml
.vs/
pizza.db*

View File

@@ -0,0 +1,50 @@
namespace PizzaExpress.API
{
public class SpoonacularApi
{
private readonly HttpClient _httpClient;
private readonly string _apiKey;
public SpoonacularApi(HttpClient httpClient, IConfiguration configuration)
{
_httpClient = httpClient;
_apiKey = configuration["Spoonacular:ApiKey"];
}
public async Task<List<string>> GetIngredientiDaPizzaAsync(string nomePizza)
{
var searchUrl = $"https://api.spoonacular.com/recipes/complexSearch?query={Uri.EscapeDataString(nomePizza)}&language=it&number=1&apiKey={_apiKey}";
// Chiamata GET Ricerca
var searchResponse = await _httpClient.GetFromJsonAsync<SearchResponse>(searchUrl);
if (searchResponse == null || searchResponse.Results.Count == 0)
return new List<string>();
// Prendiamo l'ID della prima ricetta trovata
int recipeId = searchResponse.Results[0].Id;
// Query per ottenere gli ingredienti della ricetta
var ingredientiUrl = $"https://api.spoonacular.com/recipes/{recipeId}/ingredientWidget.json?language=it&apiKey={_apiKey}";
// Chiamata GET Ingredienti
var ingredientiResponse = await _httpClient.GetFromJsonAsync<IngredientiResponse>(ingredientiUrl);
return ingredientiResponse.Ingredients.Select(i => i.Name).ToList();
}
private class SearchResponse
{
public List<SearchResult> Results { get; set; } = new();
}
private class SearchResult
{
public int Id { get; set; }
}
private class IngredientiResponse
{
public List<Ingrediente> Ingredients { get; set; } = new();
}
private class Ingrediente
{
public string Name { get; set; } = "";
}
}
}

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

@@ -22,7 +22,8 @@ namespace PizzaExpress.Controllers
{
var list = await _ctx.Pizze.AsNoTracking().ToListAsync();
// wrapper come nell'esempio Java { "pizze": [...] }
return Ok(new { pizze = list });
//return Ok(new { pizze = list });
return Ok(list);
}
// GET: /api/pizze/{id} (JSON o XML in base all'header Accept)
@@ -46,13 +47,18 @@ namespace PizzaExpress.Controllers
return NoContent();
}
// PUT: /api/pizze/{id} Body: { "prezzo": 4.70 }
// PUT: /api/pizze/{id}
[HttpPut("{id:int}")]
public async Task<IActionResult> UpdatePrezzo(int id, [FromBody] PrezzoUpdate body)
public async Task<IActionResult> UpdatePizza(int id, [FromBody] Pizza body)
{
var pizza = await _ctx.Pizze.FindAsync(id);
if (pizza is null) return NotFound();
pizza.Nome = body.Nome;
pizza.Prezzo = body.Prezzo;
pizza.Categoria = body.Categoria;
pizza.Note = body.Note;
pizza.Tavolo = body.Tavolo;
pizza.Stato = body.Stato;
await _ctx.SaveChangesAsync();
return NoContent();
}

View File

@@ -18,14 +18,6 @@ namespace PizzaExpress.Data
public static void Initialize(PizzaContext ctx)
{
if (ctx.Pizze.Any()) return;
ctx.Pizze.AddRange(
new Pizza { Id = 1, Nome = "Margherita", Prezzo = 4.50m },
new Pizza { Id = 2, Nome = "Prosciutto", Prezzo = 5.00m },
new Pizza { Id = 3, Nome = "Capricciosa", Prezzo = 7.00m }
);
ctx.SaveChanges();
}
}
}

View File

@@ -5,5 +5,9 @@
public int Id { get; set; }
public string Nome { get; set; } = string.Empty;
public decimal Prezzo { get; set; }
public string Categoria { get; set; } = string.Empty;
public string Note { get; set; } = string.Empty;
public int Tavolo { get; set; }
public string Stato { get; set; } = string.Empty;
}
}

View File

@@ -9,9 +9,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.10" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.11" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
</ItemGroup>
<ItemGroup>

View File

@@ -6,4 +6,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using PizzaExpress.Data;
using PizzaExpress.API;
namespace PizzaExpress
{
@@ -30,9 +31,11 @@ namespace PizzaExpress
builder.Services.AddControllers()
.AddXmlSerializerFormatters();
// DB in memory perch<63> siamo froci
// Creazione del contesto con DB SQLite
builder.Services.AddDbContext<PizzaContext>(opt =>
opt.UseInMemoryDatabase("dbpizze"));
opt.UseSqlite("Data Source=pizza.db"));
builder.Services.AddHttpClient<SpoonacularApi>();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
@@ -40,9 +43,11 @@ namespace PizzaExpress
var app = builder.Build();
using (var porcoidddioooo = app.Services.CreateScope())
using (var scope = app.Services.CreateScope())
{
var ctx = porcoidddioooo.ServiceProvider.GetRequiredService<PizzaContext>();
var ctx = scope.ServiceProvider.GetRequiredService<PizzaContext>();
// Crea il DB e le tabelle basate sul modello se non esistono (no migrations)
ctx.Database.EnsureCreated();
SeedData.Initialize(ctx);
}
@@ -56,6 +61,8 @@ namespace PizzaExpress
app.MapControllers();
app.Run();
}
}

View File

@@ -8,7 +8,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5011"
"applicationUrl": "http://localhost:5000"
},
"https": {
"commandName": "Project",
@@ -18,7 +18,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7297;http://localhost:5011"
"applicationUrl": "https://localhost:5001"
},
"IIS Express": {
"commandName": "IISExpress",

View File

@@ -10,5 +10,15 @@
"http://127.0.0.1:5500",
"http://localhost:5500"
]
},
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
}
}
},
"Spoonacular": {
"ApiKey": "YOUR_SPOONACULAR_API_KEY"
}
}

View File

@@ -11,5 +11,15 @@
"http://localhost:5500"
]
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:5000"
}
}
},
"Spoonacular": {
"ApiKey": "YOUR_SPOONACULAR_API_KEY"
}
}

Binary file not shown.