Skip to content

Commit

Permalink
서포터가 리뷰 완료한 게시물 개수 조회 api 반영 (#655)
Browse files Browse the repository at this point in the history
feat: 서포터가 리뷰 완료한 게시물 개수 조회 기능 추가

Co-authored-by: 상규 <[email protected]>
  • Loading branch information
tkdrb12 and 상규 authored Oct 11, 2023
1 parent 718310c commit 02a1861
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions frontend/src/apis/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { request } from './fetch';
import {
CreateRunnerPostRequest,
GetDetailedRunnerPostResponse,
GetOtherSupporterPostCountResponse,
GetRunnerPostResponse,
ReviewStatus,
getRunnerPostRequestParams,
Expand Down Expand Up @@ -98,6 +99,10 @@ export const getOtherSupporterProfile = (userId: number) => {
return request.get<GetRunnerProfileResponse>(`/profile/supporter/${userId}`, false);
};

export const getOtherSupporterPostCount = (userId: number) => {
return request.get<GetOtherSupporterPostCountResponse>(`/posts/runner/search/count?supporterId=${userId}`, false);
};

export const postRunnerPostCreation = (formData: CreateRunnerPostRequest) => {
const body = JSON.stringify(formData);
return request.post<void>(`/posts/runner`, body);
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/hooks/query/useOtherSupporterPostCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getOtherSupporterPostCount } from '@/apis/apis';
import { APIError } from '@/types/error';
import { GetOtherSupporterPostCountResponse } from '@/types/runnerPost';
import { useQuery } from '@tanstack/react-query';

export const useOtherSupporterPostCount = (supporterId: number) => {
const queryResult = useQuery<GetOtherSupporterPostCountResponse, APIError>({
queryKey: ['otherSupporterPostCount', supporterId],
queryFn: () => getOtherSupporterPostCount(supporterId),
});

return {
data: queryResult.data as NonNullable<typeof queryResult.data>,
};
};
4 changes: 4 additions & 0 deletions frontend/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ export const handlers = [
rest.patch(`${BATON_BASE_URL}/oauth/logout`, async (req, res, ctx) => {
return res(ctx.status(204));
}),

rest.get(`${BATON_BASE_URL}/posts/runner/search/count`, async (req, res, ctx) => {
return res(ctx.status(200), ctx.set('Content-Type', 'application/json'), ctx.json({ count: 99 }));
}),
];

const handleRequest = (
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/pages/SupporterProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import RunnerPostItem from '@/components/RunnerPost/RunnerPostItem/RunnerPostIte
import useViewport from '@/hooks/useViewport';
import { useOtherSupporterProfile } from '@/hooks/query/useOtherSupporterProfile';
import { useOtherSupporterPost } from '@/hooks/query/useOtherSupporterPost';
import { useOtherSupporterPostCount } from '@/hooks/query/useOtherSupporterPostCount';

/*
* api에 페이지네이션 도입 후 수정 필요
*/
const SupporterProfilePage = () => {
const { supporterId } = useParams();

const { isMobile } = useViewport();

const { data: supporterProfile } = useOtherSupporterProfile(Number(supporterId));
const { data: supporterProfilePost, hasNextPage, fetchNextPage } = useOtherSupporterPost(Number(supporterId));
const { data: supporterProfilePostCount } = useOtherSupporterPostCount(Number(supporterId));

const handleClickMoreButton = () => {
fetchNextPage();
Expand Down Expand Up @@ -60,7 +59,7 @@ const SupporterProfilePage = () => {

<S.ReviewCountWrapper>
<S.ReviewCountTitle>완료된 리뷰</S.ReviewCountTitle>
{/* <S.ReviewCount>{supporterProfilePost?.length}</S.ReviewCount> */}
<S.ReviewCount>{supporterProfilePostCount?.count}</S.ReviewCount>
</S.ReviewCountWrapper>
<S.PostsContainer>
{supporterProfilePost?.map((runnerPostData) => (
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/types/runnerPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ interface requestParams {
}

export interface getRunnerPostRequestParams extends pageParamsRequest, requestParams {}

export interface GetOtherSupporterPostCountResponse {
count: number;
}

0 comments on commit 02a1861

Please sign in to comment.