Skip to content

Commit

Permalink
미구현 페이지들 구현 및 버그 수정
Browse files Browse the repository at this point in the history
✨ 미구현 페이지들 구현 및 버그 수정
  • Loading branch information
Chaeyeon1 authored Nov 29, 2023
2 parents cd4d400 + 76cd352 commit ef36917
Show file tree
Hide file tree
Showing 34 changed files with 679 additions and 424 deletions.
14 changes: 9 additions & 5 deletions client/src/api/blog-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IBlog, IChangeBlogName, IPost, ISidebar } from '@/types/dto';
import { defaultInstance } from '.';
import { defaultInstance, unAxiosDefaultInstance } from '.';
import { useQuery } from '@tanstack/react-query';

// 초기 블로그 생성
Expand Down Expand Up @@ -44,13 +44,17 @@ export const useGetSidebarQuery = (params: ISidebar) => {
return { data, isLoading, error };
};

export const getIsNewBlogApi = async () => {
const { data } = await defaultInstance.get('/is/new/blog');
export const getIsNewBlogApi = async (token?: string | null) => {
const { data } = await unAxiosDefaultInstance.get('/is/new/blog', {
headers: {
Authorization: `Bearer ${token}`,
},
});

return data;
};

export const useGetIsNewBlogQuery = () => {
const { isLoading, error, data } = useQuery([`isNewBlog`], () => getIsNewBlogApi(), {});
export const useGetIsNewBlogQuery = (token?: string | null) => {
const { isLoading, error, data } = useQuery([`isNewBlog`], () => getIsNewBlogApi(token), {});
return { data, isLoading, error };
};
40 changes: 20 additions & 20 deletions client/src/api/category-api.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import { ICategoryParams, IDeleteCategory, IPostCategory, IPutCategory } from "@/types/dto";
import { defaultInstance } from ".";
import { useQuery } from "@tanstack/react-query";
import { ICategoryParams, IDeleteCategory, IPostCategory, IPutCategory } from '@/types/dto';
import { defaultInstance } from '.';
import { useQuery } from '@tanstack/react-query';

//카테고리 이름/pr연동여부 가져오기
export const GetCategoryApi = async (params: ICategoryParams) => {
const { data } = await defaultInstance.get('/category', { params });
return data;
const { data } = await defaultInstance.get('/category', { params });

return data;
};
export const useGetCategoryQuery = (params: ICategoryParams) => {
const { isLoading, error, data } = useQuery(['category', params], () => GetCategoryApi(params));
return { isLoading, error, data };

export const useGetCategoryQuery = (params: ICategoryParams) => {
const { isLoading, error, data } = useQuery(['category', params], () => GetCategoryApi(params));

return { isLoading, error, data };
};

//카테고리 생성
export const PostCategoryApi = async (body: IPostCategory) => {
const { data } = await defaultInstance.post('/category', body);
return data;
const { data } = await defaultInstance.post('/category', body);
return data;
};

//카테고리 이름 수정
export const PutCategoryApi = async (body: IPutCategory) => {
const { data } = await defaultInstance.put('/category', body);
return data;
const { data } = await defaultInstance.put('/category', body);
return data;
};

//카테고리 삭제
export const DeleteCategoryApi = async (params: IDeleteCategory) => {
const { data } = await defaultInstance.delete('/category', {
params,
});
return data;
};
const { data } = await defaultInstance.delete('/category', {
params,
});
return data;
};
18 changes: 18 additions & 0 deletions client/src/api/collect-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ICollect,
ICollectContent,
ISearch,
ISearchContent,
ISearchHashtag,
ISearchTitle,
Expand All @@ -25,6 +26,23 @@ export const useGetCollectDataQuery = (params: ICollect) => {
return { data, isLoading, error };
};

const GetColletSearchApi = async (params: ISearch) => {
const { data } = await defaultInstance.get(`/search`, { params });

return data;
};

export const useGetCollectSearchQuery = (params: ISearch) => {
const { isLoading, error, data } = useQuery(
[`search`, params],
() => GetColletSearchApi(params),
{
enabled: !!params.value,
},
);
return { data, isLoading, error };
};

const GetColletSearchUserApi = async (params: ISearchUser) => {
const { data } = await defaultInstance.get(`/search/user`, { params });

Expand Down
42 changes: 25 additions & 17 deletions client/src/api/friend-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { IDeleteFriend, IFriendAllow, IFriendReadParams, IFriendRequest, IFriendSearchParams, IFriendsParams } from '@/types/dto';
import {
IDeleteFriend,
IFriendAllow,
IFriendReadParams,
IFriendRequest,
IFriendSearchParams,
IFriendsParams,
} from '@/types/dto';
import { defaultInstance } from '.';
import { useQuery } from '@tanstack/react-query';

Expand All @@ -16,31 +23,30 @@ export const useGetFriendQuery = (params: IFriendsParams) => {

//친구 검색
export const GetFriendSearchApi = async (params: IFriendSearchParams) => {
const {data} = await defaultInstance.get('/search/friend/name', {params});
const { data } = await defaultInstance.get('/search/friend/name', { params });

return data;
}
};

export const useGetFriendSearchQuery = (params: IFriendSearchParams) => {
const {isLoading, error, data } = useQuery(['search', params], () => GetFriendSearchApi(params));
const { isLoading, error, data } = useQuery(['search', params], () => GetFriendSearchApi(params));

return {isLoading, error, data };
}
return { isLoading, error, data };
};

//친구 요청
//친구 요청
export const PutFriendRequestApi = async (body: IFriendRequest) => {
const { data } = await defaultInstance.put(`/friend?userId=${body.userId}`,
body,
);
const { data } = await defaultInstance.put(`/friend?userId=${body.userId}`, body);

return data;
}
};

//친구 요청 수락/거절
export const PutFriendAllowApi = async (body: IFriendAllow) => {
const { data } = await defaultInstance.put(`/friend/allow?isAccept=${body.isAccept}&userId=${body.userId}`,
body,
);
const { data } = await defaultInstance.put(
`/friend/allow?isAccept=${body.isAccept}&userId=${body.userId}`,
body,
);

return data;
};
Expand All @@ -56,12 +62,14 @@ export const DeleteFriendApi = async (params: IDeleteFriend) => {

//새 포스트 읽음 유무
export const GetFriendReadApi = async (params: IFriendReadParams) => {
const { data } = await defaultInstance.get('/friend/read', {params});
const { data } = await defaultInstance.get('/friend/read', { params });

return data;
};

export const useGetFriendReadQuery = (params: IFriendReadParams) => {
const { isLoading, error, data } = useQuery(['friendRead', params], () => GetFriendReadApi(params));
const { isLoading, error, data } = useQuery(['friendRead', params], () =>
GetFriendReadApi(params),
);
return { data, isLoading, error };
};
};
15 changes: 10 additions & 5 deletions client/src/api/github-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RepositoryParams } from '@/types/dto';
import { Repository, RepositoryParams } from '@/types/dto';
import { defaultInstance } from '.';
import { useQuery } from '@tanstack/react-query';

