diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 6567c8b2ae61cbe884c708aafe07e7cd6bdb44b3..84f2a6b0ab399a63519caeeeb1c174e93f3faa03 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -26,6 +26,10 @@ 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'; +import { TravelPlace } from './travel-place/entities/travel-place.entity'; @Module({ imports: [ @@ -48,6 +52,8 @@ import { Category } from './category/entities/category.entity'; PointOfInterestTraduction, PlaceTraduction, Category, + Route, + TravelPlace, ], synchronize: DbConstants.DB_SYNC, logging: false, @@ -65,6 +71,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 0000000000000000000000000000000000000000..ecb0704b9ea2863d76f455f2bc2ca9df238651fc --- /dev/null +++ b/backend/src/route/dto/create-route.dto.ts @@ -0,0 +1,9 @@ +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/dto/update-route.dto.ts b/backend/src/route/dto/update-route.dto.ts new file mode 100644 index 0000000000000000000000000000000000000000..ceeaf63557de198ca21e7465bdd79b16e3c6b626 --- /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 0000000000000000000000000000000000000000..764c18ff0c4effaca3f49419b2eef317542ba27a --- /dev/null +++ b/backend/src/route/entities/route.entity.ts @@ -0,0 +1,26 @@ +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, OneToMany } 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; + + @OneToMany(() => TravelPlace, (travelPlace) => travelPlace.route) + travelPlace: TravelPlace[]; + + @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 0000000000000000000000000000000000000000..fc7d8394cb8e0ce28390c2a2b8b68dadc739c98e --- /dev/null +++ b/backend/src/route/route.controller.ts @@ -0,0 +1,38 @@ +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') +@ApiTags('testing') +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(); + } + + @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); + } + + @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 0000000000000000000000000000000000000000..a9bacc34170c7d85d2420bbeaba7dd237f2f97ab --- /dev/null +++ b/backend/src/route/route.module.ts @@ -0,0 +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, + 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 new file mode 100644 index 0000000000000000000000000000000000000000..51c2f121e1a8b8a644993700fc5e05722deeac4f --- /dev/null +++ b/backend/src/route/route.service.ts @@ -0,0 +1,55 @@ +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 { + 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`; + } + + 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) { + return `This action updates a #${id} route`; + } + + remove(id: number) { + return `This action removes a #${id} route`; + } +} 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 0000000000000000000000000000000000000000..1f5617175a4dc1ff7d17b4ddea8e767f3dbd495e --- /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 0000000000000000000000000000000000000000..6a2bd1a9149a06f05fe8ef6e25e79806b8a2d471 --- /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 0000000000000000000000000000000000000000..5d095bd4cbade1f8d9144ad7ea4589af72e46619 --- /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 0000000000000000000000000000000000000000..01d13a967e6bb23e1ac0eef78459a9d43c4445af --- /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 0000000000000000000000000000000000000000..0190fd57f08031a14442210933f66c86fb4fa1df --- /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 0000000000000000000000000000000000000000..0e6867b95f1205377f9959801e543020cc1ffd19 --- /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`; + } +}