diff --git a/backend/src/place/place.controller.ts b/backend/src/place/place.controller.ts index 0a7ef30775bf8e0c47dd1022a30c5f540bdd3a8f..f8d9c2e28b2ab321f523995829c2644ef72285b3 100644 --- a/backend/src/place/place.controller.ts +++ b/backend/src/place/place.controller.ts @@ -1,18 +1,6 @@ -import { - Controller, - Get, - Post, - Body, - Patch, - Param, - Delete, - UseInterceptors, - UploadedFile, - Query, -} from '@nestjs/common'; +import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query } from '@nestjs/common'; import { PlaceService } from './place.service'; import { CreatePlaceDateTradDto } from './dto/create-place-date.dto'; -import { UpdatePlaceDto } from './dto/update-place.dto'; import { ApiBearerAuth, ApiBody, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; import { Roles } from 'src/auth/role.decorator'; import { ADMIN_ROLES } from 'src/shared/enum/admin-role.enum'; @@ -38,7 +26,7 @@ export class PlaceController { @ApiQuery({ name: 'lang', type: String }) @ApiParam({ name: 'idTown', type: Number }) - @Get('/town/:idTown/activity') + @Get('/town/:idTown/place') async findAll(@Param('idTown') idTown: number, @Query('lang') lang: string) { try { return this.placeService.findAllByTown(idTown, lang as LANGUAGES); @@ -51,14 +39,4 @@ export class PlaceController { findOne(@Param('id') id: string) { return this.placeService.findOne(+id); } - - @Patch(':id') - update(@Param('id') id: string, @Body() updatePlaceDto: UpdatePlaceDto) { - return this.placeService.update(+id, updatePlaceDto); - } - - @Delete(':id') - remove(@Param('id') id: string) { - return this.placeService.remove(+id); - } } diff --git a/backend/src/place/place.service.ts b/backend/src/place/place.service.ts index 2f0faf1b66bbaab25155d719d00918408e80829e..693269968f6c94aee14e3f94381775f2f6cbeff6 100644 --- a/backend/src/place/place.service.ts +++ b/backend/src/place/place.service.ts @@ -1,6 +1,5 @@ import { BadRequestException, Injectable } from '@nestjs/common'; import { CreatePlaceDateTradDto } from './dto/create-place-date.dto'; -import { UpdatePlaceDto } from './dto/update-place.dto'; import { InjectDataSource, InjectRepository } from '@nestjs/typeorm'; import { Place } from './entities/place.entity'; import { DataSource, Repository } from 'typeorm'; @@ -107,12 +106,4 @@ export class PlaceService { const place = await this.placeRepository.findOneBy({ idPlace: id }); return place; } - - update(id: number, updatePlaceDto: UpdatePlaceDto) { - return `This action updates a #${id} place`; - } - - remove(id: number) { - return `This action removes a #${id} place`; - } } diff --git a/backend/src/pointOfInterest/PointOfInterest.controller.ts b/backend/src/pointOfInterest/PointOfInterest.controller.ts index 979398af38efee4ffbea554636a7ab08b8204b7e..67ba26c17e63341777fcb0d7aa32e249ce0806ae 100644 --- a/backend/src/pointOfInterest/PointOfInterest.controller.ts +++ b/backend/src/pointOfInterest/PointOfInterest.controller.ts @@ -1,14 +1,14 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseInterceptors, UploadedFile } from '@nestjs/common'; +import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query } from '@nestjs/common'; import { PointOfInterestService } from './PointOfInterest.service'; import { CreatePointAndTradDto } from './dto/create-pointAndTraduction.dto'; -import { UpdatePointDto } from './dto/update-point.dto'; -import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger'; +import { ApiBearerAuth, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; import { Roles } from 'src/auth/role.decorator'; import { ADMIN_ROLES } from 'src/shared/enum/admin-role.enum'; import { fileInterceptor } from 'src/shared/interceptors/file-save.interceptor'; import { FileValidationPipe } from 'src/shared/pipe/file-validation.pipe'; +import { LANGUAGES } from 'src/shared/enum/languages.enum'; -@Controller('point') +@Controller('') @ApiTags('Point of interest') export class PointOfInterestController { constructor(private readonly activityService: PointOfInterestService) {} @@ -16,7 +16,7 @@ export class PointOfInterestController { @ApiConsumes('multipart/form-data') @Roles(ADMIN_ROLES) @ApiBearerAuth('jwt') - @Post() + @Post('point') @UseInterceptors(fileInterceptor('image', 'static/points/', ['.jpg', '.jpeg', '.png'])) async create(@UploadedFile(new FileValidationPipe()) file, @Body() createActivityDto: CreatePointAndTradDto) { try { @@ -27,23 +27,19 @@ export class PointOfInterestController { } } - @Get() - findAll() { - return this.activityService.findAll(); + @ApiQuery({ name: 'lang', type: String }) + @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); } - @Get(':id') - findOne(@Param('id') id: string) { - return this.activityService.findOne(+id); - } - - @Patch(':id') - update(@Param('id') id: string, @Body() updateActivityDto: UpdatePointDto) { - return this.activityService.update(+id, updateActivityDto); - } - - @Delete(':id') - remove(@Param('id') id: string) { - return this.activityService.remove(+id); + @ApiQuery({ name: 'lang', type: String }) + @Get('point/:idPoint/audio') + async getAudio( + @Param('idPoint') idPoint: number, + @Query('lang') lang: string, + ): Promise> { + return this.activityService.getAudio(idPoint, lang as LANGUAGES); } } diff --git a/backend/src/pointOfInterest/PointOfInterest.service.ts b/backend/src/pointOfInterest/PointOfInterest.service.ts index b7184a8ab240a66bcd4ef462acaa9b2fa32e7221..5710391436588c40a21eb1a354f9bc2d26ad620c 100644 --- a/backend/src/pointOfInterest/PointOfInterest.service.ts +++ b/backend/src/pointOfInterest/PointOfInterest.service.ts @@ -1,14 +1,16 @@ -import { BadRequestException, Injectable } from '@nestjs/common'; +import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'; import { CreatePointAndTradDto } from './dto/create-pointAndTraduction.dto'; -import { UpdatePointDto } from './dto/update-point.dto'; -import { InjectRepository } from '@nestjs/typeorm'; +import { InjectDataSource, InjectRepository } from '@nestjs/typeorm'; import { PointOfInterest } from './entities/PointOfInterest.entity'; -import { Repository } from 'typeorm'; +import { DataSource, Repository } from 'typeorm'; import { PointOfInterestTraduction } from './entities/PointOfInterestTraduction.entity'; import { CreatePointDto } from './dto/create-point.dto'; import { PlaceService } from 'src/place/place.service'; import { CreatePointTradDto } from './dto/create-pointTrad.dto'; import { LANGUAGES } from 'src/shared/enum/languages.enum'; +import { getPointDto } from './dto/getPoint.dto'; +import { ServerConstants } from 'src/constants/server.contants'; +import { createReadStream } from 'fs'; @Injectable() export class PointOfInterestService { @@ -16,6 +18,7 @@ export class PointOfInterestService { @InjectRepository(PointOfInterest) private pointRepository: Repository, @InjectRepository(PointOfInterestTraduction) private pointTraductionRepository, private readonly placeService: PlaceService, + @InjectDataSource() private dataSource: DataSource, ) {} async create(createPointAndTradDto: CreatePointAndTradDto) { const place = await this.placeService.findOne(createPointAndTradDto.idPlace); @@ -33,7 +36,7 @@ export class PointOfInterestService { idPoint: insertedId, language: LANGUAGES.EN, content: createPointAndTradDto.contentEN, - audioName: 'audioName', + audioName: 'default.mp3', directions: createPointAndTradDto.directionsEN, }; @@ -41,26 +44,55 @@ export class PointOfInterestService { idPoint: insertedId, language: LANGUAGES.ES, content: createPointAndTradDto.contentES, - audioName: 'audioName', + audioName: 'default.mp3', directions: createPointAndTradDto.directionsES, }; await this.pointTraductionRepository.insert(createTradEs); await this.pointTraductionRepository.insert(createTradEn); } - findAll() { - return `This action returns all activity`; - } - - findOne(id: number) { - return `This action returns a #${id} activity`; - } + async findAllByPlace(idPlace: number, lang: LANGUAGES): Promise { + const place = await this.placeService.findOne(idPlace); + if (!place) { + throw new BadRequestException('Place not found'); + } + let points: getPointDto[] = 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.idPlace = :idPlace', { idPlace }) + .andWhere('pointTrad.language = :lang', { lang }) + .getRawMany(); - update(id: number, updateActivityDto: UpdatePointDto) { - return `This action updates a #${id} activity`; + points = points.map((point) => { + return { + idPoint: point.idPoint, + idPlace: point.idPlace, + name: point.name, + imageName: `${ServerConstants.HOST}/points/${point.imageName}`, + content: point.content, + directions: point.directions, + audioName: `${ServerConstants.HOST}/audios/${point.audioName}`, + }; + }); + return points; } - remove(id: number) { - return `This action removes a #${id} activity`; + async getAudio(idPoint: number, lang: LANGUAGES): Promise { + const pointTrad = await this.pointTraductionRepository.findOneBy({ idPoint, language: lang }); + if (!pointTrad) { + throw new NotFoundException('Point not found'); + } + const filePath = `${ServerConstants.HOST}/audios/${pointTrad.audioName}`; + return createReadStream(filePath); } } diff --git a/backend/src/pointOfInterest/dto/getPoint.dto.ts b/backend/src/pointOfInterest/dto/getPoint.dto.ts new file mode 100644 index 0000000000000000000000000000000000000000..b4c41fb61e668688559b5e96651a20407580cc13 --- /dev/null +++ b/backend/src/pointOfInterest/dto/getPoint.dto.ts @@ -0,0 +1,9 @@ +export class getPointDto { + idPoint: number; + idPlace: number; + name: string; + imageName: string; + content: string; + directions: string; + audioName: string; +} diff --git a/backend/src/town/town.controller.ts b/backend/src/town/town.controller.ts index a8767c9ae50df240d70d132ef33235dd9707ac65..f0028d14750800aaae38c2873c65349a576eff6a 100644 --- a/backend/src/town/town.controller.ts +++ b/backend/src/town/town.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Param, Delete, UseInterceptors, UploadedFile, Body, Query } from '@nestjs/common'; +import { Controller, Get, Post, Param, UseInterceptors, UploadedFile, Body, Query } from '@nestjs/common'; import { TownService } from './town.service'; import { ApiBearerAuth, ApiBody, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; import { FileValidationPipe } from 'src/shared/pipe/file-validation.pipe'; @@ -37,14 +37,4 @@ export class TownController { throw error; } } - - @Get() - findAll() { - return this.townService.findAll(); - } - - @Delete(':id') - remove(@Param('id') id: string) { - return this.townService.remove(+id); - } } diff --git a/backend/src/town/town.service.ts b/backend/src/town/town.service.ts index badd465d4d2a1efd248461b57c438832d0631b05..c4d5ef95febab420a45a49da7c3d38e8460de372 100644 --- a/backend/src/town/town.service.ts +++ b/backend/src/town/town.service.ts @@ -69,12 +69,4 @@ export class TownService { stateId: item.stateId, })); } - - findAll() { - return `This action returns all town`; - } - - remove(id: number) { - return `This action removes a #${id} town`; - } } diff --git a/backend/static/audios/default.mp3 b/backend/static/audios/default.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..daf789f55d1e091af6dfb6982bf137ed623eefe2 Binary files /dev/null and b/backend/static/audios/default.mp3 differ