Skip to content

Commit e0a38d1

Browse files
authored
Merge pull request #16 from Nexters/feat/#12
[Feat/#12] API 요청 및 데이터 관리 구조 설계
2 parents c3d5ef7 + 40366a3 commit e0a38d1

31 files changed

+1118
-4
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
API_BASE_URL=
1+
NEXT_PUBLIC_API_BASE_URL=

package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"react": "^18",
1818
"react-dom": "^18",
1919
"styled-components": "^6.1.14",
20-
"styled-reset": "^4.5.2"
20+
"styled-reset": "^4.5.2",
21+
"zod": "^3.24.1"
2122
},
2223
"devDependencies": {
2324
"@types/node": "^20",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { SendChatMessageRequest, SendChatMessageResponse } from '@/chat/apis/sendChatMessage';
2+
import { NextRequest, NextResponse } from 'next/server';
3+
4+
export async function POST(request: NextRequest) {
5+
const body: SendChatMessageRequest = await request.json();
6+
7+
console.log(body);
8+
9+
const normalReplyMockData: SendChatMessageResponse = {
10+
messageId: 1,
11+
type: 'SYSTEM_NORMAL_REPLY',
12+
sender: 'SYSTEM',
13+
answers: ['안녕 내담자', '따듯한 마룻바닥이 그리운 겨울 밤이야', '오늘은 어떤게 궁금해서 찾어왔어냥?'],
14+
};
15+
16+
const invalidQuestionReplyMockData: SendChatMessageResponse = {
17+
messageId: 1,
18+
type: 'SYSTEM_INVALID_QUESTION_REPLY',
19+
sender: 'SYSTEM',
20+
answers: ['잘못된 질문이네냥!', '다시 질문해보라냥!'],
21+
};
22+
23+
const questionReplyMockData: SendChatMessageResponse = {
24+
messageId: 1,
25+
type: 'SYSTEM_TAROT_QUESTION_REPLY',
26+
sender: 'SYSTEM',
27+
answers: ['전남친이 아직 미련이 남았는지 궁금하구낭!', '타로카드로 그 사람의 마음을 함계 들여다 볼까냥?'],
28+
};
29+
30+
const questionAcceptanceReplyMockData: SendChatMessageResponse = {
31+
messageId: 1,
32+
type: 'SYSTEM_TAROT_QUESTION_ACCEPTANCE_REPLY',
33+
sender: 'SYSTEM',
34+
answers: ['너의 고민에 집중하면서', '카드를 한 장 뽑아봐!'],
35+
};
36+
37+
if (body.intent === 'NORMAL') {
38+
return NextResponse.json({ data: normalReplyMockData });
39+
}
40+
41+
if (body.intent === 'TAROT_ACCEPT') {
42+
if (Math.random() < 0.2) {
43+
return NextResponse.json({ data: invalidQuestionReplyMockData });
44+
}
45+
46+
return NextResponse.json({ data: questionAcceptanceReplyMockData });
47+
}
48+
49+
if (body.intent === 'TAROT_DECLINE') {
50+
return NextResponse.json({ data: normalReplyMockData });
51+
}
52+
53+
if (body.intent === 'RECOMMEND_QUESTION') {
54+
return NextResponse.json({ data: questionReplyMockData });
55+
}
56+
57+
return NextResponse.json({ error: 'Invalid intent' }, { status: 400 });
58+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { ChatMessagesByRoomIdResponse } from '@/chat/apis/getChatMessagesByRoomId';
2+
import { NextRequest } from 'next/server';
3+
4+
import { NextResponse } from 'next/server';
5+
6+
export async function GET(request: NextRequest) {
7+
const { searchParams } = new URL(request.url);
8+
const roomId = searchParams.get('roomId');
9+
10+
console.log(roomId);
11+
12+
const mockData: ChatMessagesByRoomIdResponse = {
13+
messages: [
14+
{
15+
messageId: 1,
16+
type: 'USER_NORMAL',
17+
sender: 'SYSTEM',
18+
answers: ['타로결과를 다시 보고 싶으면 카드를 눌러보라냥🐾', '또 궁금한 거 있어냥?'],
19+
tarotName: 'M_00',
20+
tarotResultId: 1,
21+
},
22+
{
23+
messageId: 2,
24+
type: 'USER_TAROT_QUESTION',
25+
sender: 'USER',
26+
answers: ['이 타로 카드가 의미하는 게 뭐냐냥?', '뭔가 다른 카드를 보고 싶다냥.'],
27+
tarotName: 'M_01',
28+
tarotResultId: 2,
29+
},
30+
{
31+
messageId: 3,
32+
type: 'SYSTEM_TAROT_RESULT',
33+
sender: 'SYSTEM',
34+
answers: ['새로운 결과를 보고 싶다면 다른 질문을 해보라냥!', '타로 카드 속에 숨겨진 비밀을 알려줄게냥!'],
35+
tarotName: 'M_02',
36+
tarotResultId: 3,
37+
},
38+
],
39+
};
40+
41+
return NextResponse.json({ data: mockData });
42+
}

src/app/api/v1/chat/room/route.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { CreateChatRoomResponse } from '@/chat/apis/createChatRoom';
2+
import { NextResponse } from 'next/server';
3+
4+
export async function POST() {
5+
const mockData: CreateChatRoomResponse = {
6+
roomId: 1,
7+
message: {
8+
messageId: 1,
9+
type: 'SYSTEM_NORMAL',
10+
sender: 'SYSTEM',
11+
answer: ['안녕이다냥?'],
12+
},
13+
};
14+
15+
return NextResponse.json({ data: mockData });
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { LogShareEventRequest } from '@/shared/apis/logShareEvent';
2+
import { NextRequest, NextResponse } from 'next/server';
3+
4+
export async function POST(request: NextRequest) {
5+
const body: LogShareEventRequest = await request.json();
6+
console.log(body);
7+
8+
return NextResponse.json({ data: { message: '성공' } });
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { TarotQuestionRecommendListResponse } from '@/tarot/apis/getTarotQuestionRecommends';
2+
import { NextResponse } from 'next/server';
3+
4+
export async function GET() {
5+
const mockData: TarotQuestionRecommendListResponse = {
6+
question: [
7+
{
8+
recommendQuestionId: 1,
9+
question: '썸남 썸녀랑 잘 될까?',
10+
referenceCount: 1,
11+
},
12+
{
13+
recommendQuestionId: 2,
14+
question: '상반기에 취업할 수 있을까?',
15+
referenceCount: 222,
16+
},
17+
{
18+
recommendQuestionId: 3,
19+
question: '그 사람은 내 생각하고 있을까?',
20+
referenceCount: 3333,
21+
},
22+
],
23+
};
24+
25+
return NextResponse.json({ data: mockData });
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { TarotReadingResultResponse } from '@/tarot/apis/getTarotReadingResultById';
2+
import { NextRequest, NextResponse } from 'next/server';
3+
4+
export async function GET(request: NextRequest) {
5+
const resultId = request.nextUrl.pathname.split('/')[4];
6+
7+
console.log(parseInt(resultId, 10));
8+
9+
const mockData: TarotReadingResultResponse = {
10+
tarot: 'M_00',
11+
type: '연애',
12+
cardValue: {
13+
summary: '집사가 주도권을 쥐고 있다냥',
14+
description: '지팡이의 여왕은 이런 의미를 가지고 있어. ',
15+
},
16+
answer: {
17+
summary: '재결합 가능성이 있다냥',
18+
description:
19+
'재결합 가능성은 충분히 있다냥. 하지만 이 카드는 집사에게 자신을 먼저 사랑하라는 메시지도 준다냥. 집사가 자신감 있게 자신만의 기준을 세울 때, 상대방이 진심으로 집사를 다시 원할 가능성이 커진다냥.',
20+
question: '전남친이 아직 저에게 미련이 남았는지 궁금해요',
21+
},
22+
advice: {
23+
summary: '가장 중요한 건 집사가 원하는 것이다냥',
24+
description:
25+
'먼저 집사가 진짜 원하는 게 뭔지 정리해라냥. 그 과정에서 집사 자신이 얼마나 소중한 사람인지 다시 느낄 수 있을 거다냥. 그리고 과거에 얽매이지 않고, 집사의 매력을 뿜뿜하는 게 중요하다냥. 재결합은 집사가 빛날 때 자연스럽게 따라오는 결과일 거다냥.',
26+
},
27+
};
28+
29+
return NextResponse.json({ data: mockData });
30+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { SelectTarotCardRequest, SelectTarotCardResponse } from '@/tarot/apis/selectTarotCard';
2+
import { NextRequest, NextResponse } from 'next/server';
3+
4+
export async function POST(request: NextRequest) {
5+
const body: SelectTarotCardRequest = await request.json();
6+
console.log(body);
7+
8+
const mockData: SelectTarotCardResponse = {
9+
messageId: 1,
10+
type: 'SYSTEM_TAROT_RESULT',
11+
sender: 'SYSTEM',
12+
answer: ['타로결과를 다시 보고 싶으면 카드를 눌러보라냥🐾', '또 궁금한 거 있어냥?'],
13+
tarotName: 'M_00',
14+
tarotResultId: 1,
15+
};
16+
17+
return NextResponse.json({ data: mockData });
18+
}

0 commit comments

Comments
 (0)