From d6d2eba4fbf1a50eed5098856c7e512185d69aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 30 Jul 2024 08:40:29 -0600 Subject: [PATCH 1/4] agregando resource route --- backend/src/app.module.ts | 6 ++++ backend/src/route/dto/create-route.dto.ts | 1 + backend/src/route/dto/update-route.dto.ts | 4 +++ backend/src/route/entities/route.entity.ts | 22 ++++++++++++++ backend/src/route/route.controller.ts | 34 ++++++++++++++++++++++ backend/src/route/route.module.ts | 9 ++++++ backend/src/route/route.service.ts | 26 +++++++++++++++++ 7 files changed, 102 insertions(+) create mode 100644 backend/src/route/dto/create-route.dto.ts create mode 100644 backend/src/route/dto/update-route.dto.ts create mode 100644 backend/src/route/entities/route.entity.ts create mode 100644 backend/src/route/route.controller.ts create mode 100644 backend/src/route/route.module.ts create mode 100644 backend/src/route/route.service.ts diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 6567c8b2..865af7f2 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -26,6 +26,9 @@ import { PointOfInterestTraduction } from './pointOfInterest/entities/PointOfInt import { PlaceTraduction } from './place/entities/place-traduction.entity'; import { CategoryModule } from './category/category.module'; import { Category } from './category/entities/category.entity'; +import { RouteModule } from './route/route.module'; +import { Route } from './route/entities/route.entity'; +import { TravelPlaceModule } from './travel-place/travel-place.module'; @Module({ imports: [ @@ -48,6 +51,7 @@ import { Category } from './category/entities/category.entity'; PointOfInterestTraduction, PlaceTraduction, Category, + Route, ], synchronize: DbConstants.DB_SYNC, logging: false, @@ -65,6 +69,8 @@ import { Category } from './category/entities/category.entity'; }), PointOfInterestModule, CategoryModule, + RouteModule, + TravelPlaceModule, ], controllers: [AppController], providers: [AppService, DatabaseSeederModule], diff --git a/backend/src/route/dto/create-route.dto.ts b/backend/src/route/dto/create-route.dto.ts new file mode 100644 index 00000000..12701626 --- /dev/null +++ b/backend/src/route/dto/create-route.dto.ts @@ -0,0 +1 @@ +export class CreateRouteDto {} diff --git a/backend/src/route/dto/update-route.dto.ts b/backend/src/route/dto/update-route.dto.ts new file mode 100644 index 00000000..ceeaf635 --- /dev/null +++ b/backend/src/route/dto/update-route.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/swagger'; +import { CreateRouteDto } from './create-route.dto'; + +export class UpdateRouteDto extends PartialType(CreateRouteDto) {} diff --git a/backend/src/route/entities/route.entity.ts b/backend/src/route/entities/route.entity.ts new file mode 100644 index 00000000..7916e7eb --- /dev/null +++ b/backend/src/route/entities/route.entity.ts @@ -0,0 +1,22 @@ +import { Town } from 'src/town/entities/town.entity'; +import { User } from 'src/user/entities/user.entity'; +import { PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Entity } from 'typeorm'; + +@Entity() +export class Route { + @PrimaryGeneratedColumn() + idRoute: number; + + @JoinColumn({ name: 'user' }) + @ManyToOne(() => User, (user) => user.email, { nullable: false }) + user: User; + + @JoinColumn({ name: 'town' }) + @ManyToOne(() => Town, (town) => town.townId, { nullable: false }) + town: Town; + + @Column({ nullable: false }) + startDate: Date; + @Column({ nullable: false }) + endDate: Date; +} diff --git a/backend/src/route/route.controller.ts b/backend/src/route/route.controller.ts new file mode 100644 index 00000000..53df1c43 --- /dev/null +++ b/backend/src/route/route.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { RouteService } from './route.service'; +import { CreateRouteDto } from './dto/create-route.dto'; +import { UpdateRouteDto } from './dto/update-route.dto'; + +@Controller('route') +export class RouteController { + constructor(private readonly routeService: RouteService) {} + + @Post() + create(@Body() createRouteDto: CreateRouteDto) { + return this.routeService.create(createRouteDto); + } + + @Get() + findAll() { + return this.routeService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.routeService.findOne(+id); + } + + @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); + } +} diff --git a/backend/src/route/route.module.ts b/backend/src/route/route.module.ts new file mode 100644 index 00000000..db6a819b --- /dev/null +++ b/backend/src/route/route.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { RouteService } from './route.service'; +import { RouteController } from './route.controller'; + +@Module({ + controllers: [RouteController], + providers: [RouteService], +}) +export class RouteModule {} diff --git a/backend/src/route/route.service.ts b/backend/src/route/route.service.ts new file mode 100644 index 00000000..4de7e5b8 --- /dev/null +++ b/backend/src/route/route.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@nestjs/common'; +import { CreateRouteDto } from './dto/create-route.dto'; +import { UpdateRouteDto } from './dto/update-route.dto'; + +@Injectable() +export class RouteService { + create(createRouteDto: CreateRouteDto) { + return 'This action adds a new route'; + } + + findAll() { + return `This action returns all route`; + } + + findOne(id: number) { + return `This action returns a #${id} route`; + } + + update(id: number, updateRouteDto: UpdateRouteDto) { + return `This action updates a #${id} route`; + } + + remove(id: number) { + return `This action removes a #${id} route`; + } +} -- GitLab From e1235f205f371c563cb0e1855eaff9ab5bda3e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:38:51 -0600 Subject: [PATCH 2/4] agregando travel-place resource --- .../dto/create-travel-place.dto.ts | 7 +++ .../dto/update-travel-place.dto.ts | 4 ++ .../entities/travel-place.entity.ts | 25 +++++++++++ .../travel-place/travel-place.controller.ts | 34 ++++++++++++++ .../src/travel-place/travel-place.module.ts | 14 ++++++ .../src/travel-place/travel-place.service.ts | 45 +++++++++++++++++++ 6 files changed, 129 insertions(+) create mode 100644 backend/src/travel-place/dto/create-travel-place.dto.ts create mode 100644 backend/src/travel-place/dto/update-travel-place.dto.ts create mode 100644 backend/src/travel-place/entities/travel-place.entity.ts create mode 100644 backend/src/travel-place/travel-place.controller.ts create mode 100644 backend/src/travel-place/travel-place.module.ts create mode 100644 backend/src/travel-place/travel-place.service.ts diff --git a/backend/src/travel-place/dto/create-travel-place.dto.ts b/backend/src/travel-place/dto/create-travel-place.dto.ts new file mode 100644 index 00000000..1f561717 --- /dev/null +++ b/backend/src/travel-place/dto/create-travel-place.dto.ts @@ -0,0 +1,7 @@ +export class CreateTravelPlaceDto { + idRoute: number; + idPlace: number; + startDate: Date; + endDate: Date; + done: boolean; +} diff --git a/backend/src/travel-place/dto/update-travel-place.dto.ts b/backend/src/travel-place/dto/update-travel-place.dto.ts new file mode 100644 index 00000000..6a2bd1a9 --- /dev/null +++ b/backend/src/travel-place/dto/update-travel-place.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/swagger'; +import { CreateTravelPlaceDto } from './create-travel-place.dto'; + +export class UpdateTravelPlaceDto extends PartialType(CreateTravelPlaceDto) {} diff --git a/backend/src/travel-place/entities/travel-place.entity.ts b/backend/src/travel-place/entities/travel-place.entity.ts new file mode 100644 index 00000000..5d095bd4 --- /dev/null +++ b/backend/src/travel-place/entities/travel-place.entity.ts @@ -0,0 +1,25 @@ +import { Place } from 'src/place/entities/place.entity'; +import { Route } from 'src/route/entities/route.entity'; +import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; + +@Entity() +export class TravelPlace { + @PrimaryGeneratedColumn() + travelPlaceId: number; + + @JoinColumn({ name: 'route' }) + @ManyToOne(() => Route, (route) => route.idRoute) + route: Route; + + @JoinColumn({ name: 'place' }) + @ManyToOne(() => Place, (place) => place.idPlace) + place: Place; + + @Column({ nullable: false }) + startDate: Date; + @Column({ nullable: false }) + endDate: Date; + + @Column({ nullable: false }) + done: boolean; +} diff --git a/backend/src/travel-place/travel-place.controller.ts b/backend/src/travel-place/travel-place.controller.ts new file mode 100644 index 00000000..01d13a96 --- /dev/null +++ b/backend/src/travel-place/travel-place.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { TravelPlaceService } from './travel-place.service'; +import { CreateTravelPlaceDto } from './dto/create-travel-place.dto'; +import { UpdateTravelPlaceDto } from './dto/update-travel-place.dto'; + +@Controller('travel-place') +export class TravelPlaceController { + constructor(private readonly travelPlaceService: TravelPlaceService) {} + + @Post() + create(@Body() createTravelPlaceDto: CreateTravelPlaceDto) { + return this.travelPlaceService.create(createTravelPlaceDto); + } + + @Get() + findAll() { + return this.travelPlaceService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.travelPlaceService.findOne(+id); + } + + @Patch(':id') + update(@Param('id') id: string, @Body() updateTravelPlaceDto: UpdateTravelPlaceDto) { + return this.travelPlaceService.update(+id, updateTravelPlaceDto); + } + + @Delete(':id') + remove(@Param('id') id: string) { + return this.travelPlaceService.remove(+id); + } +} diff --git a/backend/src/travel-place/travel-place.module.ts b/backend/src/travel-place/travel-place.module.ts new file mode 100644 index 00000000..0190fd57 --- /dev/null +++ b/backend/src/travel-place/travel-place.module.ts @@ -0,0 +1,14 @@ +import { Module } from '@nestjs/common'; +import { TravelPlaceService } from './travel-place.service'; +import { TravelPlaceController } from './travel-place.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { TravelPlace } from './entities/travel-place.entity'; +import { Place } from 'src/place/entities/place.entity'; +import { Route } from 'src/route/entities/route.entity'; + +@Module({ + controllers: [TravelPlaceController], + providers: [TravelPlaceService], + imports: [TypeOrmModule.forFeature([TravelPlace, Place, Route])], +}) +export class TravelPlaceModule {} diff --git a/backend/src/travel-place/travel-place.service.ts b/backend/src/travel-place/travel-place.service.ts new file mode 100644 index 00000000..0e6867b9 --- /dev/null +++ b/backend/src/travel-place/travel-place.service.ts @@ -0,0 +1,45 @@ +import { Injectable } from '@nestjs/common'; +import { CreateTravelPlaceDto } from './dto/create-travel-place.dto'; +import { UpdateTravelPlaceDto } from './dto/update-travel-place.dto'; +import { InjectRepository } from '@nestjs/typeorm'; +import { TravelPlace } from './entities/travel-place.entity'; +import { In, Repository } from 'typeorm'; +import { Place } from 'src/place/entities/place.entity'; +import { Route } from 'src/route/entities/route.entity'; + +@Injectable() +export class TravelPlaceService { + constructor( + @InjectRepository(TravelPlace) private travelPlaceRepository: Repository, + @InjectRepository(Place) private placeRepository: Repository, + @InjectRepository(Route) private routeRepository: Repository, + ) {} + + async create(createTravelPlaceDto: CreateTravelPlaceDto) { + const route = await this.routeRepository.findOneBy({ idRoute: createTravelPlaceDto.idRoute }); + const place = await this.placeRepository.findOneBy({ idPlace: createTravelPlaceDto.idPlace }); + await this.travelPlaceRepository.save({ + route, + place, + startDate: new Date(), + endDate: new Date(), + done: true, + }); + } + + findAll() { + return `This action returns all travelPlace`; + } + + findOne(id: number) { + return `This action returns a #${id} travelPlace`; + } + + update(id: number, updateTravelPlaceDto: UpdateTravelPlaceDto) { + return `This action updates a #${id} travelPlace`; + } + + remove(id: number) { + return `This action removes a #${id} travelPlace`; + } +} -- GitLab From 9ca10f4fe5c8e609226c74cce3ca03d85156c59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:39:54 -0600 Subject: [PATCH 3/4] agregando entidad travelPlace --- backend/src/app.module.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 865af7f2..84f2a6b0 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -29,6 +29,7 @@ import { Category } from './category/entities/category.entity'; import { RouteModule } from './route/route.module'; import { Route } from './route/entities/route.entity'; import { TravelPlaceModule } from './travel-place/travel-place.module'; +import { TravelPlace } from './travel-place/entities/travel-place.entity'; @Module({ imports: [ @@ -52,6 +53,7 @@ import { TravelPlaceModule } from './travel-place/travel-place.module'; PlaceTraduction, Category, Route, + TravelPlace, ], synchronize: DbConstants.DB_SYNC, logging: false, -- GitLab From 16d1eba9b1442dcb1dc5a912854f922830a42fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:40:20 -0600 Subject: [PATCH 4/4] pruebas para crear una ruta --- backend/src/route/dto/create-route.dto.ts | 10 +++++- backend/src/route/entities/route.entity.ts | 6 +++- backend/src/route/route.controller.ts | 18 +++++++---- backend/src/route/route.module.ts | 24 +++++++++++++- backend/src/route/route.service.ts | 37 +++++++++++++++++++--- 5 files changed, 81 insertions(+), 14 deletions(-) diff --git a/backend/src/route/dto/create-route.dto.ts b/backend/src/route/dto/create-route.dto.ts index 12701626..ecb0704b 100644 --- a/backend/src/route/dto/create-route.dto.ts +++ b/backend/src/route/dto/create-route.dto.ts @@ -1 +1,9 @@ -export class CreateRouteDto {} +import { Town } from 'src/town/entities/town.entity'; +import { User } from 'src/user/entities/user.entity'; + +export class CreateRouteDto { + user: User; + town: Town; + startDate: Date; + endDate: Date; +} diff --git a/backend/src/route/entities/route.entity.ts b/backend/src/route/entities/route.entity.ts index 7916e7eb..764c18ff 100644 --- a/backend/src/route/entities/route.entity.ts +++ b/backend/src/route/entities/route.entity.ts @@ -1,6 +1,7 @@ import { Town } from 'src/town/entities/town.entity'; +import { TravelPlace } from 'src/travel-place/entities/travel-place.entity'; import { User } from 'src/user/entities/user.entity'; -import { PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Entity } from 'typeorm'; +import { PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Entity, OneToMany } from 'typeorm'; @Entity() export class Route { @@ -15,6 +16,9 @@ export class Route { @ManyToOne(() => Town, (town) => town.townId, { nullable: false }) town: Town; + @OneToMany(() => TravelPlace, (travelPlace) => travelPlace.route) + travelPlace: TravelPlace[]; + @Column({ nullable: false }) startDate: Date; @Column({ nullable: false }) diff --git a/backend/src/route/route.controller.ts b/backend/src/route/route.controller.ts index 53df1c43..fc7d8394 100644 --- a/backend/src/route/route.controller.ts +++ b/backend/src/route/route.controller.ts @@ -1,15 +1,19 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } 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'; -@Controller('route') +@Controller('Route') +@ApiTags('testing') export class RouteController { constructor(private readonly routeService: RouteService) {} @Post() - create(@Body() createRouteDto: CreateRouteDto) { - return this.routeService.create(createRouteDto); + @ApiConsumes('multipart/form-data') + // @UseGuards(AuthUserGuard) + async create(@Body() createRouteDto: CreateRouteDto) { + return await this.routeService.create(); } @Get() @@ -17,9 +21,9 @@ export class RouteController { return this.routeService.findAll(); } - @Get(':id') - findOne(@Param('id') id: string) { - return this.routeService.findOne(+id); + @Get(':idRoute') + async findOne(@Param('idRoute') idRoute: number) { + return await this.routeService.findOne(idRoute); } @Patch(':id') diff --git a/backend/src/route/route.module.ts b/backend/src/route/route.module.ts index db6a819b..a9bacc34 100644 --- a/backend/src/route/route.module.ts +++ b/backend/src/route/route.module.ts @@ -1,9 +1,31 @@ import { Module } from '@nestjs/common'; import { RouteService } from './route.service'; import { RouteController } from './route.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { Route } from './entities/route.entity'; +import { AuthUserService } from 'src/auth/user/authUserservice'; +import { UserService } from 'src/user/user.service'; +import { JwtService } from '@nestjs/jwt'; +import { EncryptionService } from 'src/auth/encryption/encryption.service'; +import { User } from 'src/user/entities/user.entity'; +import { CategoryService } from 'src/category/category.service'; +import { Category } from 'src/category/entities/category.entity'; +import { Town } from 'src/town/entities/town.entity'; +import { TravelPlace } from 'src/travel-place/entities/travel-place.entity'; +import { TravelPlaceService } from 'src/travel-place/travel-place.service'; +import { Place } from 'src/place/entities/place.entity'; @Module({ controllers: [RouteController], - providers: [RouteService], + providers: [ + RouteService, + AuthUserService, + UserService, + JwtService, + EncryptionService, + CategoryService, + TravelPlaceService, + ], + imports: [TypeOrmModule.forFeature([Route, User, Category, Town, TravelPlace, Place])], }) export class RouteModule {} diff --git a/backend/src/route/route.service.ts b/backend/src/route/route.service.ts index 4de7e5b8..51c2f121 100644 --- a/backend/src/route/route.service.ts +++ b/backend/src/route/route.service.ts @@ -1,19 +1,48 @@ import { Injectable } from '@nestjs/common'; import { CreateRouteDto } from './dto/create-route.dto'; import { UpdateRouteDto } from './dto/update-route.dto'; +import { InjectDataSource, InjectRepository } from '@nestjs/typeorm'; +import { Route } from './entities/route.entity'; +import { DataSource, In, Repository } from 'typeorm'; +import { User } from 'src/user/entities/user.entity'; +import { Town } from 'src/town/entities/town.entity'; +import { TravelPlaceService } from 'src/travel-place/travel-place.service'; +import { TravelPlace } from 'src/travel-place/entities/travel-place.entity'; @Injectable() export class RouteService { - create(createRouteDto: CreateRouteDto) { - return 'This action adds a new route'; + constructor( + @InjectRepository(Route) private routeRepository: Repository, + @InjectRepository(User) private userRepository: Repository, + @InjectRepository(Town) private townRepository: Repository, + private readonly travelPlaceService: TravelPlaceService, + @InjectDataSource() private dataSource: DataSource, + ) {} + async create() { + const user: User = await this.userRepository.findOneBy({ userId: 1 }); + const town: Town = await this.townRepository.findOneBy({ townId: 1 }); + await this.routeRepository.save({ user, town, startDate: new Date(), endDate: new Date() }); + await this.travelPlaceService.create({ + idRoute: 1, + idPlace: 1, + startDate: new Date(), + endDate: new Date(), + done: true, + }); } findAll() { return `This action returns all route`; } - findOne(id: number) { - return `This action returns a #${id} route`; + async findOne(id: number) { + const res: any[] = await this.dataSource + .getRepository(Route) + .createQueryBuilder('route') + .leftJoinAndSelect('route.travelPlace', 'travelPlace') + .getMany(); + + return res; } update(id: number, updateRouteDto: UpdateRouteDto) { -- GitLab