53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import { Controller, Get, Post, Body, Query, UseGuards } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
|
import { GeocodingService } from './geocoding.service';
|
|
import { ApiKeyGuard } from '../common/guards/api-key.guard';
|
|
|
|
@ApiTags('geocoding')
|
|
@Controller('geocoding')
|
|
@UseGuards(ApiKeyGuard)
|
|
export class GeocodingController {
|
|
constructor(private readonly geocodingService: GeocodingService) {}
|
|
|
|
@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 })
|
|
async search(
|
|
@Query('q') query: string,
|
|
@Query('lat') lat?: number,
|
|
@Query('lng') lng?: number,
|
|
@Query('radius') radius?: number,
|
|
) {
|
|
return this.geocodingService.searchPlaces(query, lat, lng, radius);
|
|
}
|
|
|
|
@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: number, @Query('lng') lng: number) {
|
|
return this.geocodingService.reverseGeocode(lat, lng);
|
|
}
|
|
|
|
@Post('places')
|
|
@ApiOperation({ summary: 'Add a new location (User Submitted)' })
|
|
async addPlace(@Body() placeData: any) {
|
|
return this.geocodingService.addPlace(placeData);
|
|
}
|
|
|
|
@Get('places')
|
|
@ApiOperation({ summary: 'Get recent user submitted places' })
|
|
async getPlaces(@Query('limit') limit?: number) {
|
|
return this.geocodingService.getRecentPlaces(limit);
|
|
}
|
|
|
|
@Post('migrate')
|
|
@ApiOperation({ summary: 'Migrate legacy MySQL data to PostGIS' })
|
|
async migrate() {
|
|
return this.geocodingService.migrateFromMySQL('LEGACY_DB');
|
|
}
|
|
}
|