Skip to content

Commit

Permalink
fix: Problem 및 Commit API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
KimKyuHoi committed May 29, 2024
1 parent a194618 commit 74597ac
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions front/src/hooks/queries/feed/getProblems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
9 changes: 4 additions & 5 deletions front/src/pages/feed/FeedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -104,10 +107,6 @@ const FeedPage = () => {
setSelectedDate(date);
};

const formattedDate = selectedDate
? dayjs(selectedDate).format('YYYY-MM-DD')
: '';

return (
<Layout>
<DisplayLayout>
Expand Down
10 changes: 5 additions & 5 deletions front/src/pages/feed/components/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -104,7 +104,7 @@ const Profile = () => {
{username}님 반갑습니다!
</Text>
<Text size='var(--size-xs)' weight='600'>
오늘의 커밋 개수는 0개 입니다.
오늘의 커밋 개수는 {commitNum} 입니다.
</Text>
</>
)}
Expand Down
9 changes: 7 additions & 2 deletions front/src/services/feed/getProblems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion front/src/services/feed/getUserCommit.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 74597ac

Please sign in to comment.