From 916d3fd6ba359304bc5048203adf1d7e6a82d060 Mon Sep 17 00:00:00 2001 From: Toast Date: Tue, 21 Jan 2025 21:22:31 +0100 Subject: [PATCH] Add show crud Basically the result of running nest g resource shows --no-spec I did add the schema manually, and removed the update dto --- src/app.module.ts | 7 +++- src/shows/dto/show.dto.ts | 1 + src/shows/entities/show.entity.ts | 1 + src/shows/schema/show.schema/show.schema.ts | 1 + src/shows/shows.controller.ts | 41 +++++++++++++++++++++ src/shows/shows.module.ts | 9 +++++ src/shows/shows.service.ts | 25 +++++++++++++ 7 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/shows/dto/show.dto.ts create mode 100644 src/shows/entities/show.entity.ts create mode 100644 src/shows/schema/show.schema/show.schema.ts create mode 100644 src/shows/shows.controller.ts create mode 100644 src/shows/shows.module.ts create mode 100644 src/shows/shows.service.ts diff --git a/src/app.module.ts b/src/app.module.ts index f3c70cc..7dc1458 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -3,9 +3,14 @@ import { AppController } from './app.controller'; import { AppService } from './app.service'; import { ConfigModule } from '@nestjs/config'; import { MongooseModule } from '@nestjs/mongoose'; +import { ShowsModule } from './shows/shows.module'; @Module({ - imports: [ConfigModule.forRoot(), MongooseModule.forRoot(process.env.URI)], + imports: [ + ConfigModule.forRoot(), + MongooseModule.forRoot(process.env.URI), + ShowsModule, + ], controllers: [AppController], providers: [AppService], }) diff --git a/src/shows/dto/show.dto.ts b/src/shows/dto/show.dto.ts new file mode 100644 index 0000000..32a14c7 --- /dev/null +++ b/src/shows/dto/show.dto.ts @@ -0,0 +1 @@ +export class ShowDto {} diff --git a/src/shows/entities/show.entity.ts b/src/shows/entities/show.entity.ts new file mode 100644 index 0000000..ae469be --- /dev/null +++ b/src/shows/entities/show.entity.ts @@ -0,0 +1 @@ +export class Show {} diff --git a/src/shows/schema/show.schema/show.schema.ts b/src/shows/schema/show.schema/show.schema.ts new file mode 100644 index 0000000..2597c9d --- /dev/null +++ b/src/shows/schema/show.schema/show.schema.ts @@ -0,0 +1 @@ +export class ShowSchema {} diff --git a/src/shows/shows.controller.ts b/src/shows/shows.controller.ts new file mode 100644 index 0000000..5b5a2ee --- /dev/null +++ b/src/shows/shows.controller.ts @@ -0,0 +1,41 @@ +import { + Controller, + Get, + Post, + Body, + Patch, + Param, + Delete, +} from '@nestjs/common'; +import { ShowsService } from './shows.service'; +import { ShowDto } from './dto/show.dto'; + +@Controller('shows') +export class ShowsController { + constructor(private readonly showsService: ShowsService) {} + + @Post() + create(@Body() dto: ShowDto) { + return this.showsService.create(dto); + } + + @Get() + findAll() { + return this.showsService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.showsService.findOne(+id); + } + + @Patch(':id') + update(@Param('id') id: string, @Body() dto: ShowDto) { + return this.showsService.update(+id, dto); + } + + @Delete(':id') + remove(@Param('id') id: string) { + return this.showsService.remove(+id); + } +} diff --git a/src/shows/shows.module.ts b/src/shows/shows.module.ts new file mode 100644 index 0000000..3d1ea15 --- /dev/null +++ b/src/shows/shows.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { ShowsService } from './shows.service'; +import { ShowsController } from './shows.controller'; + +@Module({ + controllers: [ShowsController], + providers: [ShowsService], +}) +export class ShowsModule {} diff --git a/src/shows/shows.service.ts b/src/shows/shows.service.ts new file mode 100644 index 0000000..f433f4c --- /dev/null +++ b/src/shows/shows.service.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@nestjs/common'; +import { ShowDto } from './dto/show.dto'; + +@Injectable() +export class ShowsService { + create(dto: ShowDto) { + return 'This action adds a new show'; + } + + findAll() { + return `This action returns all shows`; + } + + findOne(id: number) { + return `This action returns a #${id} show`; + } + + update(id: number, dto: ShowDto) { + return `This action updates a #${id} show`; + } + + remove(id: number) { + return `This action removes a #${id} show`; + } +}