Skip to content

Commit fd38a6a

Browse files
committed
feat: 프로젝트 링크추가 API 컨트롤러 구현
- 웹소켓 게이트웨이에 프로젝트 링크추가 API 구현 - DTO추가
1 parent 77ecba5 commit fd38a6a

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Type } from 'class-transformer';
2+
import { IsNotEmpty, IsString, Matches, ValidateNested } from 'class-validator';
3+
4+
class Link {
5+
@IsString()
6+
url: string;
7+
8+
@IsString()
9+
description: string;
10+
}
11+
12+
export class LinkCreateRequestDto {
13+
@Matches(/^create$/)
14+
action: string;
15+
16+
@IsNotEmpty()
17+
@ValidateNested()
18+
@Type(() => Link)
19+
content: Link;
20+
}

backend/src/project/websocket.gateway.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { InitLandingResponseDto } from './dto/InitLandingResponse.dto';
2323
import { MemoColorUpdateRequestDto } from './dto/MemoColorUpdateRequest.dto';
2424
import { MemberUpdateRequestDto } from './dto/MemberUpdateRequest.dto';
2525
import { MemberStatus } from './enum/MemberStatus.enum';
26+
import { LinkCreateRequestDto } from './dto/LinkCreateRequest.dto';
2627

2728
export interface ClientSocket extends Socket {
2829
projectId?: number;
@@ -252,6 +253,36 @@ export class ProjectWebsocketGateway
252253
this.sendMemberStatusUpdate(client);
253254
}
254255

256+
@SubscribeMessage('link')
257+
async handleLinkEvent(
258+
@ConnectedSocket() client: ClientSocket,
259+
@MessageBody() data: LinkCreateRequestDto,
260+
) {
261+
if (data.action === 'create') {
262+
const errors = await validate(plainToClass(LinkCreateRequestDto, data));
263+
if (errors.length > 0) {
264+
const errorList = this.getRecursiveErrorMsgList(errors);
265+
client.emit('error', { errorList });
266+
return;
267+
}
268+
const { content } = data as LinkCreateRequestDto;
269+
const createLink = await this.projectService.createLink(
270+
client.project,
271+
content.url,
272+
content.description,
273+
);
274+
client.nsp.to('landing').emit('landing', {
275+
domain: 'link',
276+
action: 'create',
277+
content: {
278+
id: createLink.id,
279+
url: createLink.url,
280+
description: createLink.description,
281+
},
282+
});
283+
}
284+
}
285+
255286
notifyJoinToConnectedMembers(projectId: number, member: Member) {
256287
const projectNamespace = this.namespaceMap.get(projectId);
257288
if (!projectNamespace) return;

0 commit comments

Comments
 (0)