mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 10:04:44 +00:00
Enforce brewery ownership on update and delete (#267)
This commit is contained in:
@@ -2,5 +2,5 @@ using MediatR;
|
||||
|
||||
namespace Features.Breweries.Commands.DeleteBrewery;
|
||||
|
||||
/// <summary>Deletes a brewery post. Bound directly from the route of <c>DELETE /api/brewery/{id}</c>.</summary>
|
||||
public record DeleteBreweryCommand(Guid BreweryPostId) : IRequest;
|
||||
/// <summary>Deletes a brewery post. <see cref="BreweryPostId" /> is bound from the route of <c>DELETE /api/brewery/{id}</c>.</summary>
|
||||
public record DeleteBreweryCommand(Guid BreweryPostId, Guid RequestingUserId) : IRequest;
|
||||
|
||||
@@ -10,8 +10,17 @@ public class DeleteBreweryHandler(IBreweryRepository repository)
|
||||
/// <exception cref="Domain.Exceptions.NotFoundException">
|
||||
/// Thrown when no brewery exists with <paramref name="request" />'s <c>BreweryPostId</c>.
|
||||
/// </exception>
|
||||
public Task Handle(DeleteBreweryCommand request, CancellationToken cancellationToken)
|
||||
/// <exception cref="Domain.Exceptions.ForbiddenException">
|
||||
/// Thrown when <paramref name="request" />'s <c>RequestingUserId</c> did not post the brewery.
|
||||
/// </exception>
|
||||
public async Task Handle(DeleteBreweryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
return repository.DeleteAsync(request.BreweryPostId);
|
||||
await repository.EnsureCallerOwnsBreweryAsync(
|
||||
request.BreweryPostId,
|
||||
request.RequestingUserId,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
await repository.DeleteAsync(request.BreweryPostId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user