diff --git a/src/core/app.module.ts b/src/core/app.module.ts index 2274a5d..9aa1c6c 100644 --- a/src/core/app.module.ts +++ b/src/core/app.module.ts @@ -8,6 +8,7 @@ import { CategoryModule } from '../modules/category/category.module' import { HallModule } from '../modules/hall/hall.module' import { MediaModule } from '../modules/media/media.module' import { MovieModule } from '../modules/movie/movie.module' +import { ScreeningModule } from '../modules/screening/screening.module' import { SeatModule } from '../modules/seat/seat.module' import { TheaterModule } from '../modules/theater/theater.module' import { UsersModule } from '../modules/users/users.module' @@ -37,6 +38,7 @@ import { getPassportConfig } from './config' TheaterModule, HallModule, SeatModule, + ScreeningModule, PassportModule.registerAsync({ useFactory: getPassportConfig, inject: [ConfigService] diff --git a/src/modules/screening/dto/index.ts b/src/modules/screening/dto/index.ts new file mode 100644 index 0000000..66d0236 --- /dev/null +++ b/src/modules/screening/dto/index.ts @@ -0,0 +1 @@ +export * from './rq' diff --git a/src/modules/screening/dto/rq/create-screening.request.dto.ts b/src/modules/screening/dto/rq/create-screening.request.dto.ts new file mode 100644 index 0000000..56f4dbc --- /dev/null +++ b/src/modules/screening/dto/rq/create-screening.request.dto.ts @@ -0,0 +1,19 @@ +import { IsDateString, IsNotEmpty, IsString } from 'class-validator' + +export class CreateScreeningRequestDto { + @IsNotEmpty() + @IsString() + public movieId: string + + @IsNotEmpty() + @IsString() + public hallId: string + + @IsNotEmpty() + @IsDateString() + public startAt: string + + @IsNotEmpty() + @IsDateString() + public endAt: string +} diff --git a/src/modules/screening/dto/rq/get-screenings.request.dto.ts b/src/modules/screening/dto/rq/get-screenings.request.dto.ts new file mode 100644 index 0000000..e61dab8 --- /dev/null +++ b/src/modules/screening/dto/rq/get-screenings.request.dto.ts @@ -0,0 +1,18 @@ +import { ApiPropertyOptional } from '@nestjs/swagger' +import { IsISO8601, IsOptional, IsString } from 'class-validator' + +export class GetScreeningsRequestDto { + @ApiPropertyOptional({ + example: '81lI1385' + }) + @IsOptional() + @IsString() + public theaterId?: string + + @ApiPropertyOptional({ + example: '2018-02-01' + }) + @IsOptional() + @IsISO8601() + public date?: string +} diff --git a/src/modules/screening/dto/rq/index.ts b/src/modules/screening/dto/rq/index.ts new file mode 100644 index 0000000..be7ab43 --- /dev/null +++ b/src/modules/screening/dto/rq/index.ts @@ -0,0 +1,2 @@ +export * from './create-screening.request.dto' +export * from './get-screenings.request.dto' diff --git a/src/modules/screening/screening.controller.ts b/src/modules/screening/screening.controller.ts new file mode 100644 index 0000000..5a5b89f --- /dev/null +++ b/src/modules/screening/screening.controller.ts @@ -0,0 +1,47 @@ +import { + Body, + Controller, + Get, + HttpCode, + HttpStatus, + Param, + Post, + Query +} from '@nestjs/common' + +import { CreateScreeningRequestDto, GetScreeningsRequestDto } from './dto' +import { ScreeningClientGrpc } from './screening.grpc' + +@Controller('screenings') +export class ScreeningController { + constructor(private readonly client: ScreeningClientGrpc) {} + + @Post() + @HttpCode(HttpStatus.CREATED) + public create(@Body() dto: CreateScreeningRequestDto) { + return this.client.call('createScreening', dto) + } + + @Get() + @HttpCode(HttpStatus.OK) + public async getAll(@Query() dto: GetScreeningsRequestDto) { + const { screenings } = await this.client.call('getScreenings', dto) + return screenings + } + + @Get(':id') + @HttpCode(HttpStatus.OK) + public async getById(@Param('id') id: string) { + const { screening } = await this.client.call('getScreening', { id }) + return screening + } + + @Get('movie/:id') + @HttpCode(HttpStatus.OK) + public async getAllByMovieId(@Param('id') movieId: string) { + const { screenings } = await this.client.call('getScreeningsByMovie', { + movieId + }) + return screenings + } +} diff --git a/src/modules/screening/screening.grpc.ts b/src/modules/screening/screening.grpc.ts new file mode 100644 index 0000000..c45a7f1 --- /dev/null +++ b/src/modules/screening/screening.grpc.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@nestjs/common' +import type { ClientGrpc } from '@nestjs/microservices' +import { InjectGrpc } from '@teacinema/common' +import { ScreeningServiceClient } from '@teacinema/contracts/gen/ts/screening' + +import { AbstractGrpcClient } from '../../shared/grpc/abstract-grpc.client' + +@Injectable() +export class ScreeningClientGrpc extends AbstractGrpcClient { + constructor(@InjectGrpc('SCREENING_PACKAGE') client: ClientGrpc) { + super(client, 'ScreeningService') + } +} diff --git a/src/modules/screening/screening.module.ts b/src/modules/screening/screening.module.ts new file mode 100644 index 0000000..60ea471 --- /dev/null +++ b/src/modules/screening/screening.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common' +import { GrpcModule } from '@teacinema/common' + +import { ScreeningController } from './screening.controller' +import { ScreeningClientGrpc } from './screening.grpc' + +@Module({ + imports: [GrpcModule.register(['SCREENING_PACKAGE'])], + controllers: [ScreeningController], + providers: [ScreeningClientGrpc] +}) +export class ScreeningModule {} diff --git a/yarn.lock b/yarn.lock index 1d0e139..a0f2fa4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -334,9 +334,9 @@ integrity sha512-DDaRehssg1aNrH4+2hnj1B7vnUGEjU6OIlyRdkMd0aUdIUvKXrJfXsy8LVtXAy7DRvYVluWbMspsRhz2lcW0mQ== "@bufbuild/protobuf@^2.0.0", "@bufbuild/protobuf@^2.10.2": - version "2.11.0" - resolved "https://registry.yarnpkg.com/@bufbuild/protobuf/-/protobuf-2.11.0.tgz#3ec3985c9074b23aea337957225fe15a0e845f8e" - integrity sha512-sBXGT13cpmPR5BMgHE6UEEfEaShh5Ror6rfN3yEK5si7QVrtZg8LEPQb0VVhiLRUslD2yLnXtnRzG035J/mZXQ== + version "2.12.0" + resolved "https://registry.yarnpkg.com/@bufbuild/protobuf/-/protobuf-2.12.0.tgz#53225636a8fcebb2bd94998ad9d42f99f96add4d" + integrity sha512-B/XlCaFIP8LOwzo+bz5uFzATYokcwCKQcghqnlfwSmM5eX/qTkvDBnDPs+gXtX/RyjxJ4DRikECcPJbyALA8FA== "@colors/colors@1.5.0": version "1.5.0" @@ -1997,19 +1997,19 @@ "@sinonjs/commons" "^3.0.1" "@teacinema/common@^1.0.0": - version "1.5.0" - resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcommon/-/1.5.0/common-1.5.0.tgz#236c1aba248b31773297bf17aad9053116483e93" - integrity sha512-GqGx8jFaMP6ADcZP18ariJtAHbJqLhT9Up80SLwU1fInKUthQb5MzLrTc4ce8jAxbczLVMGmikphIQNYNpvCGg== + version "1.6.1" + resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcommon/-/1.6.1/common-1.6.1.tgz#403232158953c986cbd8a7f351d844ee7d3ab6e0" + integrity sha512-J0dusJwpb9JgSh6oIoa29WgCy36zZuW9VvQ6gOvPUF2PoE6c/Ktx/RRSn+kCkE7zXEZzxwoVaQh7t+0nSeX4Dg== dependencies: "@nestjs/common" "^11.1.16" "@nestjs/config" "^4.0.3" "@nestjs/microservices" "^11.1.16" - "@teacinema/contracts" "^1.1.3" + "@teacinema/contracts" "^1.5.0" -"@teacinema/contracts@^1.0.0", "@teacinema/contracts@^1.1.3": - version "1.4.1" - resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.4.1/contracts-1.4.1.tgz#20feccf1784a41ad6b4b0ebfcc035f991a7473c9" - integrity sha512-CcYU/cUQfBw+KJp8d14RONIZahkbUAYxiLqudHhx/kpEPuoQDO8VMJy6SbUqBM1HKZ1VTtyQWfxm/79PBPMe0g== +"@teacinema/contracts@^1.0.0", "@teacinema/contracts@^1.5.0": + version "1.5.0" + resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.5.0/contracts-1.5.0.tgz#d816ab6b847794328d58df1c1d08b4efeceb99bb" + integrity sha512-pLgt117PXVt7XZOko4A2Et97aRZs0QdylZAonWyt6S2U1rmWfn7CKPdPJw77LsA+GaFuE/4ntZbXxTzIFdJYVA== dependencies: "@nestjs/microservices" "^11.1.12" protoc "33.4.0"