Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

로딩에 대해서 선언적으로 리팩토링을 진행한다. #900

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e268bd3
refactor: api요청 폴더별로 분류
liswktjs Oct 20, 2022
2ce778d
fix: 유실된 import 문 추가
liswktjs Oct 20, 2022
ca036e2
refactor: axiosInstance로 중복되는 선언 제거
liswktjs Oct 20, 2022
b3621dd
feat: Article의 응답값에 대한 타입 정의
liswktjs Oct 20, 2022
75cfbd3
fix: api에 새로 정리한 타입 적용
liswktjs Oct 20, 2022
32dc734
fix: develop 충돌 해결
liswktjs Oct 21, 2022
cbaeaf5
refactor: article관련 타입 재정립 및 반영 진행
liswktjs Oct 24, 2022
6836e88
refactor: component단에서의 타입 리팩토링 적용
liswktjs Oct 24, 2022
e8219f4
refactor: author에 대한 타입 분리 진행 및 tsc를 통해 확인된 타입들에 대해서 리팩토링 진행
liswktjs Oct 24, 2022
56cd069
fix: type명 끝에 type 붙이기로 수정
liswktjs Oct 24, 2022
aecea2f
refactor: 기존에 types하위에 존재하던 type 제거 및 새롭게 짠 commentType 적용
liswktjs Oct 24, 2022
035f2d9
refactor: 기존에 있던 HashTagType삭제 및 변동된 타입 적용
liswktjs Oct 24, 2022
70c4152
refactor: searchType에 대한 위치 조정 및 새로운 searchType 적용
liswktjs Oct 24, 2022
15a9ff9
refactor: tempArticle과 관련된 타입끼리 분리 및 적용
liswktjs Oct 24, 2022
dcf2146
refactor: 투표에 대한 타입 분리 및 적용
liswktjs Oct 24, 2022
b2c1d81
이미지 리사이징이 되지 않는 문제 해결 (#879)
hwangstar156 Oct 26, 2022
c32e4b8
fix: props interface로 분리
liswktjs Nov 4, 2022
8d41768
type: interface 로 prop 분리
liswktjs Nov 4, 2022
920c59f
fix: props interface로분리
liswktjs Nov 4, 2022
3cc21f1
fix: main에서 hotfix한 내용들을 반영한다
liswktjs Nov 5, 2022
3c92682
fix: develop의 환경 변수 설정 반영
liswktjs Nov 5, 2022
12018b3
feat: loading에 대한 처리를 Suspense로 위임
hwangstar156 Nov 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/__test__/vote/useGetVote.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { QueryClient, QueryClientProvider } from 'react-query';
import { BrowserRouter } from 'react-router-dom';

import { registerVoteItems } from '@/api/vote';
import { registerVoteItems } from '@/api/vote/vote';
import useVote from '@/hooks/vote/useGetVote';
import { VoteHandler } from '@/mock';
import { theme } from '@/styles/Theme';
Expand Down
209 changes: 0 additions & 209 deletions frontend/src/api/article.ts

This file was deleted.

171 changes: 171 additions & 0 deletions frontend/src/api/article/article.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import {
DetailArticleResponseType,
TotalArticleInquiredResponseType,
} from '@/api/article/articleType';
import { convertSort } from '@/utils/converter';
import { generateAxiosInstanceWithAccessToken } from '@/utils/generateAxiosInstance';

export interface WritingArticlesProp {
title: string;
content: string;
category: string;
}

export const postWritingArticle = (article: WritingArticlesProp) => {
const axiosInstance = generateAxiosInstanceWithAccessToken();
return axiosInstance.post('/api/articles', article);
};

export const getPopularArticles = async () => {
const axiosInstance = generateAxiosInstanceWithAccessToken();
const { data } = await axiosInstance.get<TotalArticleInquiredResponseType>(
'/api/articles?category=all&sort=views&size=10',
);
return data;
};

export const getDetailArticle = async (id: string) => {
const axiosInstance = generateAxiosInstanceWithAccessToken();
const { data } = await axiosInstance.get<DetailArticleResponseType>(`/api/articles/${id}`);

return data;
};

interface getArticleProps {
category: string;
sort: '추천순' | '조회순' | '최신순';
cursorId: string;
cursorViews: string;
cursorLikes: string;
}

export const getAllArticle = async ({
category,
sort,
cursorId,
cursorViews,
cursorLikes,
}: getArticleProps) => {
if (sort === '추천순') {
const data = await getAllArticlesByLikes({ category, cursorId, cursorLikes });
return data;
}

const data = await getAllArticleByViewsOrLatest({
category,
sort,
cursorId,
cursorViews,
});
return data;
};

interface getAllArticleByViewsOrLatestProps {
category: string;
sort: '추천순' | '조회순' | '최신순';
cursorId: string;
cursorViews: string;
}

export const getAllArticleByViewsOrLatest = async ({
category,
sort,
cursorId,
cursorViews,
}: getAllArticleByViewsOrLatestProps) => {
const currentSort = convertSort(sort);
const axiosInstance = generateAxiosInstanceWithAccessToken();
const { data } = await axiosInstance.get<TotalArticleInquiredResponseType>(
`/api/articles?category=${category}&sort=${currentSort}&cursorId=${cursorId}&cursorViews=${cursorViews}&size=6`,
);
return {
articles: data.articles,
hasNext: data.hasNext,
cursorId:
data.articles && data.articles[data.articles.length - 1]
? String(data.articles[data.articles.length - 1].id)
: '',
cursorViews:
data.articles && data.articles[data.articles.length - 1]
? String(data.articles[data.articles.length - 1].views)
: '',
cursorLikes:
data.articles && data.articles[data.articles.length - 1]
? String(data.articles[data.articles.length - 1].likeCount)
: '',
};
};

interface getAllArticlesByLikesProps {
category: string;
cursorId: string;
cursorLikes: string;
}

export const getAllArticlesByLikes = async ({
category,
cursorId,
cursorLikes = '',
}: getAllArticlesByLikesProps) => {
const axiosInstance = generateAxiosInstanceWithAccessToken();

const { data } = await axiosInstance.get<TotalArticleInquiredResponseType>(
`/api/articles/likes?category=${category}&cursorId=${cursorId}&cursorLikes=${cursorLikes}&size=6`,
);

return {
articles: data.articles,
hasNext: data.hasNext,
cursorId:
data && data.articles[data.articles.length - 1]
? String(data.articles[data.articles.length - 1].id)
: '',
cursorLikes:
data && data.articles[data.articles.length - 1]
? String(data.articles[data.articles.length - 1].likeCount)
: '',
cursorViews:
data.articles && data.articles[data.articles.length - 1]
? String(data.articles[data.articles.length - 1].views)
: '',
};
};

interface postArticleProps {
article: {
id: string;
title: string;
content: string;
};
}

export const postArticle = (article: postArticleProps['article']) => {
const axiosInstance = generateAxiosInstanceWithAccessToken();
return axiosInstance.post<{ id: number; category: string }>(`/api/articles/${article.id}`, {
title: article.title,
content: article.content,
});
};

interface putArticleProps {
article: {
id: string;
title: string;
content: string;
tag: string[];
};
}

export const putArticle = (article: putArticleProps['article']) => {
const axiosInstance = generateAxiosInstanceWithAccessToken();
return axiosInstance.put<{ id: number; category: string }>(`/api/articles/${article.id}`, {
title: article.title,
content: article.content,
tag: article.tag,
});
};

export const deleteArticle = (id: string) => {
const axiosInstance = generateAxiosInstanceWithAccessToken();
return axiosInstance.delete<never, unknown, unknown>(`/api/articles/${id}`);
};
Loading