Members
(constant) Movies :mongoose.Model
Movie model from mongoose schemas
Type:
- mongoose.Model
(constant) Users :mongoose.Model
User model from mongoose schemas
Type:
- mongoose.Model
allowedOrigins :Array.<string>
List of allowed origins for CORS policy
Type:
- Array.<string>
(constant) app :Express
Express application instance
Type:
- Express
Methods
addToFavorites() → {object}
- Add a movie to user's list of favorite movies
Parameters:
Type | Description |
---|---|
Query_Parameters | :username, :movieId |
authentication | Bearer token (JWT) |
Returns:
- Updated user object
- Type
- object
Example
// Response data format
{
"_id": "507f1f77bcf86cd799439011",
"Username": "johndoe",
"Email": "john@example.com",
"FavoriteMovies": ["507f1f77bcf86cd799439012", "507f1f77bcf86cd799439013"]
}
advancedSearch() → {object}
- Advanced search with multiple filters
Parameters:
Type | Description |
---|---|
Query_Parameters | ?title=&genre=&director=&actor=&year= |
authentication | Bearer token (JWT) |
Returns:
- Search results object with filters applied
- Type
- object
Example
// Response data format
{
"filters": {
"title": "shawshank",
"genre": "drama"
},
"results": [
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption"
}
],
"count": 1
}
deleteUser() → {object}
- Delete a user account
Parameters:
Type | Description |
---|---|
Query_Parameters | :username |
authentication | Bearer token (JWT) |
Returns:
- Deletion confirmation message
- Type
- object
Example
// Response data format
{
"message": "johndoe was deleted."
}
generalSearch() → {object}
- General search endpoint - searches across multiple fields
Parameters:
Type | Description |
---|---|
Query_Parameters | ?q=searchQuery |
authentication | Bearer token (JWT) |
Returns:
- Search results object with query, results array, and count
- Type
- object
Example
// Response data format
{
"query": "drama",
"results": [
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption"
}
],
"count": 1
}
generateJWTToken(user) → {string}
Generates a JWT token for authenticated users
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
user |
Object | User object containing user information
Properties
|
Returns:
JWT token valid for 7 days
- Type
- string
getAllActors() → {Array}
- Get all unique actors
Parameters:
Type | Description |
---|---|
authentication | Bearer token (JWT) |
Returns:
- Array of actor names
- Type
- Array
Example
// Response data format
["Tim Robbins", "Morgan Freeman", "Tom Hanks"]
getAllActresses() → {object}
- Get all unique actress names
Parameters:
Type | Description |
---|---|
authentication | Bearer token (JWT) |
Returns:
- Object containing array of actress names
- Type
- object
Example
// Response data format
{
"actresses": ["Actress 1", "Actress 2"]
}
getAllGenres() → {Array}
- Get all genres
Parameters:
Type | Description |
---|---|
authentication | Bearer token (JWT) |
Returns:
- Array of all genre objects
- Type
- Array
Example
// Response data format
[
{
"_id": "Drama",
"description": "Drama is a category of narrative fiction..."
}
]
getAllMovies() → {Array}
- Return a list of ALL movies to the user
Parameters:
Type | Description |
---|---|
authentication | Bearer token (JWT) |
Returns:
- Array of all movie objects
- Type
- Array
Example
// Response data format
[
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption",
"Description": "Two imprisoned men bond over years...",
"Genre": {
"Name": "Drama",
"Description": "Drama genre description"
},
"Director": {
"Name": "Frank Darabont",
"Bio": "Director biography",
"Birth": "10/10/1970",
"Death": "10/10/2025"
},
"Actors": ["Tim Robbins", "Morgan Freeman"],
"ImagePath": "shawshank.png",
"Featured": true
}
]
getAllUsers() → {Array}
- Get all users (should be protected and restricted to admins)
Parameters:
Type | Description |
---|---|
authentication | Bearer token (JWT) |
Returns:
- Array of all user objects
- Type
- Array
Example
// Response data format
[
{
"_id": "507f1f77bcf86cd799439011",
"Username": "johndoe",
"Email": "john@example.com",
"Birthday": "1990-01-01",
"FavoriteMovies": []
}
]
getDirectorByName() → {object}
- Return data about a director (bio, birth year, death year) by name
Parameters:
Type | Description |
---|---|
Query_Parameters | :name |
authentication | Bearer token (JWT) |
Returns:
- Director object with name, bio, birth year, death year
- Type
- object
Example
// Response data format
{
"name": "Frank Darabont",
"bio": "Director biography",
"birth": "10/10/1970",
"death": "10/10/2025",
"movies": "The Shawshank Redemption"
}
getFeaturedMovies() → {Array}
- Get featured movies (commonly needed for homepage)
Parameters:
Type | Description |
---|---|
authentication | Bearer token (JWT) |
Returns:
- Array of featured movie objects
- Type
- Array
Example
// Response data format
[
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption",
"Featured": true
}
]
getGenreByName() → {object}
- Return data about a genre (description) by name/title
Parameters:
Type | Description |
---|---|
Query_Parameters | :name |
authentication | Bearer token (JWT) |
Returns:
- Genre object with name and description
- Type
- object
Example
// Response data format
{
"Name": "Drama",
"Description": "Drama is a category of narrative fiction..."
}
getMovieById() → {object}
- Get movie by ID
Parameters:
Type | Description |
---|---|
Query_Parameters | :id |
authentication | Bearer token (JWT) |
Returns:
- Movie object
- Type
- object
Example
// Response data format
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption",
"Description": "Two imprisoned men bond over years...",
"Genre": {
"Name": "Drama",
"Description": "Drama genre description"
},
"Director": {
"Name": "Frank Darabont",
"Bio": "Director biography"
},
"ImagePath": "shawshank.png",
"Featured": true
}
getMovieByTitle() → {object}
- Return data about a single movie by title to the user
Parameters:
Type | Description |
---|---|
Query_Parameters | :title |
authentication | Bearer token (JWT) |
Returns:
- Movie object with description, genre, director, image URL, featured status
- Type
- object
Example
// Response data format
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption",
"Description": "Two imprisoned men bond over years...",
"Genre": {
"Name": "Drama",
"Description": "Drama genre description"
},
"Director": {
"Name": "Frank Darabont",
"Bio": "Director biography",
"Birth": "10/10/1970",
"Death": "10/10/2025"
},
"ImagePath": "shawshank.png",
"Featured": true
}
getMoviesByGenre() → {Array}
- Get movies by genre (commonly needed for filtering)
Parameters:
Type | Description |
---|---|
Query_Parameters | :genre |
authentication | Bearer token (JWT) |
Returns:
- Array of movies matching the genre
- Type
- Array
Example
// Response data format
[
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption",
"Genre": {
"Name": "Drama",
"Description": "Drama genre description"
}
}
]
getUserByUsername() → {object}
- Get user by username
Parameters:
Type | Description |
---|---|
Query_Parameters | :username |
authentication | Bearer token (JWT) |
Returns:
- User object
- Type
- object
Example
// Response data format
{
"_id": "507f1f77bcf86cd799439011",
"Username": "johndoe",
"Email": "john@example.com",
"Birthday": "1990-01-01",
"FavoriteMovies": ["507f1f77bcf86cd799439012"]
}
getUserFavorites() → {object}
- Get user's favorite movies with full movie details
Parameters:
Type | Description |
---|---|
Query_Parameters | :username |
authentication | Bearer token (JWT) |
Returns:
- Object containing username, favorite movies array, and count
- Type
- object
Example
// Response data format
{
"username": "johndoe",
"favoriteMovies": [
{
"_id": "507f1f77bcf86cd799439012",
"Title": "The Godfather",
"Description": "Movie description..."
}
],
"count": 1
}
getWelcome() → {string}
- Welcome message endpoint
Returns:
- Welcome message with usage instructions
- Type
- string
Example
// Response data format
"Welcome to myFlix API! Use /movies for movies or /users for user operations."
loginUser(req, res) → {Object|Object}
Authenticate user credentials and return JWT token
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
req |
Object | Express request object
Properties
|
|||||||||||||||
res |
Object | Express response object |
Returns:
-
200 - Success response with user data and JWT token
- Type
- Object
-
400 - Error response for invalid credentials
- Type
- Object
Example
// Request body:
{
"Username": "johndoe",
"Password": "securePassword123"
}
// Success Response:
{
"user": {
"_id": "507f1f77bcf86cd799439011",
"Username": "johndoe",
"Email": "john@example.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
paginatedSearch() → {object}
- Search with pagination for better performance
Parameters:
Type | Description |
---|---|
Query_Parameters | ?q=searchQuery&page=1&limit=20 |
authentication | Bearer token (JWT) |
Returns:
- Search results with pagination information
- Type
- object
Example
// Response data format
{
"query": "drama",
"results": [
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption"
}
],
"pagination": {
"currentPage": 1,
"totalPages": 1,
"totalResults": 1,
"resultsPerPage": 20,
"hasNextPage": false,
"hasPrevPage": false
}
}
quickSearch() → {object}
- Quick search endpoint optimized for fast results (limited fields)
Parameters:
Type | Description |
---|---|
Query_Parameters | ?q=searchQuery&limit=20 |
authentication | Bearer token (JWT) |
Returns:
- Quick search results with essential fields only
- Type
- object
Example
// Response data format
{
"query": "drama",
"results": [
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption",
"Genre": {"Name": "Drama"},
"Director": {"Name": "Frank Darabont"},
"Year": 1994,
"ImagePath": "shawshank.png"
}
],
"count": 1,
"isQuickSearch": true
}
registerUser() → {object}
- Register a new user account
Parameters:
Type | Description |
---|---|
Request_Body | JSON object |
Returns:
- Created user object
- Type
- object
Examples
// Request data format
{
"Username": "johndoe",
"Password": "password123",
"Email": "john@example.com",
"Birthday": "1990-01-01"
}
// Response data format
{
"_id": "507f1f77bcf86cd799439011",
"Username": "johndoe",
"Email": "john@example.com",
"Birthday": "1990-01-01",
"FavoriteMovies": []
}
removeFromFavorites() → {object}
- Remove a movie from user's list of favorite movies
Parameters:
Type | Description |
---|---|
Query_Parameters | :username, :movieId |
authentication | Bearer token (JWT) |
Returns:
- Updated user object
- Type
- object
Example
// Response data format
{
"_id": "507f1f77bcf86cd799439011",
"Username": "johndoe",
"Email": "john@example.com",
"FavoriteMovies": ["507f1f77bcf86cd799439013"]
}
searchMoviesByActor() → {object}
- Search movies by actor
Parameters:
Type | Description |
---|---|
Query_Parameters | ?actor=searchQuery |
authentication | Bearer token (JWT) |
Returns:
- Search results object
- Type
- object
Example
// Response data format
{
"query": "tim robbins",
"results": [
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption",
"Actors": ["Tim Robbins", "Morgan Freeman"]
}
],
"count": 1
}
searchMoviesByDirector() → {object}
- Search movies by director
Parameters:
Type | Description |
---|---|
Query_Parameters | ?director=searchQuery |
authentication | Bearer token (JWT) |
Returns:
- Search results object
- Type
- object
Example
// Response data format
{
"query": "darabont",
"results": [
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption",
"Director": {"Name": "Frank Darabont"}
}
],
"count": 1
}
searchMoviesByGenre() → {object}
- Search movies by genre
Parameters:
Type | Description |
---|---|
Query_Parameters | ?genre=searchQuery |
authentication | Bearer token (JWT) |
Returns:
- Search results object
- Type
- object
Example
// Response data format
{
"query": "drama",
"results": [
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption",
"Genre": {"Name": "Drama"}
}
],
"count": 1
}
searchMoviesByTitle() → {object}
- Search movies by title
Parameters:
Type | Description |
---|---|
Query_Parameters | ?title=searchQuery |
authentication | Bearer token (JWT) |
Returns:
- Search results object
- Type
- object
Example
// Response data format
{
"query": "shawshank",
"results": [
{
"_id": "507f1f77bcf86cd799439011",
"Title": "The Shawshank Redemption"
}
],
"count": 1
}
searchSuggestions() → {object}
- Auto-suggestions endpoint for search-as-you-type functionality
Parameters:
Type | Description |
---|---|
Query_Parameters | ?q=searchQuery&limit=10 |
authentication | Bearer token (JWT) |
Returns:
- Suggestions object with different categories
- Type
- object
Example
// Response data format
{
"query": "shaw",
"suggestions": {
"movies": [{"type": "movie", "value": "The Shawshank Redemption"}],
"genres": [{"type": "genre", "value": "Drama"}],
"directors": [{"type": "director", "value": "Frank Darabont"}],
"actors": [{"type": "actor", "value": "Tim Robbins"}]
}
}
updateUser() → {object}
- Updates the logged in user's information
Parameters:
Type | Description |
---|---|
Query_Parameters | :Username |
Request_Body | JSON object |
Response | JSON object |
authentication | Bearer token (JWT) |
Returns:
- Updated user object
- Type
- object
Examples
// Request data format
{
"Username": "johnsmith",
"Password": "newpassword123",
"Email": "johnsmith@example.com",
"Birthday": "1990-01-01"
}
// Response data format
{
"_id": "507f1f77bcf86cd799439011",
"Username": "johnsmith",
"Email": "johnsmith@example.com",
"Birthday": "1990-01-01",
"FavoriteMovies": ["507f1f77bcf86cd799439012"]
}