Skip to content

Commit ff0c36b

Browse files
authored
Merge pull request #115 from oodd-team/feat/OD-152
[OD-152] matching & chatting 도메인 api 응답 수정
2 parents 6737adb + aed0b2a commit ff0c36b

13 files changed

Lines changed: 55 additions & 55 deletions

File tree

src/apis/chatting/dto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// base response 형태를 따르지 않으므로 data 접미사를 사용했습니다.
33
// response
44
export interface ChatRoomData {
5-
chatRoomId: number;
5+
id: number;
66
otherUser: OtherUserDto;
77
latestMessage: LatestMessageDto;
88
}
99

1010
export interface OtherUserDto {
1111
id: number;
1212
nickname: string;
13-
profileUrl: string;
13+
profilePictureUrl: string;
1414
}
1515

1616
export interface LatestMessageDto {

src/apis/matching/dto.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseSuccessResponse } from '../core/dto';
1+
import type { BaseSuccessResponse } from '@apis/core/dto';
22

33
// 매칭 요청
44
// request
@@ -12,36 +12,37 @@ export interface CreateMatchingRequest {
1212
export type CreateMatchingResponse = BaseSuccessResponse<CreateMatchingData>;
1313

1414
export interface CreateMatchingData {
15+
id: number; // matchingId
1516
chatRoomId: number;
16-
fromUserId: number;
17-
toUserId: number;
17+
requesterId: number;
18+
targetId: number;
1819
}
1920

2021
// 매칭 리스트 조회
2122
// response
2223
export type GetMatchingListResponse = BaseSuccessResponse<GetMatchingListData>;
2324

2425
export interface GetMatchingListData {
25-
isMatching: boolean; // 매칭 요청 존재 여부
26-
matchingsCount: number; // 매칭 요청 개수
26+
hasMatching: boolean;
27+
matchingsCount: number;
2728
matching: MatchingDto[];
2829
}
2930

3031
export interface MatchingDto {
31-
matchingId: number;
32+
id: number; // matchingId
3233
requester: RequesterDto;
33-
requesterPost: RequesterPostDto;
3434
}
3535

3636
export interface RequesterDto {
37-
requesterId: number;
37+
id: number; // requesterId
3838
nickname: string;
3939
profilePictureUrl: string;
40+
representativePost: RepresentativePost;
4041
}
4142

42-
export interface RequesterPostDto {
43-
postImages: PostImageDto[]; // 대표 게시글 이미지
44-
styleTags: string[]; // 게시글 스타일 태그
43+
export interface RepresentativePost {
44+
postImages: PostImageDto[];
45+
styleTags: string[];
4546
}
4647

4748
export interface PostImageDto {
@@ -59,7 +60,7 @@ export interface ModifyMatchingStatusRequest {
5960
export type ModifyMatchingStatusResponse = BaseSuccessResponse<ModifyMatchingStatusData>;
6061

6162
export interface ModifyMatchingStatusData {
62-
matchingId: number;
63+
id: number; // matchingId
6364
requesterId: number;
6465
targetId: number;
6566
requestStatus: string;

src/apis/matching/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { newRequest } from '../core';
2-
import {
1+
import { newRequest } from '@apis/core';
2+
import type {
33
CreateMatchingRequest,
44
CreateMatchingResponse,
55
GetMatchingListResponse,

src/components/CommentBottomSheet/Comment/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StyledText } from '@components/Text/StyledText';
22
import { CommentLayout, SendContainer, CommentTextarea, SendButton } from './styles';
33
import send from '@assets/default/send-comment.svg';
44
import React, { useEffect, useRef, useState } from 'react';
5-
import { CommentProps } from './dto';
5+
import type { CommentProps } from './dto';
66

77
const Comment: React.FC<CommentProps> = ({ content, sendComment, isModal = false }) => {
88
const [comment, setComment] = useState('');

src/pages/Chats/ChatRoom/ChatBox/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ChatBoxContainer, Textarea, SendButton } from './styles';
22
import { useEffect, useRef, useState } from 'react';
33
import { useRecoilValue } from 'recoil';
44
import { useParams } from 'react-router-dom';
5-
import { OpponentInfoAtom } from '@recoil/util/OpponentInfo';
5+
import { OtherUserAtom } from '@recoil/util/OtherUser';
66
import { useSocket } from '@context/SocketProvider';
77
import { getCurrentUserId } from '@utils/getCurrentUserId';
88

@@ -13,8 +13,8 @@ const ChatBox: React.FC = () => {
1313

1414
const { chatRoomId } = useParams();
1515
const currentUserId = getCurrentUserId();
16-
const opponentInfo = useRecoilValue(OpponentInfoAtom);
17-
const isOpponentValid = !!(opponentInfo && opponentInfo.id);
16+
const otherUser = useRecoilValue(OtherUserAtom);
17+
const isOpponentValid = !!(otherUser && otherUser.id);
1818

1919
useEffect(() => {
2020
if (textareaRef.current && !isOpponentValid) {
@@ -51,7 +51,7 @@ const ChatBox: React.FC = () => {
5151
if (socket) {
5252
const sendMessageRequest = {
5353
chatRoomId: Number(chatRoomId),
54-
toUserId: opponentInfo?.id,
54+
toUserId: otherUser?.id,
5555
content: newMessage,
5656
fromUserId: currentUserId,
5757
createdAt: new Date().toISOString(),

src/pages/Chats/ChatRoom/createExtendedMessages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { chatRoomMessagesData } from '@apis/chatting/dto';
88
export const createExtendedMessages = (
99
allMessages: chatRoomMessagesData[],
1010
userId: number,
11-
opponentInfo: OtherUserDto | null,
11+
otherUser: OtherUserDto | null,
1212
) => {
1313
// DateBar 표시 여부를 결정하는 함수
1414
const isNewDay = (curDate: string, lastDate: string) => {
@@ -57,8 +57,8 @@ export const createExtendedMessages = (
5757
} else {
5858
// 받은 메시지일 경우 rcvdMessage 속성 추가
5959
const rcvdMessage: RcvdMessageProps = {
60-
fromUserNickname: opponentInfo?.nickname || '알수없음',
61-
profilePictureUrl: opponentInfo?.profileUrl || defaultProfile,
60+
fromUserNickname: otherUser?.nickname || '알수없음',
61+
profilePictureUrl: otherUser?.profilePictureUrl || defaultProfile,
6262
content: message.content,
6363
isProfileImageVisible,
6464
isSenderChanged,

src/pages/Chats/ChatRoom/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type { BottomSheetMenuProps } from '@components/BottomSheetMenu/dto';
1818
import type { ModalProps } from '@components/Modal/dto';
1919
import { createExtendedMessages } from './createExtendedMessages';
2020
import { AllMesagesAtom } from '@recoil/Chats/AllMessages';
21-
import { OpponentInfoAtom } from '@recoil/util/OpponentInfo';
21+
import { OtherUserAtom } from '@recoil/util/OtherUser';
2222
import { useSocket } from '@context/SocketProvider';
2323
import Back from '@assets/arrow/left.svg';
2424
import KebabMenu from '@assets/default/more.svg';
@@ -52,7 +52,7 @@ const ChatRoom: React.FC = () => {
5252

5353
const { chatRoomId } = useParams();
5454
const currentUserId = getCurrentUserId();
55-
const opponentInfo = useRecoilValue(OpponentInfoAtom);
55+
const otherUser = useRecoilValue(OtherUserAtom);
5656

5757
// 메시지 수신 시 아래로 스크롤 (스크롤 아래 고정)
5858
const scrollToBottom = (ref: React.RefObject<HTMLDivElement>) => {
@@ -61,21 +61,21 @@ const ChatRoom: React.FC = () => {
6161

6262
// 프로필 사진 클릭 시 프로필 페이지로 이동
6363
const handleUserClick = useCallback(() => {
64-
const opponentId = opponentInfo?.id ? opponentInfo.id : -1;
64+
const opponentId = otherUser?.id ? otherUser.id : -1;
6565
if (opponentId === -1) {
6666
setModalContent('유저 정보를 찾을 수 없습니다.');
6767
setIsStatusModalOpen(true);
6868
} else {
6969
nav(`/users/${opponentId}`);
7070
}
71-
}, [opponentInfo, nav]);
71+
}, [otherUser, nav]);
7272

7373
// 유저 차단 api
7474
const postUserBlock = async () => {
7575
try {
7676
const data: PostUserBlockRequest = {
7777
requesterId: currentUserId,
78-
targetId: opponentInfo?.id || -1,
78+
targetId: otherUser?.id || -1,
7979
action: 'block',
8080
};
8181
const response = await postUserBlockApi(data);
@@ -133,7 +133,7 @@ const ChatRoom: React.FC = () => {
133133
// 메시지 수신 시
134134
useEffect(() => {
135135
// 렌더링에 필요한 정보 추가
136-
const temp = createExtendedMessages(allMessages, currentUserId, opponentInfo);
136+
const temp = createExtendedMessages(allMessages, currentUserId, otherUser);
137137
setExtendedMessages(temp);
138138

139139
// 스크롤 아래로 이동
@@ -230,7 +230,7 @@ const ChatRoom: React.FC = () => {
230230
return (
231231
<OODDFrame>
232232
<TopBar
233-
text={opponentInfo?.nickname || '알수없음'}
233+
text={otherUser?.nickname || '알수없음'}
234234
LeftButtonSrc={Back}
235235
RightButtonSrc={KebabMenu}
236236
onClickLeftButton={() => {

src/pages/Chats/ChatRoomItem/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StyledText } from '@components/Text/StyledText';
22
import { UserImage, ChatRoomItemLayout, LeftBox, RightBox, LatestMessage } from './styles';
33
import { useNavigate } from 'react-router-dom';
44
import { useRecoilState } from 'recoil';
5-
import { OpponentInfoAtom } from '@recoil/util/OpponentInfo';
5+
import { OtherUserAtom } from '@recoil/util/OtherUser';
66
import dayjs from 'dayjs';
77
import relativeTime from 'dayjs/plugin/relativeTime';
88
import 'dayjs/locale/ko';
@@ -11,14 +11,14 @@ import type { ChatRoomData } from '@apis/chatting/dto';
1111
import defaultProfile from '@assets/default/defaultProfile.svg';
1212
dayjs.extend(relativeTime);
1313

14-
const ChatRoomItem: React.FC<ChatRoomData> = ({ chatRoomId, otherUser, latestMessage }) => {
14+
const ChatRoomItem: React.FC<ChatRoomData> = ({ id, otherUser, latestMessage }) => {
1515
const [timeAgo, setTimeAgo] = useState<string | null>(null);
16-
const [, setOpponentInfo] = useRecoilState(OpponentInfoAtom);
16+
const [, setOtherUser] = useRecoilState(OtherUserAtom);
1717
const nav = useNavigate();
1818

1919
const handleChatRoomClick = () => {
20-
setOpponentInfo(otherUser);
21-
nav(`/chats/${chatRoomId}`);
20+
setOtherUser(otherUser);
21+
nav(`/chats/${id}`);
2222
};
2323

2424
useEffect(() => {
@@ -40,7 +40,7 @@ const ChatRoomItem: React.FC<ChatRoomData> = ({ chatRoomId, otherUser, latestMes
4040

4141
return (
4242
<ChatRoomItemLayout onClick={handleChatRoomClick}>
43-
<UserImage src={otherUser?.profileUrl || defaultProfile} alt="user" />
43+
<UserImage src={otherUser?.profilePictureUrl || defaultProfile} alt="user" />
4444
<LeftBox>
4545
<StyledText $textTheme={{ style: 'body2-medium' }} color="#1D1D1D">
4646
{otherUser?.nickname || '알수없음'}

src/pages/Chats/Matching/Cards/Card/index.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ import { handleError } from '@apis/util/handleError';
2626
import type { ModalProps } from '@components/Modal/dto';
2727
import Modal from '@components/Modal';
2828
import { useRecoilState } from 'recoil';
29-
import { OpponentInfoAtom } from '@recoil/util/OpponentInfo';
29+
import { OtherUserAtom } from '@recoil/util/OtherUser';
3030
import type { CardProps } from './dto';
3131

3232
const Card: React.FC<CardProps> = ({ removeRejectedMatching, matching }) => {
3333
const [isStatusModalOpen, setIsStatusModalOpen] = useState(false);
3434
const [modalContent, setModalContent] = useState('알 수 없는 오류가 발생했습니다.\n관리자에게 문의해 주세요.');
35-
const [, setOpponentInfo] = useRecoilState(OpponentInfoAtom);
35+
const [, setOtherUser] = useRecoilState(OtherUserAtom);
3636
const nav = useNavigate();
3737
const requester = matching.requester;
3838

3939
const handleUserClick = () => {
40-
nav(`/users/${matching.requester.requesterId}`);
40+
nav(`/users/${requester.id}`);
4141
};
4242

4343
const handleRejectButtonClick = () => {
@@ -52,16 +52,16 @@ const Card: React.FC<CardProps> = ({ removeRejectedMatching, matching }) => {
5252
const modifyMatchingStatus = async (status: 'accept' | 'reject') => {
5353
try {
5454
console.log(matching);
55-
const response = await modifyMatchingStatusApi(matching.matchingId, { requestStatus: status });
55+
const response = await modifyMatchingStatusApi(matching.id, { requestStatus: status });
5656

5757
if (response.isSuccess) {
5858
removeRejectedMatching(); // 매칭 리스트에서 해당 매칭을 제거
5959

6060
if (status === 'accept') {
61-
setOpponentInfo({
62-
id: requester.requesterId,
61+
setOtherUser({
62+
id: requester.id,
6363
nickname: requester.nickname,
64-
profileUrl: requester.profilePictureUrl,
64+
profilePictureUrl: requester.profilePictureUrl,
6565
});
6666
nav(`/chats/${response.data.chatRoomId}`);
6767
}
@@ -91,12 +91,12 @@ const Card: React.FC<CardProps> = ({ removeRejectedMatching, matching }) => {
9191
{requester.nickname || '알수없음'}
9292
</StyledText>
9393
<div className="row-flex">
94-
{matching.requesterPost.styleTags.map((tag, index) => (
94+
{requester.representativePost.styleTags.map((tag, index) => (
9595
<div className="row-flex" key={tag}>
9696
<StyledText $textTheme={{ style: 'caption2-regular' }} color={theme.colors.gray1}>
9797
{tag}
9898
</StyledText>
99-
{index < matching.requesterPost.styleTags.length - 1 && (
99+
{index < requester.representativePost.styleTags.length - 1 && (
100100
<StyledText $textTheme={{ style: 'caption2-regular' }} color={theme.colors.gray1}>
101101
,&nbsp;
102102
</StyledText>
@@ -105,7 +105,7 @@ const Card: React.FC<CardProps> = ({ removeRejectedMatching, matching }) => {
105105
))}
106106
</div>
107107
</ProfileInfo>
108-
<SeeMore onClick={() => nav(`/users/${requester.requesterId}`)}>
108+
<SeeMore onClick={() => nav(`/users/${requester.id}`)}>
109109
<StyledText $textTheme={{ style: 'caption2-regular' }} color="#8e8e93">
110110
OOTD 더 보기
111111
</StyledText>
@@ -123,7 +123,7 @@ const Card: React.FC<CardProps> = ({ removeRejectedMatching, matching }) => {
123123
modules={[Pagination]}
124124
className="childSwiper"
125125
>
126-
{matching.requesterPost.postImages.map((postImage) => (
126+
{requester.representativePost.postImages.map((postImage) => (
127127
<SwiperSlide key={postImage.url}>
128128
<img src={postImage.url} alt="OOTD" className="slide-image-small" />
129129
<div className="blur"></div>

src/pages/Chats/Matching/Cards/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const Cards: React.FC<CardsProps> = ({ decreaseMatchingCount }) => {
4747
className="parentSwiper"
4848
>
4949
{matchings.map((matching, index) => (
50-
<SwiperSlide key={matching.matchingId}>
50+
<SwiperSlide key={matching.id}>
5151
<Card
5252
matching={matching} // 데이터를 Card 컴포넌트에 전달
5353
removeRejectedMatching={() => removeRejectedMatching(index)}

0 commit comments

Comments
 (0)