-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 리뷰 api 연결
- Loading branch information
Showing
9 changed files
with
103 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import instance from '@apis/instance'; | ||
import { AxiosError } from 'axios'; | ||
|
||
export interface Review { | ||
reviewId: number; | ||
username: string; | ||
rating: number; | ||
isMonth: boolean; | ||
contentKorean: string; | ||
contentOriginal: string; | ||
reviewImage: string; | ||
usefulCount: number; | ||
recommendCount: number; | ||
likeCount: number; | ||
} | ||
|
||
export interface GetReviewResponse { | ||
success: boolean; | ||
data: { | ||
goodReviews: Review[]; | ||
badReviews: Review[]; | ||
}; | ||
error: null | string; | ||
} | ||
|
||
export const getReview = async (productId: number): Promise<GetReviewResponse> => { | ||
try { | ||
const response = await instance.get<GetReviewResponse>(`/api/products/${productId}/reviews`); | ||
return response.data; | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
throw error.response?.data || new Error('An error occurred'); | ||
} | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { getReview, GetReviewResponse } from './getReview'; | ||
|
||
const useReviewQueries = ({ productId }: { productId: number }) => { | ||
const QUERY_KEY = { | ||
PRODUCT_REVIEW: 'review', | ||
}; | ||
|
||
const { data, error } = useQuery<GetReviewResponse>({ | ||
queryKey: [QUERY_KEY.PRODUCT_REVIEW, productId], | ||
queryFn: () => getReview(productId), | ||
}); | ||
|
||
return { data, error }; | ||
}; | ||
|
||
export default useReviewQueries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters