-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 도어락 비밀번호 관련 컨트롤러 구현 및 모듈 추가 (#73)
- Loading branch information
Showing
7 changed files
with
137 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
57
src/app/interface/infraBlue/manager/InfraBlueManageController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/app/interface/infraBlue/manager/dto/GetDoorLockPasswordResponseDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/app/interface/infraBlue/manager/dto/UpdateDoorLockPasswordRequestDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |