using Domain.Exceptions; namespace Features.Breweries.Repository; /// Shared ownership check for commands that mutate a specific brewery post. public static class BreweryOwnershipExtensions { /// Thrown when no brewery exists with the given ID. /// Thrown when did not post the brewery. public static async Task EnsureCallerOwnsBreweryAsync( this IBreweryRepository repository, Guid breweryPostId, Guid requestingUserId, CancellationToken cancellationToken ) { Guid postedById = await repository.GetPostedByIdAsync(breweryPostId, cancellationToken) ?? throw new NotFoundException($"Brewery with ID {breweryPostId} not found."); if (postedById != requestingUserId) throw new ForbiddenException("You are not authorized to modify this brewery."); } }