Добавил несколько endpoint
Сгенерировано нейросетью! Требует проверки
This commit is contained in:
parent
9067d8dece
commit
f7f0a56c51
@ -44,6 +44,52 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseExceptionHandler();
|
app.UseExceptionHandler();
|
||||||
|
|
||||||
app.MapGet("/weatherforecast", async (DatabaseContext db) => await db.Forecasts.ToListAsync());
|
app.MapGet("/weatherforecast", async (DatabaseContext db) => await db.Forecasts.ToListAsync());
|
||||||
|
app.MapDelete("/weatherforecast/{id}", async (DatabaseContext db, int id) =>
|
||||||
|
{
|
||||||
|
var forecast = await db.Forecasts.FindAsync(id);
|
||||||
|
if (forecast == null)
|
||||||
|
{
|
||||||
|
return Results.NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
db.Forecasts.Remove(forecast);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Results.NoContent();
|
||||||
|
});
|
||||||
|
app.MapPost("/weatherforecast", async (DatabaseContext db, WeatherForecast forecast) =>
|
||||||
|
{
|
||||||
|
db.Forecasts.Add(forecast);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Results.Created($"/weatherforecast/{forecast.Id}", forecast);
|
||||||
|
});
|
||||||
|
app.MapPut("/weatherforecast/{id}", async (DatabaseContext db, int id, WeatherForecast forecast) =>
|
||||||
|
{
|
||||||
|
if (id != forecast.Id)
|
||||||
|
{
|
||||||
|
return Results.BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
db.Entry(forecast).State = EntityState.Modified;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch (DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
if (await db.Forecasts.FindAsync(id) == null)
|
||||||
|
{
|
||||||
|
return Results.NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Results.NoContent();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
app.MapDefaultEndpoints();
|
app.MapDefaultEndpoints();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user