using Domain.Exceptions; namespace Features.Breweries.Repository; /// /// Provides authorization checks for brewery-post mutations. /// public static class BreweryOwnershipExtensions { /// /// Verifies that the specified user created the brewery post. /// /// /// Thrown if the brewery post cannot be found. /// /// /// Thrown if the specified user does not own the brewery post. /// 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."); } }