This project is a NestJS application that interacts with The Movie Database (TMDB) API to manage movie data. It integrates GraphQL for querying data and uses Mongoose for MongoDB interactions. It includes full Docker support for both development and testing environments.
- Features
- Prerequisites
- Installation
- Running the Application with Docker
- API Documentation
- Testing
- Endpoints
- Additional Information
- REST API and GraphQL endpoints for movie data management.
- CSRF token generation and management.
- Swagger API documentation.
- Integration with TMDB API for fetching movie details.
- Dockerized environment setup for development and testing.
- Rate limiting with custom throttling guards.
- Response transformation with interceptors.
- Docker
- Docker Compose
Clone the repository:
git clone https://github.com/remidosol/tmdb-nestjs.git
cd tmdb-nestjs
Ensure Docker and Docker Compose are installed and then run:
docker compose up -d --build
This command will build the Docker image if it's not already built and start all services defined in docker-compose.yml
, including the NestJS application and MongoDB.
The Swagger documentation can be accessed at:
http://localhost:3333/api
The GraphQL Playground documentation can be accessed at:
http://localhost:3333/graphql
Ensure that you have a .env file located in <rootDir>/secrets/.env
. This file should contain all the necessary environment variables required by the application.
Create a .env file in the secrets directory with the following variables:
DATABASE_URL=""
TMDB_API_KEY=""
TMDB_READ_ACCESS_TOKEN=""
To run the tests within the Docker environment, use the following Docker Compose command:
docker compose run tmdb_nestjs yarn test
For end to end tests, use:
docker compose run tmdb_nestjs yarn test:e2e
This command executes the tests inside the Docker container, ensuring that the testing environment is consistent with the development setup.
- POST /csrf: Generate CSRF token
- GET /main_goal: Fetch and persist top 5 movies from TMDB
- GET /movie: Get all movies with optional sorting
- GET /movie/:movieId: Get movie by ID
- POST /movie: Create a new movie
- DELETE /movie/:movieId: Delete a movie by ID
- findById(id: String!): Movie: Find a movie by ID
Example GraphQL query to execute in the playground:
query GetMovieById($id: String!) {
findById(id: $id) {
id
name
overview
releaseDate
voteAverage
voteCount
genres {
id
name
}
popularity
}
}
Example id:
{
"id": "12345"
}
Find more detailed documentation on each endpoint in the Swagger UI or the GraphQL Playground.
- MongoDB: This application uses Mongoose to interact with MongoDB.
- CSRF Protection: Implemented using CSRF tokens.
- Throttling: Rate limiting is enforced using custom throttling guards.
- Interceptors: Used for transforming responses.