Skip to content

Commit

Permalink
feat(rest-api): Added /movie/:imdbId endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Nov 12, 2020
1 parent 0d8938c commit 21b98d6
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions apps/rest-api/src/routes/movies/movies.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Controller, Get, Inject, Param, Query } from '@nestjs/common'
import { MoviesService, MoviesArgs } from '@pct-org/api/movies'
import { Movie } from '../../shared/movie.interface'
import { MoviesService, MoviesArgs, Movie } from '@pct-org/api/movies'
import { Movie as OldMovie } from '../../shared/movie.interface'

@Controller('/movies')
@Controller()
export class MoviesController {

@Inject()
private readonly moviesService: MoviesService

@Get('')
@Get('/movies')
public async getMovies(): Promise<string[]> {
const totalMovies = await this.moviesService.count()

Expand All @@ -17,20 +17,33 @@ export class MoviesController {
))
}

@Get('/:page')
@Get('/movies/:page')
public async getMoviesPage(
@Param('page') page: number,
@Query() args: MoviesArgs
): Promise<Movie[]> {
): Promise<OldMovie[]> {
args.offset = (page - 1) * args.limit
args.query = args.keywords

const movies = await this.moviesService.findAll(args)

return movies.map((movie) => ({
return movies.map(this.formatMovie)
}

@Get('/movie/:imdbId')
public async getMovie(
@Param('imdbId') imdbId: string
): Promise<OldMovie> {
const movie = await this.moviesService.findOne(imdbId)

return this.formatMovie(movie)
}

private formatMovie(movie: Movie): OldMovie {
return {
_id: movie._id,
imdb_id: movie._id,
title: movie.title,
title: movie.title + 'test ',
year: `${(new Date(movie.released)).getFullYear()}`,
synopsis: movie.synopsis,
runtime: `${(movie.runtime.hours * 60) + movie.runtime.minutes}`,
Expand Down Expand Up @@ -66,7 +79,7 @@ export class MoviesController {
loved: 100,
hated: 100
}
}))
}
}

}

0 comments on commit 21b98d6

Please sign in to comment.