Skip to content

Commit fc4bb91

Browse files
authored
[UNI-123] feat : 대학 리스트 조회, 지도 건물, 위험 주의 요소 조회 API 연결 및 Enum, type 재정의 및 적용 (#64)
* [UNI-124] feat : University 타입 선언 및 GlobalState 변경, 대학 리스트 조회 API 적용 * [UNI-124] feat : 신규 타입 적용 * [UNI-124] fix : Loading 컴포넌트 university name 참조 변경 * [UNI-124] feat : 위험 주의 요소 Enum 재정의 * [UNI-128] fix : Route 타입 정의 변경 * [UNI-128] fix : 위험 주의 요소 (SLOPE, STAIR, ETC...) Enum 변수명 변경 및 keyof typeof 타입 선언 * [UNI-125] feat : 지도 메인 페이지 위험 주의 요소 조회 API * [UNI-124] feat : 대학리스트 조회 API, transform 패턴 적용 및 Resposne 타입 선언 * [UNI-124] fix : 대학 리스트 조회 API Transform 패턴 타입 오류 수정
1 parent c6d71c5 commit fc4bb91

20 files changed

+263
-125
lines changed

uniro_frontend/src/api/nodes.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Building } from "../data/types/node";
2+
import { getFetch } from "../utils/fetch/fetch";
3+
4+
export const getAllBuildings = (
5+
univId: number,
6+
params: {
7+
leftUpLng: number;
8+
leftUpLat: number;
9+
rightDownLng: number;
10+
rightDownLat: number;
11+
},
12+
): Promise<Building[]> => {
13+
return getFetch<Building[]>(`/${univId}/nodes/buildings`, {
14+
"left-up-lng": params.leftUpLng,
15+
"left-up-lat": params.leftUpLat,
16+
"right-down-lng": params.rightDownLng,
17+
"right-down-lat": params.rightDownLat,
18+
});
19+
};

uniro_frontend/src/api/routes.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { CautionRoute, DangerRoute } from "../data/types/route";
2+
import { getFetch } from "../utils/fetch/fetch";
3+
4+
export const getAllRisks = (
5+
univId: number,
6+
): Promise<{ dangerRoutes: DangerRoute[]; cautionRoutes: CautionRoute[] }> => {
7+
return getFetch<{ dangerRoutes: DangerRoute[]; cautionRoutes: CautionRoute[] }>(`/${univId}/routes/risks`);
8+
};

