public LocPocQuery(ILocationsRepositoryAsync repository) { Field <ListGraphType <LocationType> >( "locations", resolve: context => repository.GetAllAsync() ); }
public async Task <ActionResult <IEnumerable <DTOs.Location> > > Get() { var locations = await _locationsRepository.GetAllAsync(); var locationDTOs = locations.Select(loc => loc.ToLocationDto()); return(Ok(locationDTOs)); }
public async Task <IEnumerable <LocationWithDistanceFromStartingPoint> > GetNearestLocations(StartingLocation startingLocation, int maxDistance, int maxResults) { EnsureArg.IsNotNull(startingLocation, nameof(startingLocation)); EnsureArg.IsGte(maxDistance, 0, nameof(maxDistance)); EnsureArg.IsGt(maxResults, 0, nameof(maxResults)); // In the case of an actual database with lots of records, we can use caching to save time when // fetching al the records. var allLocations = await _locationsRepository.GetAllAsync(); var startLoc = new Location(startingLocation.Latitude, startingLocation.Longitude); // Time complexity depends on the size of M. Worst case if M is big then TC=O(M log M), else Omega(N) var res = allLocations .Select(l => new LocationWithDistanceFromStartingPoint(l, l.CalculateDistance(startLoc))) // Select: O(N) .Where(l => l.DistanceFromStartingPoint <= maxDistance) // Where: O(N) .OrderBy(l => l.DistanceFromStartingPoint) //O(M log M) .Take(maxResults); // Take: O(M) return(res); }