Skip to content

Commit

Permalink
Merge pull request #42 from Chaem03/feature/#27
Browse files Browse the repository at this point in the history
[Feature]#27 -부스페이지 API 연결 세팅
  • Loading branch information
Chaem03 authored Oct 3, 2024
2 parents c65ed01 + 6b3cffe commit be305a6
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 91 deletions.
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-ga": "^3.3.1",
Expand Down
18 changes: 18 additions & 0 deletions src/apis/booth.js
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;
}
};
10 changes: 10 additions & 0 deletions src/apis/boothDetail.js
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;
}
};
28 changes: 28 additions & 0 deletions src/apis/instance.js
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);
}
);
32 changes: 32 additions & 0 deletions src/hook/useBooth.js
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 };
};
26 changes: 26 additions & 0 deletions src/hook/useBoothDetail.js
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 };
};
Loading

0 comments on commit be305a6

Please sign in to comment.