feat(gehege): Reinigungszyklus (Maße, Kapazität, letzte/nächste Reinigung)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 22:43:19 +02:00
parent 5e14124322
commit 4e7cd21b70
15 changed files with 2071 additions and 14 deletions

View File

@@ -25,6 +25,7 @@ namespace GerbilManagerWebAPI.Endpoints
group.MapPost("/", async (EnclosureInput input, ApplicationContext db) =>
{
var e = new Enclosure { Id = Guid.NewGuid(), Name = input.Name, Notes = input.Notes };
Apply(e, input);
db.Enclosures.Add(e);
await db.SaveChangesAsync();
return TypedResults.Created($"/enclosures/{e.Id}", ToDto(e));
@@ -35,10 +36,21 @@ namespace GerbilManagerWebAPI.Endpoints
var e = await db.Enclosures.FirstOrDefaultAsync(x => x.Id == id);
if (e is null) return TypedResults.NotFound();
e.Name = input.Name; e.Notes = input.Notes;
Apply(e, input);
await db.SaveChangesAsync();
return TypedResults.NoContent();
});
// Reinigung dokumentieren: setzt LastCleanedDate auf heute (NextCleaningDate folgt aus dem Zyklus).
group.MapPost("/{id:guid}/mark-cleaned", async Task<Results<Ok<EnclosureDto>, NotFound>> (Guid id, ApplicationContext db) =>
{
var e = await db.Enclosures.FirstOrDefaultAsync(x => x.Id == id);
if (e is null) return TypedResults.NotFound();
e.LastCleanedDate = DateOnly.FromDateTime(DateTime.Today);
await db.SaveChangesAsync();
return TypedResults.Ok(ToDto(e));
});
// 409 if the enclosure still houses gerbils.
group.MapDelete("/{id:guid}", async Task<Results<NoContent, NotFound, Conflict<string>>> (Guid id, ApplicationContext db) =>
{
@@ -54,6 +66,16 @@ namespace GerbilManagerWebAPI.Endpoints
return app;
}
private static EnclosureDto ToDto(Enclosure e) => new(e.Id, e.Name, e.Notes);
private static void Apply(Enclosure e, EnclosureInput input)
{
e.Size = input.Size;
e.Capacity = input.Capacity;
e.LastCleanedDate = input.LastCleanedDate;
e.CleaningCycleDays = input.CleaningCycleDays;
}
private static EnclosureDto ToDto(Enclosure e) =>
new(e.Id, e.Name, e.Notes, e.Size, e.Capacity,
e.LastCleanedDate, e.CleaningCycleDays, e.NextCleaningDate);
}
}