Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Movies module #252

Merged
merged 20 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ca634d2
feat(modules/movies): create data for movies
devrrior Oct 20, 2022
46c40af
feat(movies/utils): create getMovieById function
devrrior Oct 20, 2022
9a9758a
feat(movies/utils): create getRandomMovies function
devrrior Oct 20, 2022
74e2217
feat(movies/api) create movies-routes.ts with 2 endpoints
devrrior Oct 20, 2022
67067ed
feat(app.ts): add movies-routes
devrrior Oct 20, 2022
c469ec6
fix(movies/data/movies.ts): change 'runtime(mins)' for runtime
devrrior Oct 20, 2022
8da98fc
fix(movies/data/movies.ts): change num_votes for IMDb_votes
devrrior Oct 20, 2022
9a688de
feat(movies/consts/Movie.ts): creat Movie type and generate documenta…
devrrior Oct 20, 2022
03ce104
docs(movies/api/movies-routes.ts): add OpenApi docs for both endpoints
devrrior Oct 20, 2022
be1a53d
tests(movies/tests/utils): create tests for getMovieById and getRando…
devrrior Oct 20, 2022
3bb176e
tests(movies/tests/api): create tests for movie-routes.ts
devrrior Oct 20, 2022
4c7bd31
test(movies/utils): update test for getRandomMovies
devrrior Oct 20, 2022
3191a70
feat(movies/utils): add object which will return in both functions
devrrior Oct 20, 2022
9f7bd62
feat(movies/consts): export Movie
devrrior Oct 20, 2022
90eaa99
fix(movies/api/movies-routes): fix endpoint patter and change of logi…
devrrior Oct 20, 2022
d7dfa44
fix(movies/api/movies-routes): fix OpenAPI documentation
devrrior Oct 20, 2022
04c27c5
test(movies): update tests
devrrior Oct 20, 2022
2965eb9
Merge branch 'dev' into movies_feature
ageddesi Oct 22, 2022
7647317
Merge branch 'dev' into movies_feature
ageddesi Oct 27, 2022
feee774
fix: moved modules and failing tests
ageddesi Oct 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/modules/movies/api/movies-routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Request, Response } from 'express';
import * as core from 'express-serve-static-core';
import { getQtyFromRequest } from '../../../utils/route-utils';
import movies from '../data/movies';
import getMovieById from '../utils/getMovieById';
import getRandomMovies from '../utils/getRandomMovies';

module.exports = function (app: core.Express) {

/**
* @openapi
* '/movies/random':
* get:
* tags:
* - Movies
* summary: Get a random movie
* responses:
* '200':
* description: OK
* schema:
* $ref: '#/definitions/MockMovie'
*/
app.get('/movies/random', (req: Request, res: Response) => {
const randomNumber = Math.floor(Math.random() * movies.length) + 1
const movie = getMovieById(randomNumber);

res.json(movie);
});

/**
* @openapi
* '/movies/{qty}':
* get:
* tags:
* - Movies
* summary: Returns random movies
* parameters:
* - in: params
* name: qty
* schema:
* type: number
* default: 10
* responses:
* '200':
* description: OK
* schema:
* type: array
* items:
* $ref: '#/definitions/MockMovie'
*/
app.get('/movies/:qty?', (req: Request, res: Response) => {
const quantity = getQtyFromRequest(req, 10);
const movies = getRandomMovies(quantity);

return res.json(movies);
});

};
62 changes: 62 additions & 0 deletions src/modules/movies/consts/Movie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

/**
* @openapi
* definitions:
* MockMovie:
* type: object
* properties:
* id:
* type: number
* example: 1
* created:
* type: string
* example: 2019-01-01
* modified:
* type: string
* example: 2019-08-03
* title:
* type: string
* example: 'The Shawshank Redemption'
* url:
* type: string
* example: 'https://www.imdb.com/title/tt0111161/'
* IMDb_rating:
* type: number
* example: 9.3
* runtime:
* type: number
* example: 142
* year:
* type: number
* example: 1994
* genres:
* type: string
* example: 'Drama, Crime'
* IMDb_votes:
* type: number
* example: 2_223_000
* release_date:
* type: string
* example: '1994-09-23'
* directors:
* type: string
* example: 'Frank Darabont'
*
*
*/
type Movie = {
id: number;
created: string;
modified: string;
title: string;
url: string;
IMDb_rating: number;
runtime: number;
year: number;
genres: string;
IMDb_votes: number;
release_date: string;
directors: string;
};

export default Movie;