Skip to content

Commit 9bb06c7

Browse files
authored
Merge pull request #304 from JEOLLOGA/feat/#290/filter-ssr
[REFACTOR] 필터링 및 검색 v2 둜직으둜 μˆ˜μ •
2 parents 5554bbf + 16a02b9 commit 9bb06c7

File tree

22 files changed

+419
-515
lines changed

22 files changed

+419
-515
lines changed

β€Ž.gitignoreβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ dist-ssr
2929

3030
.next
3131
next-env.d.ts
32-
dist
32+
dist
33+
34+
CLAUDE.md
35+
36+
# TypeScript build cache
37+
tsconfig.tsbuildinfo

β€Žsrc/apis/filter/axios.tsβ€Ž

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
1-
import { FilterType, PriceType } from '@apis/filter/type';
2-
import instance, { getAxiosInstance } from '@apis/instance';
1+
import { FilterType, PriceType, TemplestaySearchParamsV2 } from '@apis/filter/type';
2+
import instance from '@apis/instance';
33
import MESSAGES from '@apis/messages';
44
import { isAxiosError } from 'axios';
55

6-
export const fetchFilteredList = async (
7-
filterData: FilterType & { price: PriceType; content: string },
8-
page: number,
9-
userId?: string,
10-
) => {
11-
const axiosInstance = getAxiosInstance();
12-
6+
export const fetchFilteredListV2 = async (params: TemplestaySearchParamsV2) => {
137
try {
14-
const response = await axiosInstance.post(`/search?page=${page}&userId=${userId}`, {
15-
...filterData,
16-
});
8+
const response = await instance.get('/v2/api/templestay', { params });
179

18-
return response.data;
10+
return response.data.data;
1911
} catch (error) {
2012
if (isAxiosError(error)) throw error;
2113
else throw new Error(MESSAGES.UNKNOWN_ERROR);
2214
}
2315
};
2416

25-
export const fetchFilteredCount = async (
26-
filterData: FilterType & { price: PriceType; content: string },
27-
) => {
28-
try {
29-
const response = await instance.post('/public/filter/count', {
30-
...filterData,
31-
});
17+
const getSelectedItems = (filterGroup?: Record<string, number>): string | undefined => {
18+
if (!filterGroup) return undefined;
19+
const selected = Object.entries(filterGroup)
20+
.filter(([, value]) => value === 1)
21+
.map(([item]) => item);
22+
return selected.length > 0 ? selected.join(',') : undefined;
23+
};
3224

33-
return response.data;
34-
} catch (error) {
35-
if (isAxiosError(error)) throw error;
36-
else throw new Error(MESSAGES.UNKNOWN_ERROR);
37-
}
25+
export const convertToV2Params = (
26+
groupedFilters: FilterType,
27+
price: PriceType,
28+
search: string,
29+
page: number,
30+
userId?: string,
31+
sort?: string,
32+
): TemplestaySearchParamsV2 => {
33+
const params: TemplestaySearchParamsV2 = {
34+
page,
35+
search: search && search.trim() !== '' ? search : undefined,
36+
min: price.minPrice > 0 ? price.minPrice : undefined,
37+
max: price.maxPrice < 30 ? price.maxPrice : undefined,
38+
sort: sort && sort.trim() !== '' ? sort : undefined,
39+
userId: userId && userId.trim() !== '' ? userId : undefined,
40+
};
41+
42+
params.region = getSelectedItems(groupedFilters.region);
43+
params.type = getSelectedItems(groupedFilters.type);
44+
params.activity = getSelectedItems(groupedFilters.activity);
45+
params.etc = getSelectedItems(groupedFilters.etc);
46+
return params;
3847
};

β€Žsrc/apis/filter/index.tsβ€Ž

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
import { fetchFilteredList } from '@apis/filter/axios';
2-
import { FetchFilteredListProps } from '@apis/filter/type';
3-
import { useMutation } from '@tanstack/react-query';
4-
import queryClient from 'src/queryClient';
1+
import { fetchFilteredListV2 } from '@apis/filter/axios';
2+
import { TemplestaySearchParamsV2 } from '@apis/filter/type';
3+
import { useQuery } from '@tanstack/react-query';
54

6-
const useFetchFilteredList = () => {
7-
return useMutation({
8-
mutationFn: ({
9-
groupedFilters,
10-
adjustedPrice,
11-
searchQuery,
12-
page,
13-
userId,
14-
}: FetchFilteredListProps) => {
15-
return fetchFilteredList(
16-
{ ...groupedFilters, price: adjustedPrice, content: searchQuery },
17-
page,
18-
userId,
19-
);
20-
},
21-
onSuccess: (data, { groupedFilters, page, userId }: FetchFilteredListProps) => {
22-
queryClient.setQueryData(['filteredList', groupedFilters, page, userId], data);
23-
},
5+
const useFetchFilteredListV2 = (params: TemplestaySearchParamsV2) => {
6+
return useQuery({
7+
queryKey: ['filteredListV2', params],
8+
queryFn: () => fetchFilteredListV2(params),
9+
enabled: true,
10+
placeholderData: (previousData) => previousData,
2411
});
2512
};
2613

27-
export default useFetchFilteredList;
14+
export default useFetchFilteredListV2;

β€Žsrc/apis/filter/type.tsβ€Ž

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ export interface FetchFilteredListProps {
1818
page: number;
1919
userId: string;
2020
}
21+
22+
export interface TemplestaySearchParamsV2 {
23+
region?: string;
24+
type?: string;
25+
activity?: string;
26+
etc?: string;
27+
min?: number;
28+
max?: number;
29+
sort?: string;
30+
search?: string;
31+
page?: number;
32+
userId?: string;
33+
size?: number;
34+
}

β€Žsrc/app/HomeClient.tsxβ€Ž

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import PopularCarousel from '@components/carousel/popularCarousel/PopularCarousel';
44
import ModalContainer from '@components/common/modal/ModalContainer';
5-
import useFilter from '@hooks/useFilter';
65
import useNavigateTo from '@hooks/useNavigateTo';
7-
import { useSetAtom } from 'jotai';
86
import { useEffect, useState } from 'react';
97
import useEventLogger from 'src/gtm/hooks/useEventLogger';
10-
import { contentAtom } from 'src/store/store';
118

129
import * as styles from './homePage.css';
1310

@@ -16,12 +13,7 @@ const HomeClient = () => {
1613
const navigateToLogin = useNavigateTo('/loginStart');
1714
const { logClickEvent } = useEventLogger('modal_login_wish');
1815

19-
const { handleResetFilter } = useFilter();
20-
const setContent = useSetAtom(contentAtom);
21-
2216
useEffect(() => {
23-
setContent('');
24-
handleResetFilter();
2517
localStorage.setItem('prevPage', '/');
2618
}, []);
2719

β€Žsrc/app/filter/filterPage.css.tsβ€Ž

Lines changed: 0 additions & 13 deletions
This file was deleted.

β€Žsrc/app/filter/page.tsxβ€Ž

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
Β (0)