using Domain.Entities;
using Features.Breweries.Dtos;
using Features.Breweries.Repository;
using MediatR;
namespace Features.Breweries.Queries.GetBreweryLocationsWithinRange;
///
/// Handles by retrieving nearby located brewery posts.
///
public class GetBreweryLocationsWithinRangeHandler(IBreweryRepository repository)
: IRequestHandler>
{
/// Retrieves brewery posts within range of the requested coordinates, nearest first.
public async Task> Handle(
GetBreweryLocationsWithinRangeQuery request,
CancellationToken cancellationToken
)
{
IEnumerable breweries = await repository.GetAllLocationsWithinRange(
new CoordinateData(request.Latitude, request.Longitude),
request.RangeInMetres
);
return breweries.Select(b => b.ToSimplifiedDto());
}
}