-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
15 changed files
with
321 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Controller, Get, Query } from '@nestjs/common'; | ||
import { | ||
ApiBadRequestResponse, | ||
ApiOkResponse, | ||
ApiOperation, | ||
} from '@nestjs/swagger'; | ||
import { ChatService } from '@/chat/chat.service'; | ||
import { ChatScrollRequest } from '@/chat/dto/chat.request'; | ||
import { ChatScrollResponse } from '@/chat/dto/chat.response'; | ||
|
||
@Controller('chat') | ||
export class ChatController { | ||
constructor(private readonly chatService: ChatService) {} | ||
|
||
@ApiOperation({ | ||
summary: '채팅 스크롤 조회 API', | ||
description: '채팅을 스크롤하여 조회한다.', | ||
}) | ||
@ApiOkResponse({ | ||
description: '스크롤 조회 성공', | ||
type: ChatScrollResponse, | ||
}) | ||
@ApiBadRequestResponse({ | ||
description: '스크롤 크기 100 초과', | ||
example: { | ||
message: 'pageSize should be less than 100', | ||
error: 'Bad Request', | ||
statusCode: 400, | ||
}, | ||
}) | ||
@Get() | ||
async findChatList(@Query() request: ChatScrollRequest) { | ||
return await this.chatService.scrollNextChat( | ||
request.stockId, | ||
request.latestChatId, | ||
request.pageSize, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { SessionModule } from '@/auth/session.module'; | ||
import { ChatController } from '@/chat/chat.controller'; | ||
import { ChatGateway } from '@/chat/chat.gateway'; | ||
import { ChatService } from '@/chat/chat.service'; | ||
import { Chat } from '@/chat/domain/chat.entity'; | ||
import { StockModule } from '@/stock/stock.module'; | ||
import { ChatService } from '@/chat/chat.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Chat]), StockModule, SessionModule], | ||
controllers: [ChatController], | ||
providers: [ChatGateway, ChatService], | ||
}) | ||
export class ChatModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { DataSource } from 'typeorm'; | ||
import { ChatService } from '@/chat/chat.service'; | ||
import { createDataSourceMock } from '@/user/user.service.spec'; | ||
|
||
describe('ChatService 테스트', () => { | ||
test('첫 스크롤을 조회시 100개 이상 조회하면 예외가 발생한다.', async () => { | ||
const dataSource = createDataSourceMock({}); | ||
const chatService = new ChatService(dataSource as DataSource); | ||
|
||
await expect(() => | ||
chatService.scrollNextChat('A005930', 1, 101), | ||
).rejects.toThrow('pageSize should be less than 100'); | ||
}); | ||
|
||
test('100개 이상의 채팅을 조회하려 하면 예외가 발생한다.', async () => { | ||
const dataSource = createDataSourceMock({}); | ||
const chatService = new ChatService(dataSource as DataSource); | ||
|
||
await expect(() => | ||
chatService.scrollFirstChat('A005930', 101), | ||
).rejects.toThrow('pageSize should be less than 100'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNumber, IsOptional, IsString } from 'class-validator'; | ||
|
||
export class ChatScrollRequest { | ||
@ApiProperty({ | ||
description: '종목 주식 id(종목방 id)', | ||
example: 'A005930', | ||
}) | ||
@IsString() | ||
readonly stockId: string; | ||
|
||
@ApiProperty({ | ||
description: '최신 채팅 id', | ||
example: 99999, | ||
required: false, | ||
}) | ||
@IsOptional() | ||
@IsNumber() | ||
readonly latestChatId?: number; | ||
|
||
@ApiProperty({ | ||
description: '페이지 크기', | ||
example: 20, | ||
default: 20, | ||
required: false, | ||
}) | ||
@IsOptional() | ||
@IsNumber() | ||
readonly pageSize?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Chat } from '@/chat/domain/chat.entity'; | ||
import { ChatType } from '@/chat/domain/chatType.enum'; | ||
|
||
interface ChatResponse { | ||
id: number; | ||
likeCount: number; | ||
message: string; | ||
type: string; | ||
createdAt: Date; | ||
} | ||
|
||
export class ChatScrollResponse { | ||
@ApiProperty({ | ||
description: '다음 페이지가 있는지 여부', | ||
example: true, | ||
}) | ||
readonly hasMore: boolean; | ||
|
||
@ApiProperty({ | ||
description: '채팅 목록', | ||
example: [ | ||
{ | ||
id: 1, | ||
likeCount: 0, | ||
message: '안녕하세요', | ||
type: ChatType.NORMAL, | ||
createdAt: new Date(), | ||
}, | ||
], | ||
}) | ||
readonly chats: ChatResponse[]; | ||
|
||
constructor(chats: Chat[], hasMore: boolean) { | ||
this.chats = chats.map((chat) => ({ | ||
id: chat.id, | ||
likeCount: chat.likeCount, | ||
message: chat.message, | ||
type: chat.type, | ||
createdAt: chat.date!.createdAt, | ||
})); | ||
this.hasMore = hasMore; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty, IsString } from 'class-validator'; | ||
|
||
export class StockSearchRequest { | ||
@ApiProperty({ | ||
description: '검색할 단어', | ||
example: '삼성', | ||
}) | ||
@IsNotEmpty() | ||
@IsString() | ||
name: string; | ||
} |
Oops, something went wrong.