gateway/src/modules/hall/hall.controller.ts

45 lines
1.0 KiB
TypeScript

import {
Body,
Controller,
Get,
HttpCode,
HttpStatus,
Param,
Post
} from '@nestjs/common'
import type { ListHallsByTheaterRequest } from '@teacinema/contracts/gen/ts/hall'
import { Role } from 'src/shared/guards'
import { Protected } from '../../shared/decorators'
import { CreateHallRequestDto } from './dto'
import { HallClientGrpc } from './hall.grpc'
@Controller('halls')
export class HallController {
constructor(private readonly client: HallClientGrpc) {}
@Get()
@HttpCode(HttpStatus.OK)
public async getAll(@Body() data: ListHallsByTheaterRequest) {
const { halls } = await this.client.call('listHallsByTheater', data)
return halls
}
@Get(':id')
@HttpCode(HttpStatus.OK)
public async getById(@Param('id') id: string) {
const { hall } = await this.client.call('getHall', { id })
return hall
}
// @Protected(Role.ADMIN)
@Post()
@HttpCode(HttpStatus.CREATED)
public async create(@Body() dto: CreateHallRequestDto) {
const { hall } = await this.client.call('createHall', dto)
return hall
}
}