Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
563 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const environment = { | ||
osrm_url:'http://router.project-osrm.org' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
|
||
const config = new DocumentBuilder() | ||
.setTitle('Individuelle Berner Stadtspaziergänge') | ||
.setDescription('API Routenfinder') | ||
.setVersion('1.0') | ||
.addTag('spaziergaenge') | ||
.build(); | ||
const document = SwaggerModule.createDocument(app, config); | ||
SwaggerModule.setup('api', app, document); | ||
await app.listen(3000); | ||
} | ||
bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class RouteDto{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { RoutesController } from './routes.controller'; | ||
import { RoutesService } from './routes.service'; | ||
|
||
describe('RoutesController', () => { | ||
let controller: RoutesController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [RoutesController], | ||
providers: [RoutesService], | ||
}).compile(); | ||
|
||
controller = module.get<RoutesController>(RoutesController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Controller, Get, Query, HttpStatus } from '@nestjs/common'; | ||
import { RoutesService } from './routes.service'; | ||
import { ApiParam } from '@nestjs/swagger'; | ||
|
||
export interface RouteQueryParams { | ||
coordinates: string, | ||
mode: string | ||
} | ||
|
||
@Controller('routes') | ||
export class RoutesController { | ||
|
||
constructor(private readonly routesService: RoutesService) {} | ||
|
||
@Get('health') | ||
health(){ | ||
return HttpStatus.OK; | ||
} | ||
|
||
@Get() | ||
@ApiParam({ | ||
name: 'routeQueryParams', | ||
description: 'coordinates, mode', | ||
}) | ||
findRoute(@Query() routeQueryParams: RouteQueryParams) { | ||
console.log(routeQueryParams) | ||
try { | ||
return this.routesService.getRoute(routeQueryParams.coordinates, routeQueryParams.mode); | ||
} catch(error){ | ||
throw new Error(error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { RoutesService } from './routes.service'; | ||
import { RoutesController } from './routes.controller'; | ||
import {HttpModule} from '@nestjs/axios' | ||
|
||
@Module({ | ||
imports: [RoutesModule, HttpModule], | ||
controllers: [RoutesController], | ||
providers: [RoutesService] | ||
}) | ||
export class RoutesModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { RoutesService } from './routes.service'; | ||
|
||
describe('RoutesService', () => { | ||
let service: RoutesService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [RoutesService], | ||
}).compile(); | ||
|
||
service = module.get<RoutesService>(RoutesService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { HttpService } from '@nestjs/axios'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { firstValueFrom, map } from 'rxjs'; | ||
import { environment } from 'src/environment'; | ||
|
||
@Injectable() | ||
export class RoutesService { | ||
osrm_url = environment.osrm_url; | ||
|
||
constructor(private httpService: HttpService){} | ||
|
||
async getRoute(coordinates: any, mode: any) { | ||
console.log('params: ' + coordinates + ' mode ' + mode) | ||
console.log(`${this.osrm_url}/route/v1/${mode}/${coordinates}?geometries=geojson`) | ||
const routes$ = this.httpService.get(`${this.osrm_url}/route/v1/${mode}/${coordinates}?geometries=geojson`); | ||
|
||
return this.httpService.get(`${this.osrm_url}/route/v1/${mode}/${coordinates}?geometries=geojson`).pipe(map((response) => { | ||
return response.data; | ||
})) | ||
} | ||
} |
Oops, something went wrong.