Skip to content

Commit

Permalink
faet #18 Goods 조회 API 업데이트
Browse files Browse the repository at this point in the history
  • Loading branch information
lee7198 committed Jan 27, 2024
1 parent 5f81d44 commit 5bf7722
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 69 deletions.
49 changes: 30 additions & 19 deletions src/api/goods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ import qs from 'qs';
import jigumeAxios from './axios';

export const getGoodsList = async (
bounds: kakao.maps.LatLngBounds | null
map: kakao.maps.Map | null
): Promise<GoodsMarkerListType | 'retry'> => {
if (!bounds) return 'retry';
if (!map) return 'retry';

const center = map.getCenter();
const bounds = map.getBounds();
const arr = stringLatLng2Arr(bounds);

// 인코딩
const query = qs.stringify({
coordinateRequestDto: {
latitude: center.getLat().toFixed(6),
longitude: center.getLng().toFixed(6),
latitudeDelta: (arr[1] - arr[0]).toFixed(6),
longitudeDelta: (arr[3] - arr[2]).toFixed(6),
},
});

const boundArr = stringLatLng2Arr(bounds);
const response = await jigumeAxios
.get('/api/goods/marker/list', {
params: {
maxX: boundArr[3],
minX: boundArr[2],
maxY: boundArr[1],
minY: boundArr[0],
},
})
.get(`/api/goods/marker?${query}`)
.then((res) => res.data);
return response;
};
Expand All @@ -41,19 +47,24 @@ export const getSheetGoods = async (
};

