Merge branch 'worktree-agent-a9d8edbd439109a45'
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user