From 5ae638653a52e8c0130066f9f534dc68e934aae2 Mon Sep 17 00:00:00 2001 From: yulia-bel Date: Fri, 6 Oct 2023 16:14:07 +0200 Subject: [PATCH] Update cost surface tiles endpoints --- .../cost-surface/cost-surface.service.ts | 1 - .../project-cost-surface.controller.ts | 7 +++--- .../cost-surface/cost-surface.controller.ts | 9 +++---- .../cost-surface/cost-surface.service.ts | 24 +++++++++---------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/api/apps/api/src/modules/cost-surface/cost-surface.service.ts b/api/apps/api/src/modules/cost-surface/cost-surface.service.ts index 44e89f253a..7eab3ca6b4 100644 --- a/api/apps/api/src/modules/cost-surface/cost-surface.service.ts +++ b/api/apps/api/src/modules/cost-surface/cost-surface.service.ts @@ -315,5 +315,4 @@ export class CostSurfaceService { static defaultCostSurfaceName(): string { return `Default Cost Surface`; } - } diff --git a/api/apps/api/src/modules/projects/project-cost-surface.controller.ts b/api/apps/api/src/modules/projects/project-cost-surface.controller.ts index 3a67a2c42b..ea3f687d11 100644 --- a/api/apps/api/src/modules/projects/project-cost-surface.controller.ts +++ b/api/apps/api/src/modules/projects/project-cost-surface.controller.ts @@ -6,15 +6,16 @@ import { forwardRef, Get, Inject, - Param, ParseIntPipe, + Param, + ParseIntPipe, ParseUUIDPipe, Patch, Post, Req, Res, UploadedFile, - UseGuards -} from "@nestjs/common"; + UseGuards, +} from '@nestjs/common'; import { ApiForbiddenResponse, ApiOkResponse, diff --git a/api/apps/geoprocessing/src/modules/cost-surface/cost-surface.controller.ts b/api/apps/geoprocessing/src/modules/cost-surface/cost-surface.controller.ts index 6280577b9c..257e148c59 100644 --- a/api/apps/geoprocessing/src/modules/cost-surface/cost-surface.controller.ts +++ b/api/apps/geoprocessing/src/modules/cost-surface/cost-surface.controller.ts @@ -18,7 +18,10 @@ import { BBox } from 'geojson'; import { Response } from 'express'; import { setTileResponseHeadersForSuccessfulRequests } from '@marxan/tiles'; -import { CostSurfaceService, CostSurfaceTileRequest } from "@marxan-geoprocessing/modules/cost-surface/cost-surface.service"; +import { + CostSurfaceService, + CostSurfaceTileRequest, +} from '@marxan-geoprocessing/modules/cost-surface/cost-surface.service'; @Controller(`${apiGlobalPrefixes.v1}/cost-surfaces`) export class FeaturesController { @@ -66,9 +69,7 @@ export class FeaturesController { @Param() TileSpecification: CostSurfaceTileRequest, @Res() response: Response, ): Promise { - const tile: Buffer = await this.service.findTile( - TileSpecification - ); + const tile: Buffer = await this.service.findTile(TileSpecification); setTileResponseHeadersForSuccessfulRequests(response); return response.send(tile); } diff --git a/api/apps/geoprocessing/src/modules/cost-surface/cost-surface.service.ts b/api/apps/geoprocessing/src/modules/cost-surface/cost-surface.service.ts index d936253c55..e44b17b58f 100644 --- a/api/apps/geoprocessing/src/modules/cost-surface/cost-surface.service.ts +++ b/api/apps/geoprocessing/src/modules/cost-surface/cost-surface.service.ts @@ -1,19 +1,21 @@ import { Injectable, Logger, Inject } from '@nestjs/common'; import { TileService } from '@marxan-geoprocessing/modules/tile/tile.service'; import { InjectRepository } from '@nestjs/typeorm'; -import { Brackets, Repository } from "typeorm"; -import { GeoFeatureGeometry } from '@marxan/geofeatures'; -import { IsArray, IsNumber, IsString, IsOptional, IsDefined } from "class-validator"; +import { Repository } from 'typeorm'; +import { + IsArray, + IsNumber, + IsString, + IsOptional, +} from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; import { Transform } from 'class-transformer'; import { BBox } from 'geojson'; import { antimeridianBbox, nominatim2bbox } from '@marxan/utils/geo'; import { TileRequest } from '@marxan/tiles'; -import { ProtectedAreaTileRequest } from "@marxan-geoprocessing/modules/protected-areas/protected-area-tile-request"; -import { QueryResult } from "pg"; -import { TileSpecification } from "@marxan-geoprocessing/modules/features/features.service"; -import { CostSurfacePuDataEntity } from "@marxan/cost-surfaces"; + +import { CostSurfacePuDataEntity } from '@marxan/cost-surfaces'; export class CostSurfaceTileRequest extends TileRequest { @ApiProperty() @IsString() @@ -32,19 +34,17 @@ export class CostSurfaceFilters { bbox?: BBox; } - @Injectable() export class CostSurfaceService { private readonly logger: Logger = new Logger(CostSurfaceService.name); constructor( - @InjectRepository(GeoFeatureGeometry) + @InjectRepository(CostSurfacePuDataEntity) private readonly costSurfaceDataRepository: Repository, private readonly tileService: TileService, ) {} - - buildFeaturesWhereQuery(id: string, bbox?: BBox): string { + buildCostSurfacesWhereQuery(id: string, bbox?: BBox): string { let whereQuery = `cost_surface_id = '${id}'`; if (bbox) { @@ -76,7 +76,7 @@ export class CostSurfaceService { from "${this.costSurfaceDataRepository.metadata.tableName}") inner join projects_pu on project_pu.id = cost_surface_pu_dat.projects_pu_id`; - const customQuery = this.buildFeaturesWhereQuery(costSurfaceId, bbox); + const customQuery = this.buildCostSurfacesWhereQuery(costSurfaceId, bbox); return this.tileService.getTile({ z, x,