Loading backend/src/route/route.controller.ts +32 −29 Original line number Diff line number Diff line import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req, Query } from '@nestjs/common'; import { RouteService } from './route.service'; import { CreateRouteDto } from './dto/create-route.dto'; import { UpdateRouteDto } from './dto/update-route.dto'; import { ApiConsumes, ApiTags } from '@nestjs/swagger'; import { ApiBearerAuth, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; import { LANGUAGES } from 'src/shared/enum/languages.enum'; import { AuthUserGuard } from 'src/auth/user/authUser.guard'; import { CustomUserRequest } from 'src/auth/user/interface/customUserReq'; @Controller('route') @ApiTags('routes') @ApiTags('route') export class RouteController { constructor(private readonly routeService: RouteService) {} @Post() @ApiConsumes('multipart/form-data') // @UseGuards(AuthUserGuard) async create(@Body() createRouteDto: CreateRouteDto) { return await this.routeService.create(); } @Get() findAll() { return this.routeService.findAll(); } // @Post() // @ApiConsumes('multipart/form-data') // // @UseGuards(AuthUserGuard) // async create(@Body() createRouteDto: CreateRouteDto) { // return await this.routeService.recommend(); // } @Get(':idRoute') async findOne(@Param('idRoute') idRoute: number) { return await this.routeService.findOne(idRoute); } // @Get(':idRoute') // async findOne(@Param('idRoute') idRoute: number) { // return await this.routeService.findOne(idRoute); // } @Patch(':id') update(@Param('id') id: string, @Body() updateRouteDto: UpdateRouteDto) { return this.routeService.update(+id, updateRouteDto); } // @Patch(':id') // update(@Param('id') id: string, @Body() updateRouteDto: UpdateRouteDto) { // return this.routeService.update(+id, updateRouteDto); // } @Delete(':id') remove(@Param('id') id: string) { return this.routeService.remove(+id); } // @Delete(':id') // remove(@Param('id') id: string) { // return this.routeService.remove(+id); // } @Get('recommend') recommendRoute() { return this.routeService.recommend(); @Get('recommend:idTown') @ApiQuery({ name: 'lang', type: String }) @ApiParam({ name: 'idTown', type: Number }) @ApiBearerAuth('jwt') @UseGuards(AuthUserGuard) async recommendRoute(@Req() req: CustomUserRequest, @Query('lang') lang: string, @Param('idTown') idTown: number) { const { email } = req.user; return await this.routeService.recommend(idTown, email, lang as LANGUAGES); } } Loading
backend/src/route/route.controller.ts +32 −29 Original line number Diff line number Diff line import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req, Query } from '@nestjs/common'; import { RouteService } from './route.service'; import { CreateRouteDto } from './dto/create-route.dto'; import { UpdateRouteDto } from './dto/update-route.dto'; import { ApiConsumes, ApiTags } from '@nestjs/swagger'; import { ApiBearerAuth, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; import { LANGUAGES } from 'src/shared/enum/languages.enum'; import { AuthUserGuard } from 'src/auth/user/authUser.guard'; import { CustomUserRequest } from 'src/auth/user/interface/customUserReq'; @Controller('route') @ApiTags('routes') @ApiTags('route') export class RouteController { constructor(private readonly routeService: RouteService) {} @Post() @ApiConsumes('multipart/form-data') // @UseGuards(AuthUserGuard) async create(@Body() createRouteDto: CreateRouteDto) { return await this.routeService.create(); } @Get() findAll() { return this.routeService.findAll(); } // @Post() // @ApiConsumes('multipart/form-data') // // @UseGuards(AuthUserGuard) // async create(@Body() createRouteDto: CreateRouteDto) { // return await this.routeService.recommend(); // } @Get(':idRoute') async findOne(@Param('idRoute') idRoute: number) { return await this.routeService.findOne(idRoute); } // @Get(':idRoute') // async findOne(@Param('idRoute') idRoute: number) { // return await this.routeService.findOne(idRoute); // } @Patch(':id') update(@Param('id') id: string, @Body() updateRouteDto: UpdateRouteDto) { return this.routeService.update(+id, updateRouteDto); } // @Patch(':id') // update(@Param('id') id: string, @Body() updateRouteDto: UpdateRouteDto) { // return this.routeService.update(+id, updateRouteDto); // } @Delete(':id') remove(@Param('id') id: string) { return this.routeService.remove(+id); } // @Delete(':id') // remove(@Param('id') id: string) { // return this.routeService.remove(+id); // } @Get('recommend') recommendRoute() { return this.routeService.recommend(); @Get('recommend:idTown') @ApiQuery({ name: 'lang', type: String }) @ApiParam({ name: 'idTown', type: Number }) @ApiBearerAuth('jwt') @UseGuards(AuthUserGuard) async recommendRoute(@Req() req: CustomUserRequest, @Query('lang') lang: string, @Param('idTown') idTown: number) { const { email } = req.user; return await this.routeService.recommend(idTown, email, lang as LANGUAGES); } }