Skip to content

Commit

Permalink
[Fix]LikeLion-at-DGU#27 - API 연결 test 및 요일 변환 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaem03 committed Oct 4, 2024
1 parent eafca3f commit f9482de
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/apis/booth.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit f9482de

Please sign in to comment.