diff --git a/front/src/hooks/queries/feed/getProblems.ts b/front/src/hooks/queries/feed/getProblems.ts index 7e27b84..7528407 100644 --- a/front/src/hooks/queries/feed/getProblems.ts +++ b/front/src/hooks/queries/feed/getProblems.ts @@ -2,10 +2,10 @@ import { getUserProblems } from '@services/feed/getProblems'; import { useQuery } from '@tanstack/react-query'; -export const useProblem = () => { +export const useProblem = (date: string | null) => { const { data, isPending, isError, error } = useQuery({ - queryKey: ['userProblems'], - queryFn: getUserProblems, + queryKey: ['userProblems', date], + queryFn: () => (date ? getUserProblems(date) : Promise.resolve([])), refetchOnMount: false, }); diff --git a/front/src/pages/feed/FeedPage.tsx b/front/src/pages/feed/FeedPage.tsx index b8981f7..f99b1b4 100644 --- a/front/src/pages/feed/FeedPage.tsx +++ b/front/src/pages/feed/FeedPage.tsx @@ -90,11 +90,14 @@ const ProfileWrapper = styled.div` const FeedPage = () => { const { isAccessToken } = useTokenStore(); const { selectedDate, setSelectedDate } = useFeedStore(); + const formattedDate = selectedDate + ? dayjs(selectedDate).format('YYYY-MM-DD') + : ''; const { data: problemData, isPending: problemPending, isError: problemError, - } = useProblem(); + } = useProblem(formattedDate); // eslint-disable-next-line @typescript-eslint/naming-convention const formatDay = (_locale: string | undefined, date: Date) => @@ -104,10 +107,6 @@ const FeedPage = () => { setSelectedDate(date); }; - const formattedDate = selectedDate - ? dayjs(selectedDate).format('YYYY-MM-DD') - : ''; - return ( diff --git a/front/src/pages/feed/components/Profile.tsx b/front/src/pages/feed/components/Profile.tsx index 6d22f53..c989fa7 100644 --- a/front/src/pages/feed/components/Profile.tsx +++ b/front/src/pages/feed/components/Profile.tsx @@ -2,11 +2,11 @@ // import axios from 'axios'; import Text from '@components/typography/Text'; +import { useCommits } from '@hooks/queries/feed/getUserCommitQuery'; import { useUserData } from '@hooks/queries/feed/getUserDataQuery'; import DefaultProfileImg from '@assets/HaedalProfile.png'; -// import { useCommits } from '@/hooks/queries/feed/getUserCommitQuery'; // import { useUserDataStore } from '@stores/useUserDataStore'; import styled from '@emotion/styled'; @@ -38,12 +38,12 @@ const Profile = () => { isPending: userPending, isError: userError, } = useUserData(); - // const { data: commit } = useCommits(); + const { data: commit } = useCommits(); const username = userData?.loginId || ''; const profileImg = userData?.profileUrl || DefaultProfileImg; - // const commitNum = commit?.commit || 0; + const commitNum = commit?.count || 0; - // console.log('commit', commit); + // console.log('commit', commit.count); // MSW Test CODE // const { // setUsername, @@ -104,7 +104,7 @@ const Profile = () => { {username}님 반갑습니다! - 오늘의 커밋 개수는 0개 입니다. + 오늘의 커밋 개수는 {commitNum}개 입니다. )} diff --git a/front/src/services/feed/getProblems.ts b/front/src/services/feed/getProblems.ts index b8602c8..97f8b3c 100644 --- a/front/src/services/feed/getProblems.ts +++ b/front/src/services/feed/getProblems.ts @@ -2,9 +2,14 @@ import { BASE_URI } from '@constants/URI'; import { instance } from '@services/API_JWT'; -export const getUserProblems = async () => { +export const getUserProblems = async (date: string) => { try { - const response = await instance.get(`${BASE_URI}/problems`); + const response = await instance.get(`${BASE_URI}/problems`, { + params: { + type: 'DAY', + date: date, + }, + }); return response.data; } catch (error) { console.error('Error fetching UserData:', error); diff --git a/front/src/services/feed/getUserCommit.ts b/front/src/services/feed/getUserCommit.ts index 7cb2a09..5555a9c 100644 --- a/front/src/services/feed/getUserCommit.ts +++ b/front/src/services/feed/getUserCommit.ts @@ -1,10 +1,16 @@ +import dayjs from 'dayjs'; + import { BASE_URI } from '@constants/URI'; import { instance } from '@services/API_JWT'; export const getUserCommit = async () => { + const currentDate = dayjs().format('YYYY-MM-DD'); // 현재 날짜를 yyyy-mm-dd 형식으로 추출 + try { - const response = await instance.get(`${BASE_URI}/problems/count`); + const response = await instance.get( + `${BASE_URI}/problems/count?date=${currentDate}` + ); return response.data; } catch (error) { console.error('Error fetching UserData:', error);