-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] 찜 목록 API 연동 #252
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
Merged
Merged
[FEAT] 찜 목록 API 연동 #252
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
18ab8dd
docs: add local course detail mock data design
KJun-2 822f106
Revert "docs: add local course detail mock data design"
KJun-2 cdfd66b
Merge branch 'develop' of https://github.com/yeogido/frontend into de…
KJun-2 b500473
Merge branch 'develop' of https://github.com/yeogido/frontend into de…
KJun-2 237e06b
Merge branch 'develop' of https://github.com/yeogido/frontend into de…
KJun-2 b99da30
Merge branch 'develop' of https://github.com/yeogido/frontend into de…
KJun-2 9b17416
Merge branch 'develop' of https://github.com/yeogido/frontend into fe…
KJun-2 2b40482
feat: 찜 목록 API 연동 및 거리/기간 표시 개선
KJun-2 bd2898a
feat: 행사 필터링 및 행사 날짜 표시 수정
KJun-2 c08d8e9
feat: 장소 카드에 현 위치 기준 거리 표시
KJun-2 d31115a
fix: 매칭 불가능한 좋아요 상세 필터 제거 및 거리 계산 안정화
KJun-2 8774512
Merge branch 'develop' of https://github.com/yeogido/frontend into fe…
KJun-2 1ce9cb4
feat: 좋아요 목록 코스 이동 수단 및 동행 유형 표시 연동
KJun-2 e62412d
refactor: 미사용 하버사인 거리 계산 유틸리티 및 테스트 제거
KJun-2 08b9d58
feat: add Google Places opening hours
KJun-2 53e1a05
fix: refine place hours lookup behavior
KJun-2 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
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { | ||
| InvalidPlaceHoursRequestError, | ||
| lookupPlaceHours, | ||
| type PlaceHoursRequest, | ||
| } from './placeHours'; | ||
|
|
||
| export const config = { runtime: 'edge' }; | ||
|
|
||
| function json(body: unknown, status = 200) { | ||
| return new Response(JSON.stringify(body), { | ||
| status, | ||
| headers: { 'content-type': 'application/json; charset=utf-8' }, | ||
| }); | ||
| } | ||
| export default async function handler(request: Request): Promise<Response> { | ||
| if (request.method !== 'POST') { | ||
| return json({ message: 'Method not allowed.' }, 405); | ||
| } | ||
|
|
||
| const apiKey = process.env.GOOGLE_MAPS_API_KEY; | ||
| if (!apiKey) { | ||
| return json({ message: 'Google Places API is not configured.' }, 503); | ||
| } | ||
|
|
||
| let requestBody: PlaceHoursRequest; | ||
| try { | ||
| requestBody = (await request.json()) as PlaceHoursRequest; | ||
| } catch { | ||
| return json({ message: 'Invalid request body.' }, 400); | ||
| } | ||
|
|
||
| try { | ||
| return json(await lookupPlaceHours(requestBody, apiKey)); | ||
| } catch (error) { | ||
| if (error instanceof InvalidPlaceHoursRequestError) { | ||
| return json({ message: error.message }, 400); | ||
| } | ||
|
|
||
| return json({ message: 'Google Places request failed.' }, 502); | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| export interface PlaceHoursRequest { | ||
| readonly name?: unknown; | ||
| readonly address?: unknown; | ||
| readonly latitude?: unknown; | ||
| readonly longitude?: unknown; | ||
| } | ||
| export interface PlaceHoursResponse { | ||
| readonly currentWeekdayDescriptions: readonly string[]; | ||
| readonly regularWeekdayDescriptions: readonly string[]; | ||
| readonly openNow?: boolean; | ||
| readonly nextOpenTime?: string; | ||
| readonly nextCloseTime?: string; | ||
| } | ||
|
|
||
| interface GoogleOpeningHours { | ||
| readonly weekdayDescriptions?: readonly string[]; | ||
| readonly openNow?: boolean; | ||
| readonly nextOpenTime?: string; | ||
| readonly nextCloseTime?: string; | ||
| } | ||
|
|
||
| interface GooglePlaceDetails { | ||
| readonly currentOpeningHours?: GoogleOpeningHours; | ||
| readonly regularOpeningHours?: GoogleOpeningHours; | ||
| } | ||
|
|
||
| interface GoogleTextSearchResponse { | ||
| readonly places?: readonly { readonly id?: string }[]; | ||
| } | ||
|
|
||
| export class InvalidPlaceHoursRequestError extends Error {} | ||
|
|
||
| function toOptionalString(value: unknown): string | undefined { | ||
| return typeof value === 'string' && value.trim() ? value.trim() : undefined; | ||
| } | ||
|
|
||
| function toOptionalCoordinate(value: unknown): number | undefined { | ||
| return typeof value === 'number' && Number.isFinite(value) ? value : undefined; | ||
| } | ||
|
|
||
| export async function lookupPlaceHours( | ||
| requestBody: PlaceHoursRequest, | ||
| apiKey: string | ||
| ): Promise<PlaceHoursResponse | null> { | ||
| const name = toOptionalString(requestBody.name); | ||
| const address = toOptionalString(requestBody.address); | ||
| const latitude = toOptionalCoordinate(requestBody.latitude); | ||
| const longitude = toOptionalCoordinate(requestBody.longitude); | ||
|
|
||
| if (!name) { | ||
| throw new InvalidPlaceHoursRequestError('Place name is required.'); | ||
| } | ||
|
|
||
| const textSearchBody: Record<string, unknown> = { | ||
| textQuery: [name, address].filter(Boolean).join(' '), | ||
| languageCode: 'ko', | ||
| }; | ||
|
|
||
| if (latitude !== undefined && longitude !== undefined) { | ||
| textSearchBody.locationBias = { | ||
| circle: { | ||
| center: { latitude, longitude }, | ||
| radius: 1_000, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| const searchResponse = await fetch( | ||
| 'https://places.googleapis.com/v1/places:searchText', | ||
| { | ||
| method: 'POST', | ||
| headers: { | ||
| 'content-type': 'application/json', | ||
| 'X-Goog-Api-Key': apiKey, | ||
| 'X-Goog-FieldMask': 'places.id', | ||
| }, | ||
| body: JSON.stringify(textSearchBody), | ||
| } | ||
| ); | ||
|
|
||
| if (!searchResponse.ok) { | ||
| throw new Error('Google place search failed.'); | ||
| } | ||
|
|
||
| const searchResult = | ||
| (await searchResponse.json()) as GoogleTextSearchResponse; | ||
| const placeId = searchResult.places?.[0]?.id; | ||
|
|
||
| if (!placeId) { | ||
| return null; | ||
|
KJun-2 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| const detailsResponse = await fetch( | ||
| `https://places.googleapis.com/v1/places/${encodeURIComponent(placeId)}`, | ||
| { | ||
| headers: { | ||
| 'X-Goog-Api-Key': apiKey, | ||
| 'X-Goog-FieldMask': 'currentOpeningHours,regularOpeningHours', | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| ); | ||
|
|
||
| if (!detailsResponse.ok) { | ||
| throw new Error('Google place details failed.'); | ||
| } | ||
|
|
||
| const details = (await detailsResponse.json()) as GooglePlaceDetails; | ||
| const currentHours = details.currentOpeningHours; | ||
| const regularHours = details.regularOpeningHours; | ||
|
|
||
| if (!currentHours && !regularHours) { | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| currentWeekdayDescriptions: currentHours?.weekdayDescriptions ?? [], | ||
| regularWeekdayDescriptions: regularHours?.weekdayDescriptions ?? [], | ||
| openNow: currentHours?.openNow, | ||
| nextOpenTime: currentHours?.nextOpenTime, | ||
| nextCloseTime: currentHours?.nextCloseTime, | ||
| }; | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| export interface PlaceHoursLookup { | ||
| readonly name: string; | ||
| readonly address?: string; | ||
| readonly latitude?: number; | ||
| readonly longitude?: number; | ||
| } | ||
| export interface PlaceHours { | ||
| readonly currentWeekdayDescriptions: readonly string[]; | ||
| readonly regularWeekdayDescriptions: readonly string[]; | ||
| readonly openNow?: boolean; | ||
| readonly nextOpenTime?: string; | ||
| readonly nextCloseTime?: string; | ||
| } | ||
|
|
||
| export async function getPlaceHours( | ||
| lookup: PlaceHoursLookup, | ||
| signal?: AbortSignal | ||
| ): Promise<PlaceHours | null> { | ||
| const response = await fetch('/google-places/hours', { | ||
| method: 'POST', | ||
| headers: { 'content-type': 'application/json' }, | ||
| body: JSON.stringify(lookup), | ||
| signal, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error('Failed to retrieve place opening hours.'); | ||
| } | ||
|
|
||
| return (await response.json()) as PlaceHours | null; | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { apiClient, normalizeApiError } from './common'; | ||
|
|
||
| import type { | ||
| LikedItemCategory, | ||
| LikedItemQueryCategory, | ||
| } from '../pages/likes/types'; | ||
|
|
||
| export interface LikedItemsParams { | ||
| category: LikedItemQueryCategory; | ||
| keyword?: string; | ||
| sort?: 'LATEST' | 'OLDEST'; | ||
| cursorCreatedAt?: string; | ||
| cursorId?: number; | ||
| size?: number; | ||
| latitude?: number; | ||
| longitude?: number; | ||
| } | ||
|
|
||
| /** 서버 쿼리 파라미터 표기. EVENT는 서버에서 CONTENT로 받는다. */ | ||
| const LIKED_ITEM_QUERY_CATEGORY_PARAM: Record<LikedItemQueryCategory, string> = | ||
| { | ||
| ALL: 'ALL', | ||
| COURSE: 'COURSE', | ||
| EVENT: 'CONTENT', | ||
| PLACE: 'PLACE', | ||
| }; | ||
|
|
||
| /** 서버 응답 category 표기. CONTENT는 앱에서 EVENT로 다룬다. */ | ||
| type LikedItemResponseCategory = 'COURSE' | 'CONTENT' | 'PLACE'; | ||
|
|
||
| const LIKED_ITEM_RESPONSE_CATEGORY: Record< | ||
| LikedItemResponseCategory, | ||
| LikedItemCategory | ||
| > = { | ||
| COURSE: 'COURSE', | ||
| CONTENT: 'EVENT', | ||
| PLACE: 'PLACE', | ||
| }; | ||
|
|
||
| interface RawLikedItemResponse { | ||
| id: number; | ||
| category: LikedItemResponseCategory; | ||
| title: string; | ||
| externalPlaceId?: string; | ||
| thumbnailImage: string | null; | ||
| duration: string | null; | ||
| startDate: string | null; | ||
| endDate: string | null; | ||
| location: string; | ||
| transportType?: string | null; | ||
| companionType?: string | null; | ||
| distance: number | null; | ||
| hashtags: string[]; | ||
| likedAt: string; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| interface RawGetLikedItemsResponse { | ||
| items: RawLikedItemResponse[]; | ||
| cursorValue: string | null; | ||
| cursorId: number | null; | ||
| hasNext: boolean; | ||
| } | ||
|
|
||
| export interface LikedItemResponse { | ||
| id: number; | ||
| category: LikedItemCategory; | ||
| title: string; | ||
| externalPlaceId?: string; | ||
| thumbnailImage: string | null; | ||
| duration: string | null; | ||
| startDate: string | null; | ||
| endDate: string | null; | ||
| location: string; | ||
| transportType?: string | null; | ||
| companionType?: string | null; | ||
| distance: number | null; | ||
| hashtags: string[]; | ||
| likedAt: string; | ||
| } | ||
|
|
||
| export interface GetLikedItemsResponse { | ||
| items: LikedItemResponse[]; | ||
| cursorValue: string | null; | ||
| cursorId: number | null; | ||
| hasNext: boolean; | ||
| } | ||
|
|
||
| export async function getLikedItems( | ||
| params: LikedItemsParams, | ||
| signal?: AbortSignal | ||
| ): Promise<GetLikedItemsResponse> { | ||
| try { | ||
| const { data } = await apiClient.get<RawGetLikedItemsResponse>( | ||
| '/users/me/likes', | ||
| { | ||
| params: { | ||
| ...params, | ||
| category: LIKED_ITEM_QUERY_CATEGORY_PARAM[params.category], | ||
| }, | ||
| signal, | ||
| } | ||
| ); | ||
|
|
||
| return { | ||
| ...data, | ||
| items: data.items.map((item) => ({ | ||
| ...item, | ||
| category: LIKED_ITEM_RESPONSE_CATEGORY[item.category], | ||
| })), | ||
| }; | ||
| } catch (error) { | ||
| throw normalizeApiError(error); | ||
| } | ||
| } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Uh oh!
There was an error while loading. Please reload this page.