Expand All @@ -9,14 +9,19 @@ export const getRepositoryApi = async () => {
};

export const useGetRepositoryQuery = () => {
const { isLoading, error, data } = useQuery([`repository`], () => getRepositoryApi());
const {
isLoading,
error,
data: backendData,
} = useQuery([`repository`], () => getRepositoryApi());
const data: Repository = backendData;
return { data, isLoading, error };
};

export const PostRepository = async (body: RepositoryParams) => {
const { data } = await defaultInstance.put('/repository', {
body,
});
const { data } = await defaultInstance.post(
`/repository?categoryId=${body.categoryId}&repo=${body.repo}`,
);

return data;
};
18 changes: 17 additions & 1 deletion client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import axios from 'axios';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const axiosApi = (url: string, data?: any) => {
let token: string | null = '';

if (typeof window !== 'undefined') {
token = localStorage.getItem('token');
}
console.log(token);

const instance = axios.create({
baseURL: url,
withCredentials: true,
Expand All @@ -21,6 +22,21 @@ const axiosApi = (url: string, data?: any) => {
return instance;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const unAxiosApi = (url: string, data?: any) => {
const instance = axios.create({
baseURL: url,
withCredentials: true,
...data,
});

return instance;
};

export const defaultInstance = axiosApi(
'http://glogglogglog-env.eba-fuksumx7.ap-northeast-2.elasticbeanstalk.com',
);

export const unAxiosDefaultInstance = unAxiosApi(
'http://glogglogglog-env.eba-fuksumx7.ap-northeast-2.elasticbeanstalk.com',
);
18 changes: 9 additions & 9 deletions client/src/api/introduce-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { useQuery } from '@tanstack/react-query';

//유저 introducion 가져오기
export const GetIntroducedApi = async (params: IIntroduceParams) => {
const { data } = await defaultInstance.get('/introduce', {params});
return data;
};
export const useGetIntroduceQuery = (params: IIntroduceParams) => {
const { isLoading, error, data } = useQuery(['friend', params], () => GetIntroducedApi(params));
return { data, isLoading, error };
};
const { data } = await defaultInstance.get('/introduce', { params });

return data;
};

export const useGetIntroduceQuery = (params: IIntroduceParams) => {
const { isLoading, error, data } = useQuery(['friend', params], () => GetIntroducedApi(params));
return { data, isLoading, error };
};
14 changes: 11 additions & 3 deletions client/src/api/pr-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IPRParams } from '@/types/dto';
import { IPRParams, IPostedPost, IUnPostedPost } from '@/types/dto';
import { defaultInstance } from '.';
import { useQuery } from '@tanstack/react-query';

Expand All @@ -9,7 +9,10 @@ export const getPRApi = async (params: IPRParams) => {
};

export const useGetPRQuery = (params: IPRParams) => {
const { isLoading, error, data } = useQuery([`prList`], () => getPRApi(params));
const { isLoading, error, data: backendData } = useQuery([`prList`], () => getPRApi(params));

const data: IPostedPost = backendData;

return { data, isLoading, error };
};

Expand All @@ -20,6 +23,11 @@ export const getPRUnPostedApi = async (params: IPRParams) => {
};

export const useGetPRUnpostedQuery = (params: IPRParams) => {
const { isLoading, error, data } = useQuery([`prUnpostedList`], () => getPRUnPostedApi(params));
const {
isLoading,
error,
data: backendData,
} = useQuery([`prUnpostedList`], () => getPRUnPostedApi(params));
const data: IUnPostedPost = backendData;
return { data, isLoading, error };
};
4 changes: 2 additions & 2 deletions client/src/api/reply-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export const PostReplyApi = async (body: IReply) => {
};

export const PatchReplyLikeApi = async (params: IPatchReplyLike) => {
const {data} = await defaultInstance.patch(`/replies/like/${params.replyId}`, params)
const { data } = await defaultInstance.patch(`/replies/like/${params.replyId}`, params);
return data;
}
};
24 changes: 12 additions & 12 deletions client/src/api/userDetail-api.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useQuery } from "@tanstack/react-query";
import { defaultInstance } from ".";
import { useQuery } from '@tanstack/react-query';
import { defaultInstance } from '.';