export const getSheetList = async ({
bounds,
map,
}: {
bounds: kakao.maps.LatLngBounds | undefined;
map: kakao.maps.Map | null;
}): Promise<GoodSheetDTO | 'retry'> => {
if (!bounds) return 'retry';
if (!map) return 'retry';

const center = map.getCenter();
const bounds = map.getBounds();
const arr = stringLatLng2Arr(bounds);

const boundArr = stringLatLng2Arr(bounds);
// 특수문자 인코딩
const query = qs.stringify({
maxX: boundArr[3],
minX: boundArr[2],
maxY: boundArr[1],
minY: boundArr[0],
coordinateRequestDto: {
latitude: center.getLat().toFixed(6),
longitude: center.getLng().toFixed(6),
latitudeDelta: (arr[1] - arr[0]).toFixed(6),
longitudeDelta: (arr[3] - arr[2]).toFixed(6),
},
pageable: {
page: 0,
size: 5,
Expand Down
35 changes: 18 additions & 17 deletions src/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ export const setNewUser = async (param: InitUserType) => {
const randomIdx = Math.round(Math.random() * 2);
if (!param.position) return undefined;
const response = await jigumeAxios.post('/api/member/info', {
method: 'post',
data: {
nickname: param.nickname,
mapX: param.position.lng,
mapY: param.position.lat,
profileImgUrl: param.image || initProfiles[randomIdx],
},
nickname: param.nickname,
longitude: param.position.lng,
latitude: param.position.lat,
profileImgUrl: param.image || initProfiles[randomIdx],
});

return response;
Expand Down Expand Up @@ -82,20 +79,24 @@ export const checkNickname = async (nickname: string) => {
};

export const updateProfile = async (param: NewProfileType) => {
const blobData = new Blob(
[JSON.stringify({ nickname: param.nickname, profileImgUrl: param.image })],
{
type: 'application/json',
}
);
// const blobData = new Blob(
// { request: param.image },
// {
// type: 'application/json',
// }
// );

const formData = new FormData();
formData.append('UpdateMemberInfoDto', blobData);
formData.append('imageUploadRequest', param.image as string);

const response = await jigumeAxios.post('/api/member/info', {
data: formData,
console.log(formData);

const response = await jigumeAxios.post('/api/member/profile', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
console.log(response);

return response;
return response.data;
};
5 changes: 4 additions & 1 deletion src/pages/Auth/components/Init/components/initAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default function InitAddress() {
if (status === kakao.maps.services.Status.OK) {
setInitUser((prev) => ({
...prev,
position: { lat: Number(result[0].x), lng: Number(result[0].y) },
position: {
latitude: Number(result[0].x),
longitude: Number(result[0].y),
},
}));
setAddress(fullAddress);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Map/components/BottomSheetComponent/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type BottomSheetType = {
handleToCenter: () => void;
sheetProvider: sheetProvider;
preViewer: PreViewerMarker;
bounds?: kakao.maps.LatLngBounds;
map: kakao.maps.Map | null;
};

export type sheetProvider = {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Map/components/BottomSheetComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function BottomSheetComponent({
handleToCenter,
sheetProvider,
preViewer,
bounds,
map,
}: BottomSheetType) {
const [goodsArr, setGoodsArr] = useState<GoodsListDTO[]>([]);
const [filter, setFilter] = useState<FilterType[]>(
Expand Down Expand Up @@ -52,15 +52,15 @@ export default function BottomSheetComponent({
mutationFn: getSheetList,
onSuccess: (res) => {
console.log(res);
if (res === 'retry') allMutate({ bounds });
if (res === 'retry') allMutate({ map });
else setGoodsArr(res.goodsListDtoList);
},
});

useEffect(() => {
if (isOpen)
if (preViewer) preViewMutate(preViewer);
else allMutate({ bounds });
else allMutate({ map });
}, [isOpen]);

return (
Expand Down
40 changes: 18 additions & 22 deletions src/pages/Map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,20 @@ export default function Map() {
}
};

const { refetch } = useQuery(
'getGoods',
() => getGoodsList(mapRef.current && mapRef.current.getBounds()),
{
onSuccess: (res) => {
// init map list
if (res !== 'retry') {
// 중복 방지
res.markerList.forEach((item) => {
setMarkerList((prev) =>
prev?.filter((prevItem) => prevItem.goodsId !== item.categoryId)
);
});
initMap(markerList);
}
},
}
);
const { refetch } = useQuery('getGoods', () => getGoodsList(mapRef.current), {
onSuccess: (res) => {
// init map list
if (res !== 'retry') {
// 중복 방지
res.markerList.forEach((item) => {
setMarkerList((prev) =>
prev?.filter((prevItem) => prevItem.goodsId !== item.categoryId)
);
});
initMap(markerList);
}
},
});

// 클러스터 완료되었을 때 데이터를 읽어 DOM으로 변환
const drawCluster = () => {
Expand Down Expand Up @@ -186,9 +182,9 @@ export default function Map() {
setIspositing(false);
}, [user.position]);

useEffect(() => {
console.log(isPositing);
}, [isPositing]);
// useEffect(() => {
// console.log(isPositing);
// }, [isPositing]);

return (
<div className="container mx-auto max-w-screen-sm px-0">
Expand Down Expand Up @@ -230,7 +226,7 @@ export default function Map() {
handleToCenter={handleToCenter}
sheetProvider={sheetProvider}
preViewer={preViewer}
bounds={mapRef.current?.getBounds()}
map={mapRef.current}
/>
</div>
);
Expand Down
12 changes: 6 additions & 6 deletions src/pages/Mypage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { ProfileHeaderType } from './index.d';

export default function Mypage() {
// useQuery를 사용하여 fetch 함수 실행 (getProfile)
const { data: profile } = useQuery('getProfile', () => getProfile(), {
onSuccess: (data) => {
console.log(data);
},
});
// const { data: profile } = useQuery('getProfile', () => getProfile(), {
// onSuccess: (data) => {
// console.log(data);
// },
// });

const [profileHeader, setProfileHeader] = useState<ProfileHeaderType>({
title: '마이페이지',
Expand All @@ -23,7 +23,7 @@ export default function Mypage() {
title={profileHeader.title}
isAlert={profileHeader.isAlert}
/>
<Outlet context={{ setProfileHeader, profile }} />
<Outlet context={{ setProfileHeader }} />
</>
);
}

0 comments on commit 5bf7722

Please sign in to comment.