This API provides endpoints to manage the "My List" feature for an OTT platform. Users can add their favorite movies and TV shows to a personalized list, remove items from the list, and retrieve their list with pagination and caching optimizations.
$ pnpm install
# development
$ pnpm run start
# watch mode
$ pnpm run start:dev
# e2e tests
$ pnpm run test:e2e
- Added scripts to insert default records for User, Movie and TvShows. Make sure to make changes for testing and dev environment.
$ pnpm run add:users
$ pnpm run add:movies
$ pnpm run add:tvshows
- Check .env.dev and .env.test for variables for MongoURI.
Users: [6654135df8b78768eae0296b, 6654135df8b78768eae0296d]
Movies: [665413819d2ed6292ca16064, 665413819d2ed6292ca16065, 665413819d2ed6292ca16066]
TVShows: [6654138bd9423b0d534ffaf0, 6654138bd9423b0d534ffaf3, 6654138bd9423b0d534ffaf6]
- Ensure to install mongodb and redis which can run locally on default port. You can use docker and expose default port.
Endpoint:
POST /my-list/add/list
Description:
- Adds a movie or TV show to the user's list. Headers:
Content-Type: application/json
userId: 6654135df8b78768eae0296b
Request Body:
{
"contentId": "664f2790bd0129b14fe238ae",
"contentType": "TVShow"
}
Endpoint
POST /my-list/remove/list
Description:
- Removes a movie or TV show from the user's list. Headers:
Content-Type: application/json
userId: 6654135df8b78768eae0296b
Request Body:
{
"contentId": "664f2790bd0129b14fe238ae"
}
Response:
200 OK - Item successfully removed from the list.
400 Bad Request - Invalid request parameters.
500 Internal Server Error - An error occurred while processing the request.
Endpoint
GET /my-list/user/list?page=1&limit=10
Description:
- Retrieves the items in the user's list with pagination and caching optimizations.
Headers:
userId: 6654135df8b78768eae0296b
Query Parameters:
page (optional) - Page number for pagination. Default is 1.
limit (optional) - Number of items per page. Default is 10.
Response:
200 OK - List of items in the user's list.
400 Bad Request - Invalid request parameters.
500 Internal Server Error - An error occurred while processing the request.
Separate schemas for User, Movie, TVShow, and MyList. Indexes on userId in MyList for efficient querying.
- Used indexes and minimzed the necessary response.
- Caching to store the already fetched MyList information of the user.
- We can use mongodb sharding and cluster module
- Pagination used for listing items to fast and limited retreival.
- Basic user authentication is in place.
- Assumed already stored information is valid, skipped extra validation to find records on db
- MongoDB is used as the primary database.
- Not found enough time for deployment. [Skipped that part]
- Meets all functional requirements.
- Code Quality: Tried to write modular and cleaner code.
- Added validation for input.
- Well-designed API, database schema, and caching strategy.
- Integration Test written due to time limitation, few were remained.
- Could write the unite test cases, if got time.
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Nest is MIT licensed.