Skip to content

Commit 897f62c

Browse files
피드 조회수 API 연결 (#1223)
* feat: update v2 api schema(type) * feat: add PostViewsResponse * feat: add views fetch function * feat: add views mutation function * feat: 조회수 API 연결 * fix: 모임 개설 퍼널 개선으로 인해 빠진 schema optional로 변경됨에 따라 nullish 처리
1 parent 41d665b commit 897f62c

File tree

8 files changed

+162
-17
lines changed

8 files changed

+162
-17
lines changed

pages/post/index.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { api } from '@api/index';
77
import { useMeetingQueryOption } from '@api/meeting/query';
88
import { PostCommentWithMentionRequest } from '@api/mention';
99
import { useMutationPostCommentWithMention } from '@api/mention/mutation';
10-
import { useDeletePostMutation, usePostLikeMutation, useUpdatePostLikeMutation } from '@api/post/mutation';
10+
import {
11+
useDeletePostMutation,
12+
usePostLikeMutation,
13+
usePostViewsMutation,
14+
useUpdatePostLikeMutation,
15+
} from '@api/post/mutation';
1116
import { useGetPostDetailQueryOption, useGetPostListInfiniteQuery } from '@api/post/query';
1217
import { useUserProfileQueryOption } from '@api/user/query';
1318
import LikeButton from '@common/button/LikeButton';
@@ -59,6 +64,8 @@ export default function PostPage() {
5964
toggleCommentLike(commentId);
6065
};
6166

67+
const { mutate: mutatePostViews, data: viewCount } = usePostViewsMutation(query.id as string);
68+
6269
const { setTarget } = useIntersectionObserver({
6370
onIntersect: entries => {
6471
const entry = entries[0];
@@ -182,15 +189,22 @@ export default function PostPage() {
182189
if (allMeetingPosts?.length !== 5) fetchNextPage();
183190
}, [hasNextPage, allMeetingPosts, fetchNextPage]);
184191

192+
useEffect(() => {
193+
if (query.id) {
194+
mutatePostViews();
195+
}
196+
}, [query.id, mutatePostViews]);
197+
185198
// TODO: loading 스켈레톤 UI가 있으면 좋을 듯
186-
if (!post) return <Loader />;
199+
if (!post || !viewCount) return <Loader />;
187200

188201
const isMine = post.user.id === me?.id;
189202

190203
return (
191204
<Container>
192205
<FeedPostViewer
193206
post={post}
207+
viewCount={viewCount.viewCount}
194208
Actions={FeedActionsContainer({
195209
postId: post.id,
196210
isMine: isMine,

src/__generated__/schema2.d.ts

Lines changed: 123 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/post/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
GetPostListResponse,
44
PostPostLikeResponse,
55
PostPostResponse,
6+
PostViewsResponse,
67
PutPostResponse,
78
} from '@api/post/type';
89
import { FormCreateType, FormEditType } from '@shared/feed/Modal/feedSchema';
@@ -42,3 +43,8 @@ export const deletePost = async (postId: number) => {
4243
const { data } = await api.delete(`/post/v2/${postId}`);
4344
return data;
4445
};
46+
47+
export const postViews = async (postId: number) => {
48+
const { data } = await api.post<PostViewsResponse>(`/post/v2/${postId}/views`);
49+
return data;
50+
};

src/api/post/mutation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import PostQueryKey from '@api/post/PostQueryKey';
22
import { GetPostDetailResponse, GetPostListResponse } from '@api/post/type';
33
import { InfiniteData, useMutation, useQueryClient } from '@tanstack/react-query';
44
import { produce } from 'immer';
5-
import { deletePost, postPostLike } from '.';
5+
import { deletePost, postPostLike, postViews } from '.';
66

77
export const useDeletePostMutation = () => {
88
const queryClient = useQueryClient();
@@ -86,3 +86,9 @@ export const usePostLikeMutation = (queryId: string) => {
8686
},
8787
});
8888
};
89+
90+
export const usePostViewsMutation = (queryId: string) => {
91+
return useMutation({
92+
mutationFn: () => postViews(+queryId),
93+
});
94+
};

src/api/post/type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ export type PutPostResponse =
1414

1515
export type PostPostLikeResponse =
1616
paths['/post/v2/{postId}/like']['post']['responses']['201']['content']['application/json;charset=UTF-8'];
17+
18+
export type PostViewsResponse =
19+
paths['/post/v2/{postId}/views']['post']['responses']['200']['content']['application/json;charset=UTF-8'];

src/domain/detail/Information/constant.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const MeetingDetailList = (detailData: GetMeeting['response']) => [
4848
{
4949
key: '진행 방식',
5050
Title: () => <STitle>진행 방식</STitle>,
51-
Content: () => <SDescription>{parseTextToLink(detailData?.processDesc)}</SDescription>,
51+
Content: () => <SDescription>{parseTextToLink(detailData?.processDesc ?? '')}</SDescription>,
5252
isValid: detailData?.processDesc,
5353
},
5454
{
@@ -77,7 +77,7 @@ export const MeetingDetailList = (detailData: GetMeeting['response']) => [
7777
{
7878
key: '유의사항',
7979
Title: () => <STitle>유의 사항</STitle>,
80-
Content: () => <SDescription>{parseTextToLink(detailData?.note)}</SDescription>,
80+
Content: () => <SDescription>{parseTextToLink(detailData?.note ?? '')}</SDescription>,
8181
isValid: detailData?.note,
8282
},
8383
];

src/shared/feed/FeedPostViewer/FeedPostViewer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dayjs.locale('ko');
2323

2424
interface FeedPostViewerProps {
2525
post: paths['/post/v2/{postId}']['get']['responses']['200']['content']['application/json;charset=UTF-8'];
26+
viewCount: number;
2627
Actions: React.ReactNode[];
2728
CommentLikeSection: React.ReactNode;
2829
CommentList: React.ReactNode;
@@ -33,6 +34,7 @@ interface FeedPostViewerProps {
3334

3435
export default function FeedPostViewer({
3536
post,
37+
viewCount,
3638
Actions,
3739
CommentLikeSection,
3840
CommentList,
@@ -115,7 +117,7 @@ export default function FeedPostViewer({
115117
)}
116118
</ImageSection>
117119
)}
118-
<ViewCount>조회 {post.viewCount}</ViewCount>
120+
<ViewCount>조회 {viewCount}</ViewCount>
119121
</ContentBody>
120122
<Link href={`/detail?id=${post.meeting.id}`} passHref legacyBehavior>
121123
<GroupButton>

src/shared/groupBrowsing/mobileSizeCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const getIsGroupActive = (mstartDate: string, mendDate: string) => {
2424
};
2525

2626
const MobileSizeCard: FC<MeetingData> = ({ id, title, category, mStartDate, mEndDate, status, imageURL }) => {
27-
const isGroupActive = getIsGroupActive(mStartDate, mEndDate);
28-
const newStatus = getNewStatus(status, mStartDate, isGroupActive);
27+
const isGroupActive = getIsGroupActive(mStartDate ?? '', mEndDate ?? '');
28+
const newStatus = getNewStatus(status, mStartDate ?? '', isGroupActive);
2929

3030
return (
3131
<Link href={`/detail?id=${id}`}>

0 commit comments

Comments
 (0)