diff --git a/src/app.module.ts b/src/RootModule.ts similarity index 63% rename from src/app.module.ts rename to src/RootModule.ts index 56050b3..5b78d21 100644 --- a/src/app.module.ts +++ b/src/RootModule.ts @@ -5,9 +5,11 @@ import { CoreModule } from '@khlug/core/core.module'; import { Cache } from '@khlug/app/domain/cache/model/Cache'; +import { AppModule } from '@khlug/app/AppModule'; + @Module({ - imports: [CoreModule, MikroOrmModule.forFeature([Cache])], + imports: [AppModule, CoreModule, MikroOrmModule.forFeature([Cache])], controllers: [], providers: [], }) -export class AppModule {} +export class RootModule {} diff --git a/src/app/AppModule.ts b/src/app/AppModule.ts new file mode 100644 index 0000000..3788f9d --- /dev/null +++ b/src/app/AppModule.ts @@ -0,0 +1,22 @@ +import { MikroOrmModule } from '@mikro-orm/nestjs'; +import { Module } from '@nestjs/common'; + +import { InfraBlueManageController } from '@khlug/app/interface/infraBlue/manager/InfraBlueManageController'; + +import { UpdateDoorLockPasswordCommandHandler } from '@khlug/app/application/infraBlue/command/updateDoorLockPassword/UpdateDoorLockPasswordCommandHandler'; +import { GetDoorLockPasswordQueryHandler } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryHandler'; + +import { Cache } from '@khlug/app/domain/cache/model/Cache'; + +const controllers = []; +const manageControllers = [InfraBlueManageController]; + +const commandHandlers = [UpdateDoorLockPasswordCommandHandler]; +const queryHandlers = [GetDoorLockPasswordQueryHandler]; + +@Module({ + imports: [MikroOrmModule.forFeature([Cache])], + controllers: [...controllers, ...manageControllers], + providers: [...commandHandlers, ...queryHandlers], +}) +export class AppModule {} diff --git a/src/app/interface/infraBlue/manager/InfraBlueManageController.ts b/src/app/interface/infraBlue/manager/InfraBlueManageController.ts new file mode 100644 index 0000000..61306d4 --- /dev/null +++ b/src/app/interface/infraBlue/manager/InfraBlueManageController.ts @@ -0,0 +1,57 @@ +import { + Body, + Controller, + Get, + HttpCode, + HttpStatus, + Put, +} from '@nestjs/common'; +import { CommandBus, QueryBus } from '@nestjs/cqrs'; +import { ApiOperation, ApiResponse } from '@nestjs/swagger'; + +import { Auth } from '@khlug/core/auth/Auth'; +import { UserRole } from '@khlug/core/auth/UserRole'; + +import { GetDoorLockPasswordResponseDto } from '@khlug/app/interface/infraBlue/manager/dto/GetDoorLockPasswordResponseDto'; +import { UpdateDoorLockPasswordRequestDto } from '@khlug/app/interface/infraBlue/manager/dto/UpdateDoorLockPasswordRequestDto'; + +import { UpdateDoorLockPasswordCommand } from '@khlug/app/application/infraBlue/command/updateDoorLockPassword/UpdateDoorLockPasswordCommand'; +import { GetDoorLockPasswordQuery } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQuery'; +import { GetDoorLockPasswordQueryResult } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult'; + +@Controller() +export class InfraBlueManageController { + constructor( + private readonly queryBus: QueryBus, + private readonly commandBus: CommandBus, + ) {} + + @Get('/manager/door-lock-password') + @Auth([UserRole.MANAGER]) + @ApiOperation({ summary: '도어락 비밀번호 정보 조회' }) + @ApiResponse({ status: HttpStatus.OK, type: GetDoorLockPasswordResponseDto }) + async getDoorLockPassword(): Promise { + const query = new GetDoorLockPasswordQuery(); + const queryResult: GetDoorLockPasswordQueryResult = + await this.queryBus.execute(query); + return GetDoorLockPasswordResponseDto.buildFromQueryResult(queryResult); + } + + @Put('/manager/door-lock-password') + @Auth([UserRole.MANAGER]) + @HttpCode(HttpStatus.NO_CONTENT) + @ApiOperation({ summary: '도어락 비밀번호 정보 변경' }) + @ApiResponse({ status: HttpStatus.NO_CONTENT }) + async updateDoorLockPassword( + @Body() dto: UpdateDoorLockPasswordRequestDto, + ): Promise { + const { master, forJajudy, forFacilityTeam } = dto; + + const command = new UpdateDoorLockPasswordCommand({ + master, + forJajudy, + forFacilityTeam, + }); + await this.commandBus.execute(command); + } +} diff --git a/src/app/interface/infraBlue/manager/dto/GetDoorLockPasswordResponseDto.ts b/src/app/interface/infraBlue/manager/dto/GetDoorLockPasswordResponseDto.ts new file mode 100644 index 0000000..0d56824 --- /dev/null +++ b/src/app/interface/infraBlue/manager/dto/GetDoorLockPasswordResponseDto.ts @@ -0,0 +1,26 @@ +import { ApiProperty } from '@nestjs/swagger'; + +import { DtoBuilder } from '@khlug/app/interface/util/DtoBuilder'; + +import { GetDoorLockPasswordQueryResult } from '@khlug/app/application/infraBlue/query/getDoorLockPassword/GetDoorLockPasswordQueryResult'; + +export class GetDoorLockPasswordResponseDto { + @ApiProperty({ description: '마스터 비밀번호' }) + master!: string; + + @ApiProperty({ description: '중동연용 비밀번호' }) + forJajudy!: string; + + @ApiProperty({ description: '시설팀용 비밀번호' }) + forFacilityTeam!: string; + + static buildFromQueryResult( + queryResult: GetDoorLockPasswordQueryResult, + ): GetDoorLockPasswordResponseDto { + return DtoBuilder.build(GetDoorLockPasswordResponseDto, { + master: queryResult.master, + forJajudy: queryResult.forJajudy, + forFacilityTeam: queryResult.forFacilityTeam, + }); + } +} diff --git a/src/app/interface/infraBlue/manager/dto/UpdateDoorLockPasswordRequestDto.ts b/src/app/interface/infraBlue/manager/dto/UpdateDoorLockPasswordRequestDto.ts new file mode 100644 index 0000000..488ff0c --- /dev/null +++ b/src/app/interface/infraBlue/manager/dto/UpdateDoorLockPasswordRequestDto.ts @@ -0,0 +1,19 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsNotEmpty, IsString } from 'class-validator'; + +export class UpdateDoorLockPasswordRequestDto { + @ApiProperty({ description: '마스터 비밀번호' }) + @IsString() + @IsNotEmpty() + master!: string; + + @ApiProperty({ description: '중동연용 비밀번호' }) + @IsString() + @IsNotEmpty() + forJajudy!: string; + + @ApiProperty({ description: '시설팀용 비밀번호' }) + @IsString() + @IsNotEmpty() + forFacilityTeam!: string; +} diff --git a/src/app/interface/util/DtoBuilder.ts b/src/app/interface/util/DtoBuilder.ts new file mode 100644 index 0000000..8cc40f6 --- /dev/null +++ b/src/app/interface/util/DtoBuilder.ts @@ -0,0 +1,7 @@ +import { Type } from '@nestjs/common'; + +export class DtoBuilder { + static build(ctor: Type, params: T): T { + return Object.assign(new ctor(), params); + } +} diff --git a/src/main.ts b/src/main.ts index e487013..a235b9c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,9 @@ import { NestFactory } from '@nestjs/core'; -import { AppModule } from '@khlug/app.module'; +import { RootModule } from '@khlug/RootModule'; async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(RootModule); await app.listen(3000); } bootstrap();