From fd38a6a4230bccfeabf8731461a966c1f361de30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=98=81=EC=9A=B0?= Date: Thu, 13 Jun 2024 11:10:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8=20?= =?UTF-8?q?=EB=A7=81=ED=81=AC=EC=B6=94=EA=B0=80=20API=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 웹소켓 게이트웨이에 프로젝트 링크추가 API 구현 - DTO추가 --- .../src/project/dto/LinkCreateRequest.dto.ts | 20 ++++++++++++ backend/src/project/websocket.gateway.ts | 31 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 backend/src/project/dto/LinkCreateRequest.dto.ts diff --git a/backend/src/project/dto/LinkCreateRequest.dto.ts b/backend/src/project/dto/LinkCreateRequest.dto.ts new file mode 100644 index 0000000..dee49be --- /dev/null +++ b/backend/src/project/dto/LinkCreateRequest.dto.ts @@ -0,0 +1,20 @@ +import { Type } from 'class-transformer'; +import { IsNotEmpty, IsString, Matches, ValidateNested } from 'class-validator'; + +class Link { + @IsString() + url: string; + + @IsString() + description: string; +} + +export class LinkCreateRequestDto { + @Matches(/^create$/) + action: string; + + @IsNotEmpty() + @ValidateNested() + @Type(() => Link) + content: Link; +} diff --git a/backend/src/project/websocket.gateway.ts b/backend/src/project/websocket.gateway.ts index 4483ec3..ca1b969 100644 --- a/backend/src/project/websocket.gateway.ts +++ b/backend/src/project/websocket.gateway.ts @@ -23,6 +23,7 @@ import { InitLandingResponseDto } from './dto/InitLandingResponse.dto'; import { MemoColorUpdateRequestDto } from './dto/MemoColorUpdateRequest.dto'; import { MemberUpdateRequestDto } from './dto/MemberUpdateRequest.dto'; import { MemberStatus } from './enum/MemberStatus.enum'; +import { LinkCreateRequestDto } from './dto/LinkCreateRequest.dto'; export interface ClientSocket extends Socket { projectId?: number; @@ -252,6 +253,36 @@ export class ProjectWebsocketGateway this.sendMemberStatusUpdate(client); } + @SubscribeMessage('link') + async handleLinkEvent( + @ConnectedSocket() client: ClientSocket, + @MessageBody() data: LinkCreateRequestDto, + ) { + if (data.action === 'create') { + const errors = await validate(plainToClass(LinkCreateRequestDto, data)); + if (errors.length > 0) { + const errorList = this.getRecursiveErrorMsgList(errors); + client.emit('error', { errorList }); + return; + } + const { content } = data as LinkCreateRequestDto; + const createLink = await this.projectService.createLink( + client.project, + content.url, + content.description, + ); + client.nsp.to('landing').emit('landing', { + domain: 'link', + action: 'create', + content: { + id: createLink.id, + url: createLink.url, + description: createLink.description, + }, + }); + } + } + notifyJoinToConnectedMembers(projectId: number, member: Member) { const projectNamespace = this.namespaceMap.get(projectId); if (!projectNamespace) return;