using Features.Breweries.Repository;
using MediatR;
namespace Features.Breweries.Commands.DeleteBrewery;
/// Handles by deleting the corresponding brewery post.
public class DeleteBreweryHandler(IBreweryRepository repository)
: IRequestHandler
{
///
/// Thrown when no brewery exists with 's BreweryPostId.
///
///
/// Thrown when 's RequestingUserId did not post the brewery.
///
public async Task Handle(DeleteBreweryCommand request, CancellationToken cancellationToken)
{
await repository.EnsureCallerOwnsBreweryAsync(
request.BreweryPostId,
request.RequestingUserId,
cancellationToken
);
await repository.DeleteAsync(request.BreweryPostId);
}
}