Skip to content

Commit

Permalink
Merge pull request #98 from RECODE01/feat/#68/AddChattingServerAPIs
Browse files Browse the repository at this point in the history
feat/#68/AddChattingServerAPIs get channel hist / edit doce
  • Loading branch information
gchoi96 authored Jun 6, 2022
2 parents ac45570 + 7526f65 commit 9fc9b35
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -74,6 +71,8 @@ export class ChannelHistoryService {
.limit(20)
.getMany();

console.log(result);

if (!result) return [];

return result.map((el) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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 });
Expand All @@ -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 });
});
Expand All @@ -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: '[email protected]',
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: '[email protected]',
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: '[email protected]',
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 });
Expand All @@ -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('채팅 서버 수정 실패');
Expand All @@ -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('채팅 서버 삭제 실패');
Expand All @@ -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('권한 부여 실패');
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -20,6 +20,6 @@ import { ChattingChannel } from '../chatting-channel/entities/chatting-channel.e
]),
],
controllers: [ChattingServerController],
providers: [ChattingRoomService, AuthModule],
providers: [ChattingServerService, AuthModule],
})
export class ChattingRoomModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from './entities/chatting-server.entity';

@Injectable()
export class ChattingRoomService {
export class ChattingServerService {
constructor(
@InjectRepository(ChattingServer)
private readonly chattingServerRepository: Repository<ChattingServer>,
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion with-chat-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ async function bootstrap() {
});
setupSwagger(app);
app.useWebSocketAdapter(new SocketIoAdapter(app));
await app.listen(3000);
await app.listen(4000);
}
bootstrap();

0 comments on commit 9fc9b35

Please sign in to comment.