uniro_frontend/src/api/search.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { University } from "../data/types/university";
2+
import { getFetch } from "../utils/fetch/fetch";
3+
import { transformGetUniversityList } from "./transformer/search";
4+
import { GetUniversityListResponse } from "./type/response/search";
5+
6+
export const getUniversityList = (): Promise<University[]> => {
7+
return getFetch<GetUniversityListResponse>("/univ/search").then(transformGetUniversityList);
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { University } from "../../data/types/university";
2+
import { GetUniversityListResponse } from "../type/response/search";
3+
4+
export const transformGetUniversityList = (res: GetUniversityListResponse): University[] => {
5+
return res.data;
6+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type GetUniversityListResponse = {
2+
data: University[];
3+
nextCursor: number | null;
4+
hasNext: boolean;
5+
};

uniro_frontend/src/components/loading/loading.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const Loading = ({ isLoading, loadingContent }: Props) => {
2525
>
2626
<div className="flex flex-row items-center justify-center bg-white rounded-3xl space-x-1">
2727
<img src={svgPath} className="h-4 w-4 ml-2 my-2" />
28-
<p className="text-kor-body2 mr-2 my-1">{university}</p>
28+
<p className="text-kor-body2 mr-2 my-1">{university?.name}</p>
2929
</div>
3030
<p className="text-kor-body2 mt-3">{loadingContent}</p>
3131
<img src="/loading/spinner.gif" className="w-12 h-12 mt-8" />

uniro_frontend/src/components/map/mapBottomSheet.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface MapBottomSheetFromListProps {
1212
export function MapBottomSheetFromList({ building, buttonText, onClick }: MapBottomSheetFromListProps) {
1313
if (building.property === undefined) return;
1414

15-
const { id, lng, lat, isCore, buildingName, buildingImageUrl, phoneNumber, address } = building.property;
15+
const { nodeId, lng, lat, buildingName, buildingImageUrl, phoneNumber, address } = building.property;
1616

1717
return (
1818
<div className="h-full px-5 pt-3 pb-6 flex flex-col items-between">
@@ -46,7 +46,7 @@ interface MapBottomSheetProps {
4646
export function MapBottomSheetFromMarker({ building, onClickLeft, onClickRight }: MapBottomSheetProps) {
4747
if (building.property === undefined) return;
4848

49-
const { id, lng, lat, isCore, buildingName, buildingImageUrl, phoneNumber, address } = building.property;
49+
const { nodeId, lng, lat, buildingName, buildingImageUrl, phoneNumber, address } = building.property;
5050

5151
return (
5252
<div className="h-full px-5 pt-3 pb-6 flex flex-col items-between">

uniro_frontend/src/components/map/mapMarkers.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { MarkerTypes } from "../../data/types/marker";
1+
22
import { Markers } from "../../constant/enum/markerEnum";
3+
import { MarkerTypes } from "../../data/types/enum";
34

45
const markerImages = import.meta.glob("/src/assets/markers/*.svg", { eager: true });
56

uniro_frontend/src/components/report/secondaryButton.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import React from "react";
2-
import { CautionIssueType, DangerIssueType, PassableStatus } from "../../data/types/report";
32
import { getThemeByPassableStatus } from "../../utils/report/getThemeByPassableStatus";
3+
import { CautionIssue, DangerIssue, PassableStatus } from "../../constant/enum/reportEnum";
44

55
export const SecondaryFormButton = ({
66
onClick,
77
formPassableStatus,
88
content,
99
isSelected,
1010
}: {
11-
onClick: (answer: DangerIssueType | CautionIssueType) => void;
11+
onClick: (answer: DangerIssue | CautionIssue) => void;
1212
formPassableStatus: PassableStatus;
13-
content: DangerIssueType | CautionIssueType;
13+
content: DangerIssue | CautionIssue;
1414
isSelected: boolean;
1515
}) => {
1616
return (

uniro_frontend/src/components/report/secondaryForm.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import { CautionIssueType, DangerIssueType, PassableStatus } from "../../constant/enum/reportEnum";
1+
import { CautionIssue, DangerIssue, PassableStatus } from "../../constant/enum/reportEnum";
22
import { IssueQuestionButtons, ReportFormData, ReportModeType } from "../../data/types/report";
33

44
import { FormTitle } from "./formTitle";
55
import { SecondaryFormButton } from "./secondaryButton";
66

77
const buttonConfig = {
8-
danger: [DangerIssueType.LOW_STEP, DangerIssueType.CRACK, DangerIssueType.LOW_SLOPE, DangerIssueType.OTHERS],
8+
danger: [DangerIssue.CURB, DangerIssue.CRACK, DangerIssue.SLOPE, DangerIssue.ETC],
99
caution: [
10-
CautionIssueType.HIGH_STEP,
11-
CautionIssueType.STAIRS,
12-
CautionIssueType.STEEP_SLOPE,
13-
CautionIssueType.OTHERS,
10+
CautionIssue.CURB,
11+
CautionIssue.STAIRS,
12+
CautionIssue.SLOPE,
13+
CautionIssue.ETC,
1414
],
1515
} as IssueQuestionButtons;
1616

1717
type SecondaryFormProps = {
1818
reportMode: ReportModeType;
1919
formData: ReportFormData;
20-
handleSecondarySelect: (answer: DangerIssueType | CautionIssueType) => void;
20+
handleSecondarySelect: (answer: DangerIssue | CautionIssue) => void;
2121
};
2222

2323
export const SecondaryForm = ({ formData, handleSecondarySelect, reportMode }: SecondaryFormProps) => {
2424
return (
2525
<>
2626
{(formData.passableStatus === PassableStatus.CAUTION ||
2727
formData.passableStatus === PassableStatus.DANGER) && (
28-
<FormTitle isPrimary={false} reportMode={reportMode} passableStatus={formData.passableStatus} />
29-
)}
28+
<FormTitle isPrimary={false} reportMode={reportMode} passableStatus={formData.passableStatus} />
29+
)}
3030
<div className="flex flex-wrap w-full pt-5 pl-6 pr-4">
3131
{formData.passableStatus === PassableStatus.CAUTION &&
3232
buttonConfig.caution.map((button, index) => {

uniro_frontend/src/components/universityButton.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,19 @@ interface UniversityButtonProps {
77
onClick: () => void;
88
}
99

10-
const svgModules = import.meta.glob("/src/assets/university/*.svg", { eager: true });
11-
1210
export default function UniversityButton({ name, img, selected, onClick }: UniversityButtonProps) {
1311
const handleClick = (e: MouseEvent<HTMLButtonElement>) => {
1412
e.stopPropagation();
1513
onClick();
1614
};
1715

18-
const svgPath = (svgModules[`/src/assets/university/${img}`] as { default: string })?.default;
19-
2016
return (
2117
<li className="my-[6px]">
2218
<button
2319
onClick={handleClick}
2420
className={`w-full h-full p-6 flex flex-row items-center border rounded-400 ${selected ? "border-primary-400 bg-system-skyblue text-primary-500" : "border-gray-400"} `}
2521
>
26-
<img src={svgPath} className="mr-4" />
22+
<img src={img} className="mr-4" />
2723
<span className="text-kor-body2 font-medium leading-[140%]">{name}</span>
2824
</button>
2925
</li>

uniro_frontend/src/constant/enum/reportEnum.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@ export enum PassableStatus {
55
INITIAL = "INITIAL",
66
}
77

8-
export enum DangerIssueType {
9-
LOW_STEP = "낮은 턱이 있어요",
8+
export enum DangerIssue {
9+
CURB = "낮은 턱이 있어요",
1010
CRACK = "도로에 균열이 있어요",
11-
LOW_SLOPE = "낮은 비탈길이 있어요",
12-
OTHERS = "그 외 요소",
11+
SLOPE = "낮은 비탈길이 있어요",
12+
ETC = "그 외 요소",
1313
}
1414

15-
export enum CautionIssueType {
16-
HIGH_STEP = "높은 턱이 있어요",
15+
export enum CautionIssue {
16+
CURB = "높은 턱이 있어요",
1717
STAIRS = "계단이 있어요",
18-
STEEP_SLOPE = "경사가 매우 높아요",
19-
OTHERS = "그 외 요소",
18+
SLOPE = "경사가 매우 높아요",
19+
ETC = "그 외 요소",
20+
}
21+
22+
export enum IssueTypeKey {
23+
CURB = "CURB",
24+
CRACK = "CRACK",
25+
SLOPE = "SLOPE",
26+
ETC = "ETC",
27+
STAIRS = "STAIRS",
2028
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Markers } from "../../constant/enum/markerEnum";
2+
import { DangerIssue, CautionIssue } from "../../constant/enum/reportEnum";
3+
4+
export type DangerIssueType = keyof typeof DangerIssue;
5+
export type CautionIssueType = keyof typeof CautionIssue;
6+
export type MarkerTypes = (typeof Markers)[keyof typeof Markers];

uniro_frontend/src/data/types/marker.d.ts

-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ import { Markers } from "../../constant/enum/markerEnum";
22

33
export type AdvancedMarker = google.maps.marker.AdvancedMarkerElement;
44

5-
export type MarkerTypes =
6-
| Markers.BUILDING
7-
| Markers.CAUTION
8-
| Markers.DANGER
9-
| Markers.DESTINATION
10-
| Markers.ORIGIN
11-
| Markers.NUMBERED_WAYPOINT
12-
| Markers.WAYPOINT
13-
| Markers.SELECTED_BUILDING
14-
| Markers.REPORT;
15-
165
export type MarkerTypesWithElement = {
176
type: MarkerTypes;
187
element: AdvancedMarker;
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CautionIssueType, DangerIssueType, PassableStatus } from "../../constant/enum/reportEnum";
1+
import { CautionIssue, DangerIssue, PassableStatus } from "../../constant/enum/reportEnum";
22

33
export type ReportModeType = "create" | "update";
44

@@ -9,11 +9,11 @@ export interface PrimaryQuestionButton {
99
}
1010

1111
export interface IssueQuestionButtons {
12-
danger: DangerIssueType[];
13-
caution: CautionIssueType[];
12+
danger: DangerIssue[];
13+
caution: CautionIssue[];
1414
}
1515
export interface ReportFormData {
1616
passableStatus: PassableStatus;
17-
dangerIssues: DangerIssueType[];
18-
cautionIssues: CautionIssueType[];
17+
dangerIssues: DangerIssue[];
18+
cautionIssues: CautionIssue[];
1919
}

uniro_frontend/src/data/types/route.d.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import { Markers } from "../../constant/enum/markerEnum";
12
import { CautionIssueType, DangerIssueType } from "../../constant/enum/reportEnum";
3+
import { RoutePoint } from "../../constant/enum/routeEnum";
24
import { Coord } from "./coord";
3-
import { Node } from "./node";
5+
import { MarkerTypes } from "./marker";
46

57
export type RouteId = number;
68

79
export type Route = {
810
routeId: RouteId;
9-
startNode: Node;
10-
endNode: Node;
11+
node1: Coord;
12+
node2: Coord;
1113
};
1214

1315
export type Direction = "origin" | "right" | "straight" | "left" | "uturn" | "destination" | "caution";
@@ -24,6 +26,8 @@ export interface NavigationRoute extends Route {
2426
cautionTypes: CautionIssueType[];
2527
}
2628

29+
export type RoutePointType = RoutePoint.ORIGIN | RoutePoint.DESTINATION;
30+
2731
export type RouteDetail = {
2832
dist: number;
2933
directionType: Direction;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type University = {
2+
name: string;
3+
imageUrl: string;
4+
id: number;
5+
};

uniro_frontend/src/hooks/useUniversityInfo.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { create } from "zustand";
22
import { persist } from "zustand/middleware";
3+
import { University } from "../data/types/university";
34

45
interface UniversityInfoStore {
5-
university: string | undefined;
6-
setUniversity: (university: string) => void;
6+
university: University | undefined;
7+
setUniversity: (university: University) => void;
78
resetUniversity: () => void;
89
}
910

1011
const useUniversityInfo = create(
1112
persist<UniversityInfoStore>(
1213
(set) => ({
1314
university: undefined,
14-
setUniversity: (newUniversity: string) => {
15+
setUniversity: (newUniversity: University) => {
1516
set(() => ({ university: newUniversity }));
1617
},
1718
resetUniversity: () => {

0 commit comments

Comments
 (0)