From 7526f65a35fe246eb3a63a5d14e5605f96e0a08c Mon Sep 17 00:00:00 2001 From: choigeon Date: Mon, 6 Jun 2022 16:29:10 +0900 Subject: [PATCH] feat/#68/AddChattingServerAPIs get channel hist / edit doce --- .../channel-history.controller.ts | 2 +- .../channel-history.service.ts | 9 +-- .../chatting-server.controller.ts | 73 ++++++++++++++++--- .../chatting-server/chatting-server.module.ts | 4 +- .../chatting-server.service.ts | 4 +- with-chat-server/src/main.ts | 2 +- 6 files changed, 73 insertions(+), 21 deletions(-) diff --git a/with-chat-server/src/apis/channel-history/channel-history.controller.ts b/with-chat-server/src/apis/channel-history/channel-history.controller.ts index 9f4cca7..ae0a6a6 100644 --- a/with-chat-server/src/apis/channel-history/channel-history.controller.ts +++ b/with-chat-server/src/apis/channel-history/channel-history.controller.ts @@ -84,7 +84,7 @@ export class ChannelHistoryController { .then((result) => { res.status(HttpStatus.OK).json({ success: true, - nextIdx: result[result.length - 1].idx, + nextIdx: result.length > 0 ? result[result.length - 1].idx : -1, message: result, }); }); diff --git a/with-chat-server/src/apis/channel-history/channel-history.service.ts b/with-chat-server/src/apis/channel-history/channel-history.service.ts index 6a31c55..9474383 100644 --- a/with-chat-server/src/apis/channel-history/channel-history.service.ts +++ b/with-chat-server/src/apis/channel-history/channel-history.service.ts @@ -1,13 +1,10 @@ -import { ConflictException, Injectable } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { ConnectedSocket } from '@nestjs/websockets'; -import { Socket } from 'socket.io'; import { ChatGateway } from 'src/chat/chat.gateway'; -import { Connection, createQueryBuilder, Repository } from 'typeorm'; +import { Connection, Repository } from 'typeorm'; import { ICurrentUser } from '../auth/gql-user.param'; import { User } from '../users/entities/user.entity'; import { CreateChannelHistoryDto } from './dto/create-channel-history.dto'; -import { UpdateChannelHistoryDto } from './dto/update-channel-history.dto'; import { ChannelHistory } from './entities/channel-history.entity'; @Injectable() @@ -74,6 +71,8 @@ export class ChannelHistoryService { .limit(20) .getMany(); + console.log(result); + if (!result) return []; return result.map((el) => { diff --git a/with-chat-server/src/apis/chatting-server/chatting-server.controller.ts b/with-chat-server/src/apis/chatting-server/chatting-server.controller.ts index d107aaa..5231ea6 100644 --- a/with-chat-server/src/apis/chatting-server/chatting-server.controller.ts +++ b/with-chat-server/src/apis/chatting-server/chatting-server.controller.ts @@ -21,7 +21,7 @@ import { } from '@nestjs/swagger'; import { AuthAccessGuard } from '../auth/gql-auth.guard'; import { CurrentUser, ICurrentUser } from '../auth/gql-user.param'; -import { ChattingRoomService } from './chatting-server.service'; +import { ChattingServerService } from './chatting-server.service'; import { ChattingRoomResult, MyChattingRoomList, @@ -33,7 +33,7 @@ import { UpdateChattingRoomDto } from './dto/update-chatting-room.dto'; @Controller('chatting-server') @ApiTags('채팅 서버 API') export class ChattingServerController { - constructor(private readonly chattingRoomService: ChattingRoomService) {} + constructor(private readonly chattingServerService: ChattingServerService) {} @UseGuards(AuthAccessGuard) @Post() @@ -51,7 +51,7 @@ export class ChattingServerController { @Body() createChattingRoomDto: CreateChattingRoomDto, @CurrentUser() currentUser: ICurrentUser, ) { - return this.chattingRoomService + return this.chattingServerService .createChattingServer(createChattingRoomDto, currentUser) .then((result) => { res.status(HttpStatus.OK).json({ success: true, result: result }); @@ -70,8 +70,8 @@ export class ChattingServerController { type: MyChattingRoomList, }) fetchMyChattingRoom(@Res() res, @CurrentUser() currentUser: ICurrentUser) { - return this.chattingRoomService - .fetchMyChattingRoom(currentUser) + return this.chattingServerService + .fetchMyChattingServer(currentUser) .then((result) => { res.status(HttpStatus.OK).json({ success: true, result: result }); }); @@ -86,14 +86,67 @@ export class ChattingServerController { }) @ApiOkResponse({ description: '채팅 서버 조회 성공', - type: MyChattingRoomList, + schema: { + example: { + success: true, + id: '5a360b2a-289e-40ae-a99d-3be8830b6ba2', + name: '테스트', + image: + 'https://storage.googleapis.com/wthchat/3c31dec5-9528-4017-8613-3e44fa51431a.png', + users: [ + { + id: '50893644-5292-471a-a970-dbc651a592fc', + email: 'asd@asd.asd', + name: 'asd', + picture: '', + nickName: '최총123', + createdAt: '2022-05-16T05:36:40.938Z', + updatedAt: '2022-05-28T07:21:37.259Z', + }, + { + id: '1f5a82f3-5860-4fff-bcaa-a0fb310bff0d', + email: 'kjmkjm822@naver.com', + name: '김재민', + picture: null, + nickName: '~제이민', + createdAt: '2022-05-27T21:29:06.250Z', + updatedAt: '2022-06-01T08:42:03.067Z', + }, + { + id: '05f37505-9f62-4a22-9e76-ae9f9932adee', + email: 'choigeon96@gmail.com', + name: '최건', + picture: null, + nickName: '최총테스트123123', + createdAt: '2022-06-05T06:50:20.134Z', + updatedAt: '2022-06-05T06:50:41.384Z', + }, + ], + channels: [ + { + id: '4a7f7eaa-1bd2-4628-8e59-cb7ebc7da3f3', + name: '스터디룸', + createdAt: '2022-06-01T07:14:41.270Z', + updatedAt: '2022-06-01T07:14:41.270Z', + deletedAt: null, + }, + { + id: 'bb28bbff-52bb-4c37-8eda-740b4704d946', + name: '스터디룸2', + createdAt: '2022-06-01T07:14:55.985Z', + updatedAt: '2022-06-01T07:14:55.985Z', + deletedAt: null, + }, + ], + }, + }, }) fetchChattingServerDetail( @Res() res, @CurrentUser() currentUser: ICurrentUser, @Param('serverId') serverId: string, ) { - return this.chattingRoomService + return this.chattingServerService .fetchChattingServerDetail(currentUser, serverId) .then((result) => { res.status(HttpStatus.OK).json({ success: true, ...result }); @@ -114,7 +167,7 @@ export class ChattingServerController { @Body() updateUserDto: UpdateChattingRoomDto, @CurrentUser() currentUser: ICurrentUser, ) { - return this.chattingRoomService + return this.chattingServerService .updateChattingRoom(updateUserDto, currentUser) .then((result) => { if (!result) throw new ConflictException('채팅 서버 수정 실패'); @@ -139,7 +192,7 @@ export class ChattingServerController { @Query('roomId') roomId: string, @CurrentUser() currentUser: ICurrentUser, ) { - return this.chattingRoomService + return this.chattingServerService .deleteChattingRoom(roomId, currentUser) .then((result) => { if (!result) throw new ConflictException('채팅 서버 삭제 실패'); @@ -164,7 +217,7 @@ export class ChattingServerController { @Body() grantUserAuthorityDto: GrantUserAuthorityDto, @CurrentUser() currentUser: ICurrentUser, ) { - return this.chattingRoomService + return this.chattingServerService .grantUserAuthority(grantUserAuthorityDto, currentUser) .then((result) => { if (!result) throw new ConflictException('권한 부여 실패'); diff --git a/with-chat-server/src/apis/chatting-server/chatting-server.module.ts b/with-chat-server/src/apis/chatting-server/chatting-server.module.ts index 6f9900e..88a8f54 100644 --- a/with-chat-server/src/apis/chatting-server/chatting-server.module.ts +++ b/with-chat-server/src/apis/chatting-server/chatting-server.module.ts @@ -1,5 +1,5 @@ import { Module } from '@nestjs/common'; -import { ChattingRoomService } from './chatting-server.service'; +import { ChattingServerService } from './chatting-server.service'; import { ChattingServerController } from './chatting-server.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; import { @@ -20,6 +20,6 @@ import { ChattingChannel } from '../chatting-channel/entities/chatting-channel.e ]), ], controllers: [ChattingServerController], - providers: [ChattingRoomService, AuthModule], + providers: [ChattingServerService, AuthModule], }) export class ChattingRoomModule {} diff --git a/with-chat-server/src/apis/chatting-server/chatting-server.service.ts b/with-chat-server/src/apis/chatting-server/chatting-server.service.ts index e8366ef..690eef4 100644 --- a/with-chat-server/src/apis/chatting-server/chatting-server.service.ts +++ b/with-chat-server/src/apis/chatting-server/chatting-server.service.ts @@ -14,7 +14,7 @@ import { } from './entities/chatting-server.entity'; @Injectable() -export class ChattingRoomService { +export class ChattingServerService { constructor( @InjectRepository(ChattingServer) private readonly chattingServerRepository: Repository, @@ -58,7 +58,7 @@ export class ChattingRoomService { } } - async fetchMyChattingRoom(currentUser: ICurrentUser) { + async fetchMyChattingServer(currentUser: ICurrentUser) { const result = await this.chattingServerRepository .createQueryBuilder('chattingRoom') .leftJoin('chattingRoom.users', 'chattingRoomUserDetail') diff --git a/with-chat-server/src/main.ts b/with-chat-server/src/main.ts index ca897fc..7fcb3c9 100644 --- a/with-chat-server/src/main.ts +++ b/with-chat-server/src/main.ts @@ -12,6 +12,6 @@ async function bootstrap() { }); setupSwagger(app); app.useWebSocketAdapter(new SocketIoAdapter(app)); - await app.listen(3000); + await app.listen(4000); } bootstrap();