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

검색 api, 상품 api 연결 #108 #117

Merged
merged 23 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
289e539
feat(queryKeys): queryKey 검색 리스트 추가
seung365 Nov 14, 2024
1366e9b
feat(types): api response type 추가
seung365 Nov 14, 2024
b608202
feat(api): 찜 삭제 api 추가
seung365 Nov 14, 2024
117b6ee
feat(api): 찜 추가 api 추가
seung365 Nov 14, 2024
26bd3fb
chore(data): 안쓰는 목데이터 삭제
seung365 Nov 14, 2024
6af857d
feat(SearchResults): 검색 페이지 api 통해 데이터 보여줌
seung365 Nov 14, 2024
43c4eef
feat(api): 작가 검색 api 추가
seung365 Nov 14, 2024
83eccfa
feat(api): 작품 검색 api 추가
seung365 Nov 14, 2024
80df106
feat(ProductItem): 상품 좋아요 기능 추가
seung365 Nov 14, 2024
8953f83
feat(component): 목데이터 대신 실제 검색 결과 보여줌
seung365 Nov 14, 2024
2942b28
feat(HorizontalFrame): 실제 api결과에 따른 Item 속성 수정
seung365 Nov 14, 2024
f9d1b30
Merge branch 'Weekly11' of https://github.com/kakao-tech-campus-2nd-s…
seung365 Nov 14, 2024
b492b8e
feat(api): 프로필 가져오는 api 구현
seung365 Nov 14, 2024
3d070e5
feat(api): 상품 상세정보 가져오는 api 구현
seung365 Nov 14, 2024
27789e9
feat(types): 작가 프로필, 상품 상세 정보 가져오는 api response 구현
seung365 Nov 14, 2024
a6afd8a
feat(queryKeys): 작가 프로필, 상품 상세정보 쿼리 키 추가
seung365 Nov 14, 2024
f8d2b68
chore(SearchResults): import 정렬
seung365 Nov 14, 2024
04e5154
feat(page): 상품 상세 정보 페이지 구현
seung365 Nov 14, 2024
8f5d596
feat(page): 작가 상세 정보 페이지 구현
seung365 Nov 14, 2024
b8abf5e
feat(Thumbnail): navigate 추가
seung365 Nov 14, 2024
c765896
chore(type): thumbnail 타입 추가 수정
seung365 Nov 14, 2024
5b9effe
feat(queryKeys): 아티스트 프로필 쿼리 키 추가
seung365 Nov 15, 2024
0aaacc5
Merge branch 'Weekly11' of https://github.com/kakao-tech-campus-2nd-s…
seung365 Nov 15, 2024
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
22 changes: 22 additions & 0 deletions src/apis/artists/useGetProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useSuspenseQuery } from '@tanstack/react-query';

import { APIResponse, ProfileResponse } from '@/types';
import fetchInstance from '../fetchInstance';
import QUERY_KEYS from '../queryKeys';

async function getProfile(artistInfoId: number | null): Promise<APIResponse<ProfileResponse>> {
const response = await fetchInstance().get(`/artists/${artistInfoId}`);

return response.data;
}

const useGetProfile = (artistInfoId: number | null) => {
const { data } = useSuspenseQuery<APIResponse<ProfileResponse>, Error>({
queryKey: [QUERY_KEYS.ARTIST_PROFILE, artistInfoId],
queryFn: () => getProfile(artistInfoId),
});

return { data };
};

export default useGetProfile;
78 changes: 0 additions & 78 deletions src/apis/data/searchArtist.ts

This file was deleted.

69 changes: 0 additions & 69 deletions src/apis/data/searchWork.ts

This file was deleted.

22 changes: 22 additions & 0 deletions src/apis/products/useGetDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useSuspenseQuery } from '@tanstack/react-query';

import { APIResponse, ProductResponse } from '@/types';
import fetchInstance from '../fetchInstance';
import QUERY_KEYS from '../queryKeys';

async function getDetail(productId: number | null): Promise<APIResponse<ProductResponse>> {
const response = await fetchInstance().get(`/products/${productId}`);

return response.data;
}

const useGetDetail = (productId: number | null) => {
const { data } = useSuspenseQuery<APIResponse<ProductResponse>, Error>({
queryKey: [QUERY_KEYS.PRODUCT_DETAIL, productId],
queryFn: () => getDetail(productId),
});

return { data };
};

