Skip to content
Snippets Groups Projects
movies.controller.ts 1.8 KiB
Newer Older
import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { MoviesService } from './movies.service';
import { CreateMovieDto } from './dto/create-movie.dto';
import { UpdateMovieDto } from './dto/update-movie.dto';
import { MovieEntity } from './entities/movie.entity';
import { AuthorizationGuard } from '../../authorization/authorization.guard';
@Controller('movies')
export class MoviesController {
  constructor(private readonly moviesService: MoviesService) {}

  @Post()
  async create(@Body() createMovieDto: CreateMovieDto): Promise<MovieEntity> {
    return await this.moviesService.create(createMovieDto);
  }

  @Get()
  async findAll(@Query() query: MoviesQuery): Promise<MovieEntity[]> {
    return await this.moviesService.findAll(query);
  }

  @Get(':id')
  async findOne(@Param('id') id: string): Promise<MovieEntity> {
    return await this.moviesService.findOne(id);
  }

  @Patch(':id/:categoryName')
  @ApiOperation({ summary: 'Add category to a movie' })
  async addCategory(
    @Param('id') id: string,
    @Param('categoryName') categoryName: string,
  ): Promise<MovieEntity> {
    return await this.moviesService.addCategory(id, categoryName);
  }

  @Patch(':id')
  async update(
    @Param('id') id: string,
    @Body() updateMovieDto: UpdateMovieDto,
  ): Promise<MovieEntity> {
    return await this.moviesService.update(id, updateMovieDto);
  }

  @Delete(':id')
  async remove(@Param('id') id: string): Promise<MovieEntity> {
    return await this.moviesService.remove(id);
  }
}