-
Notifications
You must be signed in to change notification settings - Fork 7
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
[Feature]#27 -부스페이지 API 연결 세팅
- Loading branch information
Showing
10 changed files
with
413 additions
and
91 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
import { instance } from "./instance"; | ||
export const getBoothList = async ({ | ||
day, | ||
category, | ||
location, | ||
is_night, | ||
is_reservable, | ||
}) => { | ||
try { | ||
const res = await instance.get( | ||
`api/v1/booth/?day=${day}&category=${category}&location=${location}&is_night=${is_night}&is_reservable=${is_reservable}` | ||
); | ||
return res; | ||
} catch (err) { | ||
console.log(err); | ||
throw err; | ||
} | ||
}; |
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,10 @@ | ||
import { instance } from "./instance"; | ||
export const getBoothDetail = async ({ booth_id }) => { | ||
try { | ||
const res = await instance.get(`api/v1/booth/detail/${booth_id}`); | ||
return res; | ||
} catch (err) { | ||
console.log(err); | ||
throw err; | ||
} | ||
}; |
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,28 @@ | ||
import axios from "axios"; | ||
|
||
// Axios 인스턴스 생성 | ||
export const instance = axios.create({ | ||
baseURL: import.meta.env.VITE_BASE_URL, | ||
withCredentials: true, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
timeout: 10000, // 10초 타임아웃 설정 | ||
}); | ||
|
||
// 요청 인터셉터 추가 | ||
instance.interceptors.request.use( | ||
(config) => config, | ||
(error) => Promise.reject(error) | ||
); | ||
|
||
// 응답 인터셉터 추가 | ||
instance.interceptors.response.use( | ||
(response) => response, | ||
(error) => { | ||
if (error.code === "ECONNABORTED") { | ||
console.log("Request timeout"); | ||
} | ||
return Promise.reject(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,32 @@ | ||
// src/hooks/useMain.js | ||
import { useState, useEffect } from "react"; | ||
import { getBoothList } from "../apis/booth"; | ||
import { useParams } from "react-router-dom"; | ||
|
||
export const useBoothData = () => { | ||
const [boothData, setBoothData] = useState(null); | ||
const { day, category, location, is_night, is_reservable } = useParams(); | ||
const fetchBoothData = async () => { | ||
try { | ||
const res = await getBoothList( | ||
day, | ||
category, | ||
location, | ||
is_night, | ||
is_reservable | ||
); | ||
console.log("response:", res); | ||
const resData = res.data; | ||
console.log("resData:", resData); | ||
setBoothData(resData); | ||
} catch (error) { | ||
// console.error("error:", error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchBoothData(); | ||
}, []); | ||
|
||
return { boothData }; | ||
}; |
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,26 @@ | ||
// src/hooks/useMain.js | ||
import { useState, useEffect } from "react"; | ||
import { getBoothDetail } from "../apis/boothDetail"; | ||
import { useParams } from "react-router-dom"; | ||
|
||
export const useBoothDetailData = () => { | ||
const [boothDetailData, setBoothDetailData] = useState(null); | ||
const { booth_id } = useParams(); | ||
const fetchBoothDetailData = async () => { | ||
try { | ||
const res = await getBoothDetail(booth_id); | ||
console.log("response:", res); | ||
const resData = res.data; | ||
console.log("resData:", resData); | ||
setBoothDetailData(resData); | ||
} catch (error) { | ||
// console.error("error:", error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchBoothDetailData(); | ||
}, []); | ||
|
||
return { boothDetailData }; | ||
}; |
Oops, something went wrong.