From 7eec8f160286746c713b451d7d8576bc50314c9b Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Wed, 7 Apr 2021 09:43:09 +0200
Subject: [PATCH] feat: zoom on town

---
 src/structures/structures.controller.ts | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/structures/structures.controller.ts b/src/structures/structures.controller.ts
index b4aeea9bc..b25e60d5e 100644
--- a/src/structures/structures.controller.ts
+++ b/src/structures/structures.controller.ts
@@ -4,6 +4,7 @@ import {
   Delete,
   Get,
   HttpException,
+  HttpService,
   HttpStatus,
   Param,
   Post,
@@ -29,11 +30,28 @@ import { StructuresService } from './services/structures.service';
 @Controller('structures')
 export class StructuresController {
   constructor(
+    private readonly httpService: HttpService,
     private readonly structureService: StructuresService,
     private readonly userService: UsersService,
     private readonly tempUserService: TempUserService
   ) {}
 
+  /**
+   * Return points of given town exist.
+   * @param zipcode
+   * @returns Array of points
+   */
+  @Get('coordinates/:zipcode')
+  @ApiParam({ name: 'zipcode', type: String, required: true })
+  public async getCoordinates(@Param('zipcode') city: string): Promise<any> {
+    return await this.httpService
+      .get(encodeURI('https://download.data.grandlyon.com/geocoding/photon-bal/api?q=' + city))
+      .toPromise()
+      .then(async (res) => res.data.features)
+      .then((data) => data.filter((cityPoint) => cityPoint.properties.city.toLowerCase().includes(city.toLowerCase())))
+      .then((data) => data.map((filteredCityPoint) => filteredCityPoint.geometry.coordinates));
+  }
+
   @Post()
   public async create(@Body() createStructureDto: CreateStructureDto): Promise<Structure> {
     return this.structureService.create(createStructureDto.idUser, createStructureDto.structure);
-- 
GitLab