mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
27 lines
1.0 KiB
C#
27 lines
1.0 KiB
C#
using Domain.Entities;
|
|
using Features.Breweries.Dtos;
|
|
using Features.Breweries.Repository;
|
|
using MediatR;
|
|
|
|
namespace Features.Breweries.Queries.GetBreweryLocationsWithinRange;
|
|
|
|
/// <summary>
|
|
/// Handles <see cref="GetBreweryLocationsWithinRangeQuery" /> by retrieving nearby located brewery posts.
|
|
/// </summary>
|
|
public class GetBreweryLocationsWithinRangeHandler(IBreweryRepository repository)
|
|
: IRequestHandler<GetBreweryLocationsWithinRangeQuery, IEnumerable<SimplifiedBreweryDto>>
|
|
{
|
|
/// <summary>Retrieves brewery posts within range of the requested coordinates, nearest first.</summary>
|
|
public async Task<IEnumerable<SimplifiedBreweryDto>> Handle(
|
|
GetBreweryLocationsWithinRangeQuery request,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
IEnumerable<BreweryPost> breweries = await repository.GetAllLocationsWithinRange(
|
|
new CoordinateData(request.Latitude, request.Longitude),
|
|
request.RangeInMetres
|
|
);
|
|
return breweries.Select(b => b.ToSimplifiedDto());
|
|
}
|
|
}
|