From bf3638f1d5eceb11af5637827d05a704d51e4883 Mon Sep 17 00:00:00 2001 From: popovspiridon99 Date: Wed, 24 Sep 2025 11:12:59 +0900 Subject: [PATCH] server: add POST bounds get method by list of ids --- server/src/gis/gis.controller.ts | 13 +++++++++- server/src/gis/gis.service.ts | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/server/src/gis/gis.controller.ts b/server/src/gis/gis.controller.ts index b743e71..8d3e357 100644 --- a/server/src/gis/gis.controller.ts +++ b/server/src/gis/gis.controller.ts @@ -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 { ApiBody } from '@nestjs/swagger'; +import { BoundsRequestDto } from './dto/bound'; @Controller('gis') export class GisController { @@ -20,6 +22,15 @@ export class GisController { 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') 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) diff --git a/server/src/gis/gis.service.ts b/server/src/gis/gis.service.ts index 2501676..d91f275 100644 --- a/server/src/gis/gis.service.ts +++ b/server/src/gis/gis.service.ts @@ -64,6 +64,50 @@ export class GisService { } } + async getBoundsByEntityTypeAndList( + entity_type: 'region' | 'district' | 'city', + list: number[], + ): Promise { + 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 { const result = await this.emsDataSource.query(` SELECT * FROM images