-
Notifications
You must be signed in to change notification settings - Fork 1
여행지 탐색 추가 #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
The head ref may contain hidden characters: "106-feat-\uC5EC\uD589\uC9C0-\uD0D0\uC0C9-\uAE30\uB2A5-\uCD94\uAC00"
Closed
여행지 탐색 추가 #109
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,73 @@ | ||
| import api from '@/api/api'; | ||
| import api from "@/api/api"; | ||
|
|
||
| export interface SigunguDto { | ||
| sigunguCode: string; | ||
| sigunguName: string; | ||
| } | ||
|
|
||
| export interface AreaDto { | ||
| areaCode: string; | ||
| areaName: string; | ||
| sigunguList: SigunguDto[]; | ||
| } | ||
|
|
||
| function unwrap<T>(raw: any): T { | ||
| return raw && typeof raw.success === 'boolean' && 'data' in raw ? raw.data : raw; | ||
| type RegionsWire = | ||
| | AreaDto[] | ||
| | { data?: AreaDto[]; result?: AreaDto[] } | ||
| | { success?: boolean; data?: AreaDto[] }; | ||
| function joinUrl(...parts: (string | undefined | null)[]) { | ||
| const raw = parts.filter(Boolean).join("/"); | ||
| return raw.replace(/(?<!:)\/{2,}/g, "/"); | ||
| } | ||
|
|
||
| function resolveApiPrefix() { | ||
| const base: string = (api as any)?.defaults?.baseURL ?? ""; | ||
| const envPrefix: string = | ||
| (import.meta as any)?.env?.VITE_API_PREFIX?.toString?.() || "/api"; | ||
|
|
||
| try { | ||
| const url = new URL(base, "http://_dummy.origin"); | ||
| const path = url.pathname || ""; | ||
| if (path.split("/").includes("api")) return ""; // 이미 /api 세그먼트 존재 | ||
| } catch { | ||
| if (typeof base === "string" && /(^|\/)api(\/|$)/.test(base)) return ""; | ||
| } | ||
| return envPrefix; | ||
| } | ||
|
|
||
| export async function fetchRegions(): Promise<AreaDto[]> { | ||
| const res = await api.get('/places/regions'); | ||
| const data = unwrap<AreaDto[]>(res.data); | ||
| if (!Array.isArray(data)) throw new Error('Unexpected response for /places/regions'); | ||
| return data; | ||
| const API_PREFIX = resolveApiPrefix(); | ||
| const REGIONS_ENDPOINT = joinUrl(API_PREFIX || "", "places", "regions"); | ||
|
|
||
|
|
||
| export async function fetchRegions( | ||
| options?: { signal?: AbortSignal } | ||
| ): Promise<AreaDto[]> { | ||
| const res = await api.get<RegionsWire>(REGIONS_ENDPOINT, { | ||
| signal: options?.signal, | ||
| }); | ||
|
|
||
| const wire = res.data as any; | ||
|
|
||
| const payload: unknown = Array.isArray(wire) | ||
| ? wire | ||
| : wire?.data ?? wire?.result ?? wire; | ||
|
|
||
| if (!Array.isArray(payload)) { | ||
| throw new Error("Invalid response format from /places/regions"); | ||
| } | ||
|
|
||
| const normalized: AreaDto[] = (payload as AreaDto[]) | ||
| .map((area) => ({ | ||
| ...area, | ||
| sigunguList: Array.isArray(area.sigunguList) | ||
| ? [...area.sigunguList].sort((a, b) => | ||
| a.sigunguName.localeCompare(b.sigunguName) | ||
| ) | ||
| : [], | ||
| })) | ||
| .sort((a, b) => a.areaName.localeCompare(b.areaName)); | ||
|
|
||
| return normalized; | ||
| } | ||
|
|
||
| export default { fetchRegions }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,78 @@ | ||
| import api from '../api'; | ||
| import type { ApiResponse } from '@/types/api-response'; | ||
| import api from "@/api/api"; | ||
| import type { AxiosResponse } from "axios"; | ||
| import type { ApiResponse } from "@/types/api-response"; | ||
|
|
||
| export interface ThemeCat2 { | ||
| cat2: string; | ||
| cat2Name: string; | ||
| cat2: string; | ||
| cat2Name: string; | ||
| } | ||
|
|
||
| export interface ThemeGroup { | ||
| cat1: string; | ||
| cat1Name: string; | ||
| cat1: string; | ||
| cat1Name: string; | ||
| cat2List: ThemeCat2[]; | ||
| } | ||
|
|
||
| export async function getThemeGroups(): Promise<ThemeGroup[]> { | ||
| const { data } = await api.get<ThemeGroup[] | ApiResponse<ThemeGroup[]>>('/places/themes'); | ||
| const payload = (data as any)?.data ?? data; | ||
| return payload as ThemeGroup[]; | ||
| type ThemeGroupsWire = | ||
| | ThemeGroup[] | ||
| | ApiResponse<ThemeGroup[]> | ||
| | { result?: ThemeGroup[]; data?: ThemeGroup[] }; | ||
| function joinUrl(...parts: (string | undefined | null)[]) { | ||
| const raw = parts.filter(Boolean).join("/"); | ||
| return raw.replace(/(?<!:)\/{2,}/g, "/"); | ||
| } | ||
|
|
||
| function resolveApiPrefix() { | ||
| const base: string = (api as any)?.defaults?.baseURL ?? ""; | ||
| const envPrefix: string = | ||
| (import.meta as any)?.env?.VITE_API_PREFIX?.toString?.() || "/api"; | ||
|
|
||
| try { | ||
| const url = new URL(base, "http://_dummy.origin"); | ||
| const path = url.pathname || ""; | ||
| if (path.split("/").includes("api")) return ""; | ||
| } catch { | ||
| if (typeof base === "string" && /(^|\/)api(\/|$)/.test(base)) return ""; | ||
| } | ||
| return envPrefix; | ||
| } | ||
|
|
||
| const API_PREFIX = resolveApiPrefix(); | ||
| const THEMES_ENDPOINT = joinUrl(API_PREFIX || "", "places", "themes"); | ||
|
|
||
|
|
||
|
|
||
| export async function getThemeGroups( | ||
| options?: { signal?: AbortSignal } | ||
| ): Promise<ThemeGroup[]> { | ||
| const res: AxiosResponse<ThemeGroupsWire> = await api.get(THEMES_ENDPOINT, { | ||
| signal: options?.signal, | ||
| }); | ||
|
|
||
| const wire = res.data as any; | ||
|
|
||
| const payload: unknown = Array.isArray(wire) | ||
| ? wire | ||
| : wire?.data ?? wire?.result ?? wire; | ||
|
|
||
| if (!Array.isArray(payload)) { | ||
| throw new Error("Invalid response format from /places/themes"); | ||
| } | ||
|
|
||
| const normalized: ThemeGroup[] = (payload as ThemeGroup[]) | ||
| .map((group) => ({ | ||
| ...group, | ||
| cat2List: Array.isArray(group.cat2List) | ||
| ? [...group.cat2List].sort((a, b) => | ||
| a.cat2Name.localeCompare(b.cat2Name) | ||
| ) | ||
| : [], | ||
| })) | ||
| .sort((a, b) => a.cat1Name.localeCompare(b.cat1Name)); | ||
|
|
||
| return normalized; | ||
| } | ||
|
|
||
| export default { | ||
| getThemeGroups, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재윤님 혹시 지역이랑 테마 불러오는 API 연결 파일은 왜 이렇게 수정하셨나요?