export const GetUserDetailApi = async () => {
const {data} = await defaultInstance.get('/user/detail');
return data;
};
export const useGetUserDetailQuery = () => {
const {isLoading, error, data } = useQuery(['userDetail'], () => GetUserDetailApi());
return {isLoading, error, data };
};
const { data } = await defaultInstance.get('/user/detail');

return data;
};

export const useGetUserDetailQuery = () => {
const { isLoading, error, data } = useQuery(['userDetail'], () => GetUserDetailApi());

return { isLoading, error, data };
};
14 changes: 13 additions & 1 deletion client/src/api/write-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';
import { defaultInstance } from '.';
import { ITemplateDetailParams, ITemporaryDetailParams } from '@/types/dto';
import { IRemovePostParams, ITemplateDetailParams, ITemporaryDetailParams } from '@/types/dto';

export const PostWriteApi = async (body: FormData) => {
const { data } = await defaultInstance.post('/post', body, {
Expand All @@ -22,6 +22,18 @@ export const UpdateWriteApi = async (body: FormData) => {
return data;
};

export const AddLikeApi = async (params: { postId: number }) => {
const { data } = await defaultInstance.patch(`/post/like?postId=${params?.postId}`);

return data;
};

export const DeleteWriteApi = async (params: IRemovePostParams) => {
const { data } = await defaultInstance.delete('/post', { params });

return data;
};

const GetTemplateApi = async () => {
const { data } = await defaultInstance.get(`/template`);

Expand Down
Loading

0 comments on commit ef36917

Please sign in to comment.