Skip to content

Commit

Permalink
feat: 도어락 비밀번호 관련 컨트롤러 구현 및 모듈 추가 (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coalery authored Oct 15, 2024
2 parents 21f00f8 + dc59175 commit d1eae79
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/app.module.ts → src/RootModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
22 changes: 22 additions & 0 deletions src/app/AppModule.ts
Original file line number Diff line number Diff line change
@@ -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 {}
57 changes: 57 additions & 0 deletions src/app/interface/infraBlue/manager/InfraBlueManageController.ts
Original file line number Diff line number Diff line change
@@ -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<GetDoorLockPasswordResponseDto> {
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<void> {
const { master, forJajudy, forFacilityTeam } = dto;

const command = new UpdateDoorLockPasswordCommand({
master,
forJajudy,
forFacilityTeam,
});
await this.commandBus.execute(command);
}
}
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions src/app/interface/util/DtoBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Type } from '@nestjs/common';

export class DtoBuilder {
static build<T extends object>(ctor: Type<T>, params: T): T {
return Object.assign(new ctor(), params);
}
}
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit d1eae79

Please sign in to comment.