server: add POST bounds get method by list of ids
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
import { Controller, Get, Param, ParseIntPipe, Query } from '@nestjs/common';
|
import { Body, Controller, Get, Param, ParseIntPipe, Post, Query } from '@nestjs/common';
|
||||||
import { GisService } from './gis.service';
|
import { GisService } from './gis.service';
|
||||||
|
import { ApiBody } from '@nestjs/swagger';
|
||||||
|
import { BoundsRequestDto } from './dto/bound';
|
||||||
|
|
||||||
@Controller('gis')
|
@Controller('gis')
|
||||||
export class GisController {
|
export class GisController {
|
||||||
@ -20,6 +22,15 @@ export class GisController {
|
|||||||
return await this.gisService.getBoundsByEntityTypeAndId(entity_type, entity_id)
|
return await this.gisService.getBoundsByEntityTypeAndId(entity_type, entity_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('/bounds/:entity_type')
|
||||||
|
@ApiBody({ type: BoundsRequestDto })
|
||||||
|
async getBoundsByEntityTypeAndList(
|
||||||
|
@Param('entity_type') entity_type: 'region' | 'district' | 'city',
|
||||||
|
@Body('list') list: number[],
|
||||||
|
) {
|
||||||
|
return await this.gisService.getBoundsByEntityTypeAndList(entity_type, list);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('/images/all')
|
@Get('/images/all')
|
||||||
async getImages(@Query('offset') offset: number, @Query('limit') limit: number, @Query('city_id') city_id: number) {
|
async getImages(@Query('offset') offset: number, @Query('limit') limit: number, @Query('city_id') city_id: number) {
|
||||||
return await this.gisService.getImages(offset, limit, city_id)
|
return await this.gisService.getImages(offset, limit, city_id)
|
||||||
|
@ -64,6 +64,50 @@ export class GisService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBoundsByEntityTypeAndList(
|
||||||
|
entity_type: 'region' | 'district' | 'city',
|
||||||
|
list: number[],
|
||||||
|
): Promise<any[]> {
|
||||||
|
if (!list || list.length === 0) {
|
||||||
|
throw new NotFoundException('No entity IDs provided');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build placeholders (?, ?, ?) for SQLite IN clause
|
||||||
|
const placeholders = list.map(() => '?').join(', ');
|
||||||
|
|
||||||
|
const result = await this.dataSource.query(
|
||||||
|
`
|
||||||
|
SELECT entity_id, entity_type, geometry
|
||||||
|
FROM bounds
|
||||||
|
WHERE entity_type = ?
|
||||||
|
AND entity_id IN (${placeholders})
|
||||||
|
`,
|
||||||
|
[entity_type, ...list],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!Array.isArray(result) || result.length === 0) {
|
||||||
|
throw new NotFoundException('Not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.map(
|
||||||
|
(bound: {
|
||||||
|
id: string;
|
||||||
|
entity_id: number;
|
||||||
|
entity_type: string;
|
||||||
|
geometry: string;
|
||||||
|
published_at: string;
|
||||||
|
deleted_at: string | null;
|
||||||
|
}) => ({
|
||||||
|
...(JSON.parse(bound.geometry)),
|
||||||
|
properties: {
|
||||||
|
id: bound.id,
|
||||||
|
entity_id: bound.entity_id,
|
||||||
|
entity_type: bound.entity_type,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async getImages(offset: number, limit: number, city_id: number): Promise<any[]> {
|
async getImages(offset: number, limit: number, city_id: number): Promise<any[]> {
|
||||||
const result = await this.emsDataSource.query(`
|
const result = await this.emsDataSource.query(`
|
||||||
SELECT * FROM images
|
SELECT * FROM images
|
||||||
|
Reference in New Issue
Block a user