-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from kakao-tech-campus-2nd-step3/feature/foot…
- Loading branch information
Showing
53 changed files
with
1,112 additions
and
513 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { defaultApi } from "@api/axiosInstance"; | ||
|
||
type ReviewData = { | ||
rating: number; | ||
content: string; | ||
product_id?: number; | ||
farm_id?: number; | ||
}; | ||
|
||
const useGetProductReviews = (reviewId: number) => { | ||
const fetcher = () => defaultApi.get(`/api/products/{product_id}/reviews`).then(({ data }) => data); | ||
|
||
return useQuery({ | ||
queryKey: ["reviews", reviewId], | ||
queryFn: fetcher, | ||
}); | ||
}; | ||
|
||
const useCreateProductReviews = () => { | ||
const fetcher = (reviewData: ReviewData) => | ||
defaultApi.post(`/api/products/{product_id}/reviews`, reviewData).then(({ data }) => data); | ||
|
||
return useMutation({ mutationFn: fetcher }); | ||
}; | ||
|
||
const useUpdateReviews = (reviewId: number) => { | ||
const queryClient = useQueryClient(); | ||
|
||
const fetcher = (reviewData: ReviewData) => | ||
defaultApi.put(`/api/reviews/{review_id}`, reviewData).then(({ data }) => data); | ||
|
||
return useMutation({ | ||
mutationFn: fetcher, | ||
onSuccess: () => | ||
queryClient.invalidateQueries({ | ||
queryKey: ["reviews", reviewId], | ||
}), | ||
}); | ||
}; | ||
|
||
const useDeleteReviews = (reviewId: number) => { | ||
const queryClient = useQueryClient(); | ||
|
||
const fetcher = () => defaultApi.delete(`/api/reviews/${reviewId}`).then(({ data }) => data); | ||
|
||
return useMutation({ | ||
mutationFn: fetcher, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: ["reviews", reviewId], | ||
}); | ||
}, | ||
}); | ||
}; | ||
|
||
const useGetFarmReviews = (reviewId: number) => { | ||
const fetcher = () => defaultApi.get(`/api/farms/{farm_id}/reviews`).then(({ data }) => data); | ||
|
||
return useQuery({ | ||
queryKey: ["reviews", reviewId], | ||
queryFn: fetcher, | ||
}); | ||
}; | ||
|
||
const useCreateFarmReviews = () => { | ||
const fetcher = (reviewData: ReviewData) => | ||
defaultApi.post(`/api/farms/{reservationId}/reviews`, reviewData).then(({ data }) => data); | ||
|
||
return useMutation({ mutationFn: fetcher }); | ||
}; | ||
|
||
export { | ||
useGetProductReviews, | ||
useCreateProductReviews, | ||
useUpdateReviews, | ||
useDeleteReviews, | ||
useGetFarmReviews, | ||
useCreateFarmReviews, | ||
}; |
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,30 @@ | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { defaultApi } from "@api/axiosInstance"; | ||
|
||
type StoreData = { | ||
name: string; | ||
address: string; | ||
phone: number; | ||
}; | ||
|
||
const useCreateStore = () => { | ||
const fetcher = (storeData: StoreData) => defaultApi.post(`/api/stores`, storeData).then(({ data }) => data); | ||
|
||
return useMutation({ mutationFn: fetcher }); | ||
}; | ||
|
||
const useUpdateStore = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
const fetcher = (storeData: StoreData) => defaultApi.put(`/api/stores`, storeData).then(({ data }) => data); | ||
|
||
return useMutation({ | ||
mutationFn: fetcher, | ||
onSuccess: () => | ||
queryClient.invalidateQueries({ | ||
queryKey: ["store"], | ||
}), | ||
}); | ||
}; | ||
|
||
export { useCreateStore, useUpdateStore }; |
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,30 @@ | ||
import { useQuery, useMutation } from "@tanstack/react-query"; | ||
import { defaultApi, needAuthDefaultApi } from "@api/axiosInstance"; | ||
|
||
type WishlistData = { | ||
product_id: number; | ||
}; | ||
|
||
const useCreateWishlists = () => { | ||
const fetcher = (wishlistData: WishlistData) => | ||
defaultApi.post(`/api/v1/wishlist/{product_id}`, wishlistData).then(({ data }) => data); | ||
|
||
return useMutation({ mutationFn: fetcher }); | ||
}; | ||
|
||
const useGetWishlists = (type: "product" | "farm") => { | ||
const fetcher = () => needAuthDefaultApi.get(`/api/v1/wishlist`, { params: { type } }).then(({ data }) => data); | ||
|
||
return useQuery({ | ||
queryKey: ["wishlists"], | ||
queryFn: fetcher, | ||
}); | ||
}; | ||
|
||
const useDeleteWishlists = () => { | ||
const fetcher = (wishlistId: number) => defaultApi.delete(`/api/v1/wishlist/${wishlistId}`).then(({ data }) => data); | ||
|
||
return useMutation({ mutationFn: fetcher }); | ||
}; | ||
|
||
export { useCreateWishlists, useGetWishlists, useDeleteWishlists }; |
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
Oops, something went wrong.