export default useGetDetail;
4 changes: 4 additions & 0 deletions src/apis/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ const QUERY_KEYS = {
FEED: 'feed',
FOLLOW_LIST: 'followList',
USER_INFO: 'userInfo',
ARTIST_LIST: 'artistList',
PRODUCT_LIST: 'productList',
CHAT_ROOM: 'chatRoom',
PRODUCT_DETAIL: 'productDetail',
ARTIST_PROFILE: 'artistProfile',
};

export default QUERY_KEYS;
40 changes: 40 additions & 0 deletions src/apis/search/useSearchArtists.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { APIResponse, InfiniteAPIResponse, SearchArtistsResponse } from '@/types';
import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
import fetchInstance from '../instance';
import QueryKeys from '../queryKeys';

async function searchArtists(
{ pageParam = 0 }: { pageParam: number },
query: string,
): Promise<APIResponse<SearchArtistsResponse>> {
const size = 20;
const response = await fetchInstance().get('/artists/search', {
params: {
query,
size,
page: pageParam,
},
});
return response.data;
}

const useSearchArtists = (query: string) => {
const queryResult = useSuspenseInfiniteQuery<
APIResponse<SearchArtistsResponse>,
Error,
InfiniteAPIResponse<SearchArtistsResponse>,
[string, string],
number
>({
queryKey: [QueryKeys.ARTIST_LIST, query],
queryFn: ({ pageParam }) => searchArtists({ pageParam }, query),
initialPageParam: 0,
getNextPageParam: (lastPage, allPages) => {
return lastPage.data.hasNext ? allPages.length : undefined;
},
});

return queryResult;
};

export default useSearchArtists;
42 changes: 42 additions & 0 deletions src/apis/search/useSearchProducts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { APIResponse, InfiniteAPIResponse, SearchProductsResponse } from '@/types';
import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
import fetchInstance from '../instance';
import QueryKeys from '../queryKeys';

async function searchProducts(
{ pageParam = 0 }: { pageParam: number },
query: string,
): Promise<APIResponse<SearchProductsResponse>> {
const size = 20;
const sort = 'LATEST';
const response = await fetchInstance().get('/products', {
params: {
query,
size,
page: pageParam,
sort,
},
});
return response.data;
}

const useSearchProducts = (query: string) => {
const queryResult = useSuspenseInfiniteQuery<
APIResponse<SearchProductsResponse>,
Error,
InfiniteAPIResponse<SearchProductsResponse>,
[string, string],
number
>({
queryKey: [QueryKeys.PRODUCT_LIST, query],
queryFn: ({ pageParam }) => searchProducts({ pageParam }, query),
initialPageParam: 0,
getNextPageParam: (lastPage, allPages) => {
return lastPage.data.hasNext ? allPages.length : undefined;
},
});

return queryResult;
};

export default useSearchProducts;
26 changes: 26 additions & 0 deletions src/apis/users/useDeleteLikes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';

import fetchInstance from '../fetchInstance';
import QUERY_KEYS from '../queryKeys';

async function deleteLikes(productId: number): Promise<void> {
await fetchInstance().delete(`/products/${productId}/likes`);
}

const useDeleteLikes = () => {
const queryClient = useQueryClient();

const { mutate, status } = useMutation<void, Error, number>({
mutationFn: (productId: number) => deleteLikes(productId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.PRODUCT_LIST] });
},
onError: (error) => {
console.error('Failed to delete likes:', error);
},
});

return { mutate, status };
};

export default useDeleteLikes;
20 changes: 20 additions & 0 deletions src/apis/users/usePostLikes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useMutation } from '@tanstack/react-query';

import fetchInstance from '../fetchInstance';

async function postLikes(productId: number): Promise<void> {
await fetchInstance().post(`/products/${productId}/likes`, {});
}

const usePostLikes = () => {
const { mutate, status } = useMutation<void, Error, number>({
mutationFn: (productId: number) => postLikes(productId),
onError: (error) => {
console.error('API call failed:', error);
},
});

return { mutate, status };
};

export default usePostLikes;
2 changes: 1 addition & 1 deletion src/components/common/ArtistItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ArtistItem = ({ artistId, author, like, follower, src, alt, isFollow }: Ar

return (
<Wrapper>
<Thumbnail ratio="square" src={src} alt={alt} />
<Thumbnail ratio="square" src={src} alt={alt} id={artistId} type="artist" />
<MidWrapper>
<p style={{ fontSize: 'var(--font-size-sm)', fontWeight: 'bold' }}>{author}</p>
<FollowButton
Expand Down
Loading