Skip to content

Commit

Permalink
feat: 프로젝트 링크추가 API 컨트롤러 구현
Browse files Browse the repository at this point in the history
- 웹소켓 게이트웨이에 프로젝트 링크추가 API 구현
- DTO추가
  • Loading branch information
choyoungwoo9 committed Jun 13, 2024
1 parent 77ecba5 commit fd38a6a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
20 changes: 20 additions & 0 deletions backend/src/project/dto/LinkCreateRequest.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
31 changes: 31 additions & 0 deletions backend/src/project/websocket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fd38a6a

Please sign in to comment.