diff --git a/src/api/noticeApi.ts b/src/api/noticeApi.ts index fdb35fd..124989f 100644 --- a/src/api/noticeApi.ts +++ b/src/api/noticeApi.ts @@ -90,19 +90,32 @@ export interface NoticeUpsertRequest { export const getNotices = async (query?: { offset?: number; limit?: number; - address?: string; + address?: string[]; keyword?: string; startsAtGte?: string; hourlyPayGte?: number; sort?: 'time' | 'pay' | 'hour' | 'shop'; }): Promise => { try { - const newQuery = new URLSearchParams({ - ...query, - offset: String(query?.offset ?? ''), - limit: String(query?.limit ?? ''), - hourlyPayGte: String(query?.hourlyPayGte ?? ''), + const { address, ...rest } = query ?? {}; // address만 분리 + + const newQuery = new URLSearchParams(); + + // 키값을 하나씩 꺼내 문자열 변환 + Object.entries(rest).forEach(([key, value]) => { + if (value !== undefined && value !== null) { + newQuery.set(key, String(value)); + } + }); + + // 배열로 각 값의 trim 적용, 유효한 값만 append + address?.forEach((addr) => { + const trimmed = addr.trim(); + if (trimmed) { + newQuery.append('address', trimmed); + } }); + const response = await api.get(`/notices?${newQuery}`); return response.data; } catch (error) { diff --git a/src/pages/notice/NoticeList.tsx b/src/pages/notice/NoticeList.tsx index d2ca9b3..7eaba06 100644 --- a/src/pages/notice/NoticeList.tsx +++ b/src/pages/notice/NoticeList.tsx @@ -90,7 +90,7 @@ export default function NoticeList({ search = '' }: { search?: string }) { const rawQuery = { offset: (currentPage - 1) * ITEMS_PER_PAGE, limit: ITEMS_PER_PAGE, - address: filterValues.address?.[0], + address: filterValues.address, keyword: search, startsAtGte: filterValues.startsAt ?? getTomorrowISOString(), hourlyPayGte: filterValues.hourlyPay, @@ -134,13 +134,19 @@ export default function NoticeList({ search = '' }: { search?: string }) { const userInfo = await getUser(userId); const preferredAddress = userInfo.item.address; + let addressArray: string[] = []; + if (preferredAddress) { + addressArray = Array.isArray(preferredAddress) + ? preferredAddress + : [preferredAddress]; + } + const result = await getNotices({ offset: 0, limit: 9, startsAtGte: getTomorrowISOString(), - ...(preferredAddress - ? { address: preferredAddress } - : { sort: 'shop' }), + address: addressArray.length > 0 ? addressArray : undefined, + sort: addressArray.length === 0 ? 'shop' : undefined, }); setRecommendedNotices(