2026-04-14-8 auth and commercial
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import { Controller, Get, Post, Delete, Body, Query, UseGuards, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
||||
import { ApiTags, ApiOperation, ApiQuery, ApiHeader } from '@nestjs/swagger';
|
||||
import { GeocodingService } from './geocoding.service';
|
||||
import { AdminBoundariesService } from './admin-boundaries.service';
|
||||
import { JordanResearchService } from './jordan-research.service';
|
||||
import { AdministrativeLinkingService } from './administrative-linking.service';
|
||||
import { ApiKeyGuard } from '../common/guards/api-key.guard';
|
||||
import { TenantThrottlerGuard } from '../common/guards/rate-limiter.guard';
|
||||
import { SearchQueryDto } from './dto/search-query.dto';
|
||||
import { ReverseGeocodeDto } from './dto/reverse-geocode.dto';
|
||||
|
||||
@ApiTags('geocoding')
|
||||
@ApiHeader({ name: 'x-api-key', description: 'Multi-tenant API Key', required: true })
|
||||
@Controller('geocoding')
|
||||
@UseGuards(ApiKeyGuard)
|
||||
@UseGuards(ApiKeyGuard, TenantThrottlerGuard)
|
||||
export class GeocodingController {
|
||||
constructor(
|
||||
private readonly geocodingService: GeocodingService,
|
||||
@@ -19,46 +23,18 @@ export class GeocodingController {
|
||||
|
||||
@Get('search')
|
||||
@ApiOperation({ summary: 'Search for locations (Forward Geocoding)' })
|
||||
@ApiQuery({ name: 'q', required: true })
|
||||
@ApiQuery({ name: 'lat', required: false, type: Number })
|
||||
@ApiQuery({ name: 'lng', required: false, type: Number })
|
||||
@ApiQuery({ name: 'radius', required: false, type: Number })
|
||||
@ApiQuery({ name: 'country', required: false, enum: ['jordan', 'syria', 'egypt'] })
|
||||
async search(
|
||||
@Query('q') query: string,
|
||||
@Query('lat') lat?: string,
|
||||
@Query('lng') lng?: string,
|
||||
@Query('radius') radius?: string,
|
||||
@Query('country') country?: string,
|
||||
) {
|
||||
// NestJS @Query() always receives strings — must parse explicitly for numeric types
|
||||
const parsedLat = lat !== undefined ? parseFloat(lat) : Number.NaN;
|
||||
const parsedLng = lng !== undefined ? parseFloat(lng) : Number.NaN;
|
||||
const parsedRadius = radius !== undefined ? parseFloat(radius) : 20000;
|
||||
|
||||
// Guard against malformed float values (NaN breaks PostGIS)
|
||||
const safeLat = !isNaN(parsedLat) ? parsedLat : undefined;
|
||||
const safeLng = !isNaN(parsedLng) ? parsedLng : undefined;
|
||||
|
||||
return this.geocodingService.searchPlaces(query, safeLat, safeLng, parsedRadius, country);
|
||||
async search(@Query() queryDto: SearchQueryDto) {
|
||||
const { q, lat, lng, radius, country } = queryDto;
|
||||
|
||||
// ValidationPipe with { transform: true } handles numeric conversion and defaults
|
||||
return this.geocodingService.searchPlaces(q, lat, lng, radius, country);
|
||||
}
|
||||
|
||||
@Get('reverse')
|
||||
@ApiOperation({ summary: 'Reverse Geocoding (Lat/Lng to Address)' })
|
||||
@ApiQuery({ name: 'lat', required: true })
|
||||
@ApiQuery({ name: 'lng', required: true })
|
||||
async reverse(
|
||||
@Query('lat') lat: string,
|
||||
@Query('lng') lng: string,
|
||||
) {
|
||||
const parsedLat = parseFloat(lat);
|
||||
const parsedLng = parseFloat(lng);
|
||||
|
||||
if (isNaN(parsedLat) || isNaN(parsedLng)) {
|
||||
throw new HttpException('Invalid lat/lng values', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
return this.geocodingService.reverseGeocode(parsedLat, parsedLng);
|
||||
async reverse(@Query() reverseDto: ReverseGeocodeDto) {
|
||||
const { lat, lng } = reverseDto;
|
||||
return this.geocodingService.reverseGeocode(lat, lng);
|
||||
}
|
||||
|
||||
@Post('places')
|
||||
|
||||
Reference in New Issue
Block a user