Compare commits
2 Commits
87d81f98e9
...
fd9b9c7c2e
| Author | SHA1 | Date | |
|---|---|---|---|
| fd9b9c7c2e | |||
| b6f9b5fb26 |
@@ -106,7 +106,7 @@ export class EntryCardComponent {
|
|||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: 'Serverfehler',
|
summary: 'Serverfehler',
|
||||||
detail:
|
detail:
|
||||||
'Beim Erstellen des Eintrags ist ein Fehler aufgetreten. Bitte versuche es erneut.',
|
'Beim Löschen des Eintrags ist ein Fehler aufgetreten. Bitte versuche es erneut.',
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case error.status === 400:
|
case error.status === 400:
|
||||||
@@ -123,7 +123,7 @@ export class EntryCardComponent {
|
|||||||
severity: 'error',
|
severity: 'error',
|
||||||
summary: 'Unerwarteter Fehler',
|
summary: 'Unerwarteter Fehler',
|
||||||
detail:
|
detail:
|
||||||
'Beim Erstellen des Eintrags hat der Server eine unerwartete Antwort zurückgegeben.',
|
'Beim Löschen des Eintrags hat der Server eine unerwartete Antwort zurückgegeben.',
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Vegasco.Server.Api.Persistence;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Vegasco.Server.Api.Persistence;
|
||||||
|
|
||||||
namespace Vegasco.Server.Api.Cars;
|
namespace Vegasco.Server.Api.Cars;
|
||||||
|
|
||||||
@@ -17,18 +18,21 @@ public static class DeleteCar
|
|||||||
public static async Task<IResult> Endpoint(
|
public static async Task<IResult> Endpoint(
|
||||||
Guid id,
|
Guid id,
|
||||||
ApplicationDbContext dbContext,
|
ApplicationDbContext dbContext,
|
||||||
|
ILoggerFactory loggerFactory,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Car? car = await dbContext.Cars.FindAsync([new CarId(id)], cancellationToken: cancellationToken);
|
var rows = await dbContext.Cars
|
||||||
|
.Where(x => x.Id == new CarId(id))
|
||||||
|
.ExecuteDeleteAsync(cancellationToken);
|
||||||
|
|
||||||
if (car is null)
|
if (rows > 1)
|
||||||
{
|
{
|
||||||
return TypedResults.NotFound();
|
var logger = loggerFactory.CreateLogger(nameof(DeleteCar));
|
||||||
|
logger.LogWarning("Deleted '{DeletedRowCount}' rows for id '{CarId}'", rows, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbContext.Cars.Remove(car);
|
return rows > 0
|
||||||
await dbContext.SaveChangesAsync(cancellationToken);
|
? TypedResults.NoContent()
|
||||||
|
: TypedResults.NotFound();
|
||||||
return TypedResults.NoContent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Vegasco.Server.Api.Persistence;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Vegasco.Server.Api.Persistence;
|
||||||
|
|
||||||
namespace Vegasco.Server.Api.Consumptions;
|
namespace Vegasco.Server.Api.Consumptions;
|
||||||
|
|
||||||
@@ -15,19 +16,23 @@ public static class DeleteConsumption
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<IResult> Endpoint(
|
private static async Task<IResult> Endpoint(
|
||||||
ApplicationDbContext dbContext,
|
|
||||||
Guid id,
|
Guid id,
|
||||||
|
ApplicationDbContext dbContext,
|
||||||
|
ILoggerFactory loggerFactory,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Consumption? consumption = await dbContext.Consumptions.FindAsync([new ConsumptionId(id)], cancellationToken);
|
var rows = await dbContext.Consumptions
|
||||||
if (consumption is null)
|
.Where(x => x.Id == new ConsumptionId(id))
|
||||||
|
.ExecuteDeleteAsync(cancellationToken);
|
||||||
|
|
||||||
|
if (rows > 1)
|
||||||
{
|
{
|
||||||
return TypedResults.NotFound();
|
var logger = loggerFactory.CreateLogger(nameof(DeleteConsumption));
|
||||||
|
logger.LogWarning("Deleted '{DeletedRowCount}' rows for id '{ConsumptionId}'", rows, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbContext.Consumptions.Remove(consumption);
|
return rows > 0
|
||||||
await dbContext.SaveChangesAsync(cancellationToken);
|
? TypedResults.NoContent()
|
||||||
|
: TypedResults.NotFound();
|
||||||
return TypedResults.NoContent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user