From a1ed3769ad89eabd3162025eccf5ba3086daab90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:44:05 -0600 Subject: [PATCH 1/2] eliminando audio name de dto --- backend/src/pointOfInterest/dto/getPoint.dto.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/pointOfInterest/dto/getPoint.dto.ts b/backend/src/pointOfInterest/dto/getPoint.dto.ts index b4c41fb6..2a826ef0 100644 --- a/backend/src/pointOfInterest/dto/getPoint.dto.ts +++ b/backend/src/pointOfInterest/dto/getPoint.dto.ts @@ -5,5 +5,4 @@ export class getPointDto { imageName: string; content: string; directions: string; - audioName: string; } -- GitLab From 5875552e15a246971333f57e023ad382a5ff5aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:44:24 -0600 Subject: [PATCH 2/2] agregando endpoint para obtner un solo point por id --- .../PointOfInterest.controller.ts | 13 +++++--- .../PointOfInterest.service.ts | 33 ++++++++++++++++++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/backend/src/pointOfInterest/PointOfInterest.controller.ts b/backend/src/pointOfInterest/PointOfInterest.controller.ts index 746b9c5a..57c26d37 100644 --- a/backend/src/pointOfInterest/PointOfInterest.controller.ts +++ b/backend/src/pointOfInterest/PointOfInterest.controller.ts @@ -21,7 +21,7 @@ import { LANGUAGES } from 'src/shared/enum/languages.enum'; @Controller('') @ApiTags('Point of interest') export class PointOfInterestController { - constructor(private readonly activityService: PointOfInterestService) {} + constructor(private readonly pointService: PointOfInterestService) {} @ApiConsumes('multipart/form-data') @Roles(ADMIN_ROLES) @@ -31,7 +31,7 @@ export class PointOfInterestController { async create(@UploadedFile(new FileValidationPipe()) file, @Body() createActivityDto: CreatePointAndTradDto) { try { createActivityDto.image = file.filename; - return await this.activityService.create(createActivityDto); + return await this.pointService.create(createActivityDto); } catch (error) { throw error; } @@ -41,13 +41,18 @@ export class PointOfInterestController { @ApiParam({ name: 'idPlace', type: Number }) @Get('/place/:idPlace/point') async findAllByPlace(@Param('idPlace') idPlace: number, @Query('lang') lang: string) { - return this.activityService.findAllByPlace(idPlace, lang as LANGUAGES); + return this.pointService.findAllByPlace(idPlace, lang as LANGUAGES); } @ApiQuery({ name: 'lang', type: String }) @Get('point/:idPoint/audio') async getAudio(@Param('idPoint') idPoint: number, @Query('lang') lang: string): Promise { - const file = await this.activityService.getAudio(idPoint, lang as LANGUAGES); + const file = await this.pointService.getAudio(idPoint, lang as LANGUAGES); return file; } + + @Get('point/:idPoint?lang') + async findOne(@Param('idPoint') idPoint: number, @Query('lang') lang: string) { + return await this.pointService.findOne(idPoint, lang as LANGUAGES); + } } diff --git a/backend/src/pointOfInterest/PointOfInterest.service.ts b/backend/src/pointOfInterest/PointOfInterest.service.ts index 7b9f1db5..95cd7232 100644 --- a/backend/src/pointOfInterest/PointOfInterest.service.ts +++ b/backend/src/pointOfInterest/PointOfInterest.service.ts @@ -82,7 +82,6 @@ export class PointOfInterestService { imageName: `${ServerConstants.HOST}/points/${point.imageName}`, content: point.content, directions: point.directions, - audioName: `${ServerConstants.HOST}/audios/${point.audioName}`, }; }); return points; @@ -102,4 +101,36 @@ export class PointOfInterestService { } async createAudio() {} + + async findOne(idPoint: number, lang: LANGUAGES): Promise { + const pointTrad = await this.dataSource + .getRepository(PointOfInterestTraduction) + .createQueryBuilder('pointTrad') + .leftJoin('pointTrad.idPoint', 'point') + .select([ + 'point.idPoint as idPoint', + 'point.name as name', + 'point.imageName as imageName', + 'pointTrad.content as content', + 'pointTrad.directions as directions', + 'pointTrad.audioName as audioName', + 'point.idPlace as idPlace', + ]) + .where('point.idPoint = :idPoint', { idPoint }) + .andWhere('pointTrad.language = :lang', { lang }) + .getRawOne(); + if (!pointTrad) { + throw new NotFoundException('Point not found'); + } + + const point: getPointDto = { + idPoint: pointTrad.idPoint, + idPlace: pointTrad.idPlace, + name: pointTrad.name, + imageName: `${ServerConstants.HOST}/points/${pointTrad.imageName}`, + content: pointTrad.content, + directions: pointTrad.directions, + }; + return point; + } } -- GitLab