mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
Enforce brewery ownership on update and delete (#267)
This commit is contained in:
@@ -37,6 +37,17 @@ public class CreateBreweryHandler(IBreweryRepository repository)
|
||||
};
|
||||
|
||||
await repository.CreateAsync(entity);
|
||||
return entity.ToDto();
|
||||
|
||||
// RowVersion is a DB-computed column, unset on the in-memory entity; re-fetch so callers
|
||||
// get back the value needed for a subsequent optimistic-concurrency update. Uses
|
||||
// CancellationToken.None since the write already committed: cancelling the caller's request
|
||||
// at this point must not turn a successful creation into a thrown exception.
|
||||
BreweryPost created =
|
||||
await repository.GetByIdAsync(entity.BreweryPostId, CancellationToken.None)
|
||||
?? throw new InvalidOperationException(
|
||||
$"Brewery '{entity.BreweryPostId}' was not found after a successful creation."
|
||||
);
|
||||
|
||||
return created.ToDto();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user