Skip to content

Commit c09f3a5

Browse files
authored
Merge pull request #45 from Nexters/feat/#44
2 parents 9618153 + f6bc45e commit c09f3a5

29 files changed

+108
-179
lines changed

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,33 @@
1-
import {
2-
SendChatMessageRequest,
3-
SendChatMessageResponse,
4-
} from "@/chat/apis/sendChatMessage";
1+
import { SendChatMessageRequest } from "@/chat/apis/sendChatMessage";
52
import { NextRequest, NextResponse } from "next/server";
63

74
export async function POST(request: NextRequest) {
85
const body: SendChatMessageRequest = await request.json();
96

107
console.log(body);
118

12-
const normalReplyMockData: SendChatMessageResponse = {
9+
const normalReplyMockData = {
1310
messageId: 1,
1411
type: "SYSTEM_NORMAL_REPLY",
1512
sender: "SYSTEM",
16-
answers: [
17-
"안녕 내담자",
18-
"따듯한 마룻바닥이 그리운 겨울 밤이야",
19-
"오늘은 어떤게 궁금해서 찾어왔어냥?",
20-
],
13+
answers: ["안녕 내담자", "따듯한 마룻바닥이 그리운 겨울 밤이야", "오늘은 어떤게 궁금해서 찾어왔어냥?"],
2114
};
2215

23-
const invalidQuestionReplyMockData: SendChatMessageResponse = {
16+
const invalidQuestionReplyMockData = {
2417
messageId: 1,
2518
type: "SYSTEM_INVALID_QUESTION_REPLY",
2619
sender: "SYSTEM",
2720
answers: ["잘못된 질문이네냥!", "다시 질문해보라냥!"],
2821
};
2922

30-
const questionReplyMockData: SendChatMessageResponse = {
23+
const questionReplyMockData = {
3124
messageId: 1,
3225
type: "SYSTEM_TAROT_QUESTION_REPLY",
3326
sender: "SYSTEM",
34-
answers: [
35-
"전남친이 아직 미련이 남았는지 궁금하구낭!",
36-
"타로카드로 그 사람의 마음을 함계 들여다 볼까냥?",
37-
],
27+
answers: ["전남친이 아직 미련이 남았는지 궁금하구낭!", "타로카드로 그 사람의 마음을 함계 들여다 볼까냥?"],
3828
};
3929

40-
const questionAcceptanceReplyMockData: SendChatMessageResponse = {
30+
const questionAcceptanceReplyMockData = {
4131
messageId: 1,
4232
type: "SYSTEM_TAROT_QUESTION_ACCEPTANCE_REPLY",
4333
sender: "SYSTEM",

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ChatMessagesByRoomIdResponse } from "@/chat/apis/getChatMessagesByRoomId";
21
import { NextRequest } from "next/server";
32

43
import { NextResponse } from "next/server";
@@ -9,38 +8,29 @@ export async function GET(request: NextRequest) {
98

109
console.log(roomId);
1110

12-
const mockData: ChatMessagesByRoomIdResponse = {
11+
const mockData = {
1312
messages: [
1413
{
1514
messageId: 1,
1615
type: "USER_NORMAL",
1716
sender: "SYSTEM",
18-
answers: [
19-
"타로결과를 다시 보고 싶으면 카드를 눌러보라냥🐾",
20-
"또 궁금한 거 있어냥?",
21-
],
17+
answers: ["타로결과를 다시 보고 싶으면 카드를 눌러보라냥🐾", "또 궁금한 거 있어냥?"],
2218
tarotName: "M_00",
2319
tarotResultId: 1,
2420
},
2521
{
2622
messageId: 2,
2723
type: "USER_TAROT_QUESTION",
2824
sender: "USER",
29-
answers: [
30-
"이 타로 카드가 의미하는 게 뭐냐냥?",
31-
"뭔가 다른 카드를 보고 싶다냥.",
32-
],
25+
answers: ["이 타로 카드가 의미하는 게 뭐냐냥?", "뭔가 다른 카드를 보고 싶다냥."],
3326
tarotName: "M_01",
3427
tarotResultId: 2,
3528
},
3629
{
3730
messageId: 3,
3831
type: "SYSTEM_TAROT_RESULT",
3932
sender: "SYSTEM",
40-
answers: [
41-
"새로운 결과를 보고 싶다면 다른 질문을 해보라냥!",
42-
"타로 카드 속에 숨겨진 비밀을 알려줄게냥!",
43-
],
33+
answers: ["새로운 결과를 보고 싶다면 다른 질문을 해보라냥!", "타로 카드 속에 숨겨진 비밀을 알려줄게냥!"],
4434
tarotName: "M_02",
4535
tarotResultId: 3,
4636
},

src/app/api/v1/tarot/result/[resultId]/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { TarotReadingResultResponse } from "@/tarot/apis/getTarotReadingResultById";
21
import { NextRequest, NextResponse } from "next/server";
32

43
export async function GET(request: NextRequest) {
54
const resultId = request.nextUrl.pathname.split("/")[4];
65

76
console.log(parseInt(resultId, 10));
87

9-
const mockData: TarotReadingResultResponse = {
8+
const mockData = {
109
tarot: "M_00",
1110
type: "연애",
1211
cardValue: {

src/app/api/v1/tarot/select/route.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import {
2-
SelectTarotCardRequest,
3-
SelectTarotCardResponse,
4-
} from "@/tarot/apis/selectTarotCard";
1+
import { SelectTarotCardRequest } from "@/tarot/apis/selectTarotCard";
52
import { NextRequest, NextResponse } from "next/server";
63

74
export async function POST(request: NextRequest) {
85
const body: SelectTarotCardRequest = await request.json();
96
console.log(body);
107

11-
const mockData: SelectTarotCardResponse = {
8+
const mockData = {
129
messageId: 1,
1310
type: "SYSTEM_TAROT_RESULT",
1411
sender: "SYSTEM",
15-
answer: [
16-
"타로결과를 다시 보고 싶으면 카드를 눌러보라냥🐾",
17-
"또 궁금한 거 있어냥?",
18-
],
12+
answer: ["타로결과를 다시 보고 싶으면 카드를 눌러보라냥🐾", "또 궁금한 거 있어냥?"],
1913
tarotName: "M_00",
2014
tarotResultId: 1,
2115
};

src/chat/apis/createChatRoom.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import apiClient from "@/shared/lib/axios/apiClient";
22
import { z } from "zod";
33

4-
export type CreateChatRoomResponse = {
4+
type serverResponse = {
55
roomId: number;
66
};
77

88
const schema = z.object({
99
roomId: z.number(),
1010
});
1111

12-
type CreateChatRoomData = z.infer<typeof schema>;
12+
export type CreateChatRoomResponse = z.infer<typeof schema>;
1313

14-
const validate = (data: CreateChatRoomResponse): CreateChatRoomData => {
14+
const validate = (data: serverResponse): CreateChatRoomResponse => {
1515
const validatedData = schema.parse(data);
1616
return validatedData;
1717
};
1818

19-
export const createChatRoom = () => {
19+
export const createChatRoom = (): Promise<CreateChatRoomResponse> => {
2020
return apiClient
21-
.post<CreateChatRoomResponse>(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/chat/room`)
21+
.post<serverResponse>(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/chat/room`)
2222
.then((res) => validate(res.data))
2323
.catch((error) => {
2424
console.error(error);

src/chat/apis/getChatMessagesByRoomId.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import apiClient from "@/shared/lib/axios/apiClient";
2-
import { TarotCardIdSchema } from "@/tarot/models/tarotCardId";
2+
import { TarotCardIdSchema } from "@/tarot/types/tarotCardId";
33
import { z } from "zod";
4-
import { MessageCategorySchema } from "../models/messageCategory";
5-
import { MessageSenderTypeSchema } from "../models/messageSender";
4+
import { MessageCategorySchema } from "../types/messageCategory";
5+
import { MessageSenderTypeSchema } from "../types/messageSender";
66

7-
export type ChatMessagesByRoomIdResponse = {
7+
type serverResponse = {
88
messages: {
99
messageId: number;
1010
type: string;
@@ -28,16 +28,16 @@ const schema = z.object({
2828
),
2929
});
3030

31-
export type ChatMessagesByRoomIdData = z.infer<typeof schema>;
31+
export type ChatMessagesByRoomIdResponse = z.infer<typeof schema>;
3232

33-
const validate = (data: ChatMessagesByRoomIdResponse): ChatMessagesByRoomIdData => {
33+
const validate = (data: serverResponse): ChatMessagesByRoomIdResponse => {
3434
const validatedData = schema.parse(data);
3535
return validatedData;
3636
};
3737

38-
export const getChatMessagesByRoomId = (roomId: number) => {
38+
export const getChatMessagesByRoomId = (roomId: number): Promise<ChatMessagesByRoomIdResponse> => {
3939
return apiClient
40-
.get<ChatMessagesByRoomIdResponse>(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/chat/room/messages`, {
40+
.get<serverResponse>(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/chat/room/messages`, {
4141
params: {
4242
roomId,
4343
},

src/chat/apis/sendChatMessage.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import apiClient from "@/shared/lib/axios/apiClient";
22
import { z } from "zod";
3-
import { MessageCategorySchema } from "../models/messageCategory";
4-
import { MessageSenderTypeSchema } from "../models/messageSender";
3+
import { MessageCategorySchema } from "../types/messageCategory";
4+
import { MessageSenderTypeSchema } from "../types/messageSender";
55

66
export type SendChatMessageRequest = {
77
roomId: number;
@@ -10,7 +10,7 @@ export type SendChatMessageRequest = {
1010
referenceQuestionId?: number;
1111
};
1212

13-
export type SendChatMessageResponse = {
13+
type serverResponse = {
1414
messageId: number;
1515
type: string;
1616
sender: string;
@@ -30,19 +30,16 @@ const schema = z.object({
3030
answers: z.array(z.string()),
3131
});
3232

33-
type SendChatMessageData = z.infer<typeof schema>;
33+
export type SendChatMessageResponse = z.infer<typeof schema>;
3434

35-
const validate = (data: SendChatMessageResponse): SendChatMessageData => {
35+
const validate = (data: serverResponse): SendChatMessageResponse => {
3636
const validatedData = schema.parse(data);
3737
return validatedData;
3838
};
3939

40-
export const sendChatMessage = (request: SendChatMessageRequest) => {
40+
export const sendChatMessage = (request: SendChatMessageRequest): Promise<SendChatMessageResponse> => {
4141
return apiClient
42-
.post<SendChatMessageResponse>(
43-
`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/chat/room/message`,
44-
request,
45-
)
42+
.post<serverResponse>(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/chat/room/message`, request)
4643
.then((res) => validate(res.data))
4744
.catch((error) => {
4845
console.error(error);

src/chat/components/Card.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"use client";
22

3-
import Image from "next/image";
4-
import styled from "styled-components";
53
import CardBack from "@/shared/assets/images/cardBack.webp";
64
import { cubicBezier, easeOut } from "motion";
75
import { div } from "motion/react-client";
8-
import { useState } from "react";
9-
import { Dispatch, SetStateAction, useRef, useEffect } from "react";
10-
import { CardPickState } from "../models/CardPickState";
11-
import { DeckState } from "../models/DeckState";
6+
import Image from "next/image";
7+
import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";
8+
import styled from "styled-components";
9+
import { CardPickState } from "../types/CardPickState";
10+
import { DeckState } from "../types/DeckState";
1211
interface PropTypes {
1312
idx: number;
1413
deckState: DeckState;
@@ -17,13 +16,7 @@ interface PropTypes {
1716
cardPickState: CardPickState[];
1817
}
1918

20-
const Card = ({
21-
idx,
22-
deckState,
23-
setDeckState,
24-
onClick,
25-
cardPickState,
26-
}: PropTypes) => {
19+
const Card = ({ idx, deckState, setDeckState, onClick, cardPickState }: PropTypes) => {
2720
const [isCardShadow, setIsCardShadow] = useState(false);
2821
const [moveDistance, setMoveDistance] = useState(0);
2922
const cardRef = useRef<HTMLDivElement>(null);
@@ -98,11 +91,7 @@ const Card = ({
9891
onClick={handleClickCard}
9992
onAnimationComplete={onAnimationEnd}
10093
>
101-
<CardWrapper
102-
src={CardBack}
103-
alt="카드 뒷면 이미지"
104-
isCardShadow={isCardShadow}
105-
/>
94+
<CardWrapper src={CardBack} alt="카드 뒷면 이미지" isCardShadow={isCardShadow} />
10695
</CardAnimationWrapper>
10796
);
10897
};
@@ -120,8 +109,7 @@ const CardAnimationWrapper = styled(div)`
120109
const CardWrapper = styled(Image)<{ isCardShadow: boolean }>`
121110
border-radius: 8px;
122111
123-
box-shadow: ${({ isCardShadow }) =>
124-
isCardShadow ? "-8px 0px 12px 0px rgba(0, 0, 0, 0.15)" : ""};
112+
box-shadow: ${({ isCardShadow }) => (isCardShadow ? "-8px 0px 12px 0px rgba(0, 0, 0, 0.15)" : "")};
125113
126114
width: 100px;
127115
height: 160px;

src/chat/components/ChatBubble.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { MessageSenderType } from "@/chat/models/messageSender";
2-
import { TarotCardIdType } from "@/tarot/models/tarotCardId";
1+
import { MessageSenderType } from "@/chat/types/messageSender";
2+
import { TarotCardIdType } from "@/tarot/types/tarotCardId";
33
import findCardById from "@/tarot/utils/findCardById";
44
import Image from "next/image";
55
import Link from "next/link";

src/chat/components/ChatBubbleGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MessageType } from "@/chat/models/message";
1+
import { MessageType } from "@/chat/types/message";
22
import { css, styled } from "styled-components";
33
import ChatAvatar from "./ChatAvatar";
44
import ChatBubble from "./ChatBubble";

0 commit comments

Comments
 (0)