36 lines
956 B
TypeScript
36 lines
956 B
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
HttpCode,
|
|
HttpStatus,
|
|
Param,
|
|
Query
|
|
} from '@nestjs/common'
|
|
import { Movie, MovieDetails } from '@teacinema/contracts/gen/ts/movie'
|
|
|
|
import { GetMoviesRequestDto } from './dto'
|
|
import { MovieClientGrpc } from './movie.grpc'
|
|
import { MovieMapper } from './movie.mapper'
|
|
|
|
@Controller('movies')
|
|
export class MovieController {
|
|
constructor(private readonly client: MovieClientGrpc) {}
|
|
|
|
@Get()
|
|
@HttpCode(HttpStatus.OK)
|
|
public async getAll(@Query() dto: GetMoviesRequestDto) {
|
|
const { movies } = await this.client.call('listMovies', dto)
|
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
return movies.map(MovieMapper.toMovie<Movie>)
|
|
}
|
|
|
|
@Get(':slug')
|
|
@HttpCode(HttpStatus.OK)
|
|
public async getBySlug(@Param('slug') slug: string) {
|
|
const { movie } = await this.client.call('getMovie', { slug })
|
|
|
|
// @ts-expect-error -- ok
|
|
return MovieMapper.toMovie<MovieDetails>(movie)
|
|
}
|
|
}
|