diff --git a/src/apis/booth.js b/src/apis/booth.js index 6e502f0..063cac9 100644 --- a/src/apis/booth.js +++ b/src/apis/booth.js @@ -1,26 +1,26 @@ import { instance } from "./instance"; -export const getBoothList = async ({ +export const getBoothList = async ( day, category, location, is_night, - is_reservable, -}) => { + is_reservable +) => { try { - // URLSearchParams 객체 생성 - const params = new URLSearchParams(); + let params = []; - // 파라미터가 존재할 때만 추가 - if (day) params.append("day", day); - if (category) params.append("category", category); - if (location) params.append("location", location); - if (is_night !== undefined) params.append("is_night", is_night); + // 각 필터가 값이 있을 때만 쿼리 파라미터에 추가 + if (day) params.push(`day=${day}`); + if (category) params.push(`category=${category}`); + if (location) params.push(`location=${location}`); + if (is_night !== undefined) params.push(`is_night=${is_night}`); if (is_reservable !== undefined) - params.append("is_reservable", is_reservable); - console.log("params:", params.toString()); + params.push(`is_reservable=${is_reservable}`); - // 파라미터들을 포함한 GET 요청 - const res = await instance.get(`api/v1/booth/?${params.toString()}`); + // 쿼리 파라미터가 있을 경우 URL에 추가 + const queryString = params.length > 0 ? `?${params.join("&")}` : ""; + + const res = await instance.get(`api/v1/booth/${queryString}`); console.log("booth.js에서의 res 값", res); return res; } catch (err) {