mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Add brewery location query endpoints
This commit is contained in:
@@ -3,7 +3,9 @@ using Features.Breweries.Commands.DeleteBrewery;
|
||||
using Features.Breweries.Commands.UpdateBrewery;
|
||||
using Features.Breweries.Dtos;
|
||||
using Features.Breweries.Queries.GetAllBreweries;
|
||||
using Features.Breweries.Queries.GetAllBreweryLocations;
|
||||
using Features.Breweries.Queries.GetBreweryById;
|
||||
using Features.Breweries.Queries.GetBreweryLocationsWithinRange;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -64,6 +66,49 @@ public class BreweryController(IMediator mediator) : ControllerBase
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Retrieves all brewery posts that have a set location.</summary>
|
||||
/// <remarks>Allows anonymous access.</remarks>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("locations")]
|
||||
public async Task<ActionResult<ResponseBody<IEnumerable<SimplifiedBreweryDto>>>> GetAllLocations()
|
||||
{
|
||||
IEnumerable<SimplifiedBreweryDto> breweries = await mediator.Send(
|
||||
new GetAllBreweryLocationsQuery()
|
||||
);
|
||||
return Ok(
|
||||
new ResponseBody<IEnumerable<SimplifiedBreweryDto>>
|
||||
{
|
||||
Message = "Brewery locations retrieved successfully.",
|
||||
Payload = breweries,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Retrieves brewery posts with a set location within range of the given coordinates, nearest first.</summary>
|
||||
/// <param name="latitude">The origin latitude, in decimal degrees.</param>
|
||||
/// <param name="longitude">The origin longitude, in decimal degrees.</param>
|
||||
/// <param name="rangeInMetres">The maximum distance, in metres, from the origin coordinates.</param>
|
||||
/// <remarks>Allows anonymous access.</remarks>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("locations/nearby")]
|
||||
public async Task<ActionResult<ResponseBody<IEnumerable<SimplifiedBreweryDto>>>> GetLocationsWithinRange(
|
||||
[FromQuery] double latitude,
|
||||
[FromQuery] double longitude,
|
||||
[FromQuery] double rangeInMetres
|
||||
)
|
||||
{
|
||||
IEnumerable<SimplifiedBreweryDto> breweries = await mediator.Send(
|
||||
new GetBreweryLocationsWithinRangeQuery(latitude, longitude, rangeInMetres)
|
||||
);
|
||||
return Ok(
|
||||
new ResponseBody<IEnumerable<SimplifiedBreweryDto>>
|
||||
{
|
||||
Message = "Brewery locations retrieved successfully.",
|
||||
Payload = breweries,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Creates a new brewery post.</summary>
|
||||
/// <returns><c>201 Created</c> with the newly created brewery.</returns>
|
||||
[HttpPost]
|
||||
|
||||
Reference in New Issue
Block a user