-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add resort and weather api * feat: update resorts data with api * feat: connect resort api in discovery detail page
- Loading branch information
1 parent
896dfa8
commit 934b400
Showing
15 changed files
with
181 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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,8 @@ | ||
import { apiClient } from '@/shared/api/base'; | ||
import type { Resort } from '../model'; | ||
|
||
export const getResorts = async (): Promise<Resort[]> => { | ||
const result = await apiClient.get<Resort[]>('/api/ski-resorts'); | ||
|
||
return result; | ||
}; |
This file contains 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,8 @@ | ||
import { apiClient } from '@/shared/api/base'; | ||
import type { WeatherResponse } from '../model'; | ||
|
||
export const getWeather = async (resortId: number): Promise<WeatherResponse> => { | ||
const result = await apiClient.get<WeatherResponse>(`/api/weather/${resortId}`); | ||
|
||
return result; | ||
}; |
This file contains 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,2 +1,4 @@ | ||
export { discoveryQueries } from './discovery.queries'; | ||
export { discoveryQueries } from './query/discovery.queries' | ||
export { resortQueries } from './query/resort.queries' | ||
export { weatherQueries } from './weather.queries'; | ||
export { postVote } from './post-vote'; |
4 changes: 2 additions & 2 deletions
4
...tities/discovery/api/discovery.queries.ts → .../discovery/api/query/discovery.queries.ts
This file contains 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 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,13 @@ | ||
import { queryOptions } from '@tanstack/react-query'; | ||
import { getResorts } from '../get-resort'; | ||
|
||
export const resortQueries = { | ||
all: () => ['resort'], | ||
|
||
listQueryKey: () => [...resortQueries.all(), 'list'], | ||
list: () => | ||
queryOptions({ | ||
queryKey: [...resortQueries.listQueryKey()], | ||
queryFn: () => getResorts(), | ||
}), | ||
}; |
This file contains 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,13 @@ | ||
import { queryOptions } from '@tanstack/react-query'; | ||
import { getWeather } from './get-weather'; | ||
|
||
export const weatherQueries = { | ||
all: () => ['weather'], | ||
|
||
weatherQueryKey: (resortId: number) => [...weatherQueries.all(), resortId], | ||
weather: (resortId: number) => | ||
queryOptions({ | ||
queryKey: weatherQueries.weatherQueryKey(resortId), | ||
queryFn: () => getWeather(resortId), | ||
}), | ||
}; |
This file contains 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,2 +1,2 @@ | ||
export { DiscoveryData } from './constants'; | ||
export type { Weather, WeeklyWeather, Discovery, Vote } from './model'; | ||
export type { Weather, Discovery, Vote, WeeklyWeather, WeatherResponse, Resort, Url } from './model'; |
This file contains 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,33 +1,77 @@ | ||
export type Weather = 'sun' | 'cloud' | 'rain' | 'snow' | 'fog' | 'snow-rain'; | ||
|
||
export type WeeklyWeather = { | ||
export type DuplicatedWeeklyWeather = { | ||
weather: Weather; | ||
temperature: { | ||
lowest: string; | ||
average: string; | ||
}; | ||
}; | ||
|
||
export type Url = { | ||
bus: string; | ||
homepage: string; | ||
}; | ||
|
||
export type Discovery = { | ||
id: number; | ||
name: string; | ||
map: string; | ||
slope: number | null; | ||
url: { | ||
bus: string; | ||
homepage: string; | ||
}; | ||
url: Url; | ||
weather: { | ||
weather: Weather; | ||
temperature: number; | ||
description: string; | ||
}; | ||
weeklyWeather: WeeklyWeather[]; | ||
weeklyWeather: DuplicatedWeeklyWeather[]; | ||
}; | ||
|
||
export type Vote = { | ||
resortId: number; | ||
totalVotes: number; | ||
positiveVotes: number; | ||
status: string; | ||
}; | ||
}; | ||
|
||
export type WeatherResponse = { | ||
resortId: number, | ||
currentWeather: { | ||
temperature: number, | ||
maxTemperature: number, | ||
minTemperature: number, | ||
feelsLike: number, | ||
description: string, | ||
condition: string | ||
}, | ||
hourlyWeather: [], | ||
weeklyWeather: WeeklyWeather[] | ||
} | ||
|
||
export type WeeklyWeather = { | ||
day: string; | ||
date: string; | ||
precipitationChance: string; | ||
maxTemperature: number; | ||
minTemperature: number; | ||
condition: string; | ||
}; | ||
|
||
export type SummarizedWeeklyWeather = { | ||
day: string; | ||
maxTemperature: number; | ||
minTemperature: number; | ||
description: string; | ||
}; | ||
|
||
export type Resort = { | ||
resortId: number, | ||
name: string, | ||
status: string, | ||
openSlopes: number, | ||
currentWeather: { | ||
temperature: number, | ||
description: string | ||
}, | ||
weeklyWeather: SummarizedWeeklyWeather[] | ||
} |
This file contains 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,21 @@ | ||
// eslint-disable-next-line boundaries/element-types | ||
import type { Weather } from "@/entities/discovery"; | ||
|
||
const weatherDescription = { | ||
sun: ['맑음'], | ||
cloud: ['구름', '구름많음'], | ||
rain: ['비', '구름많고 비', '흐리고 비', '구름많고 소나기', '흐리고 소나기'], | ||
snow: ['눈', '구름많고 눈', '흐리고 눈'], | ||
fog: ['안개', '흐림'], | ||
'snow-rain': ['흐리고 비/눈', '구름많고 비/눈'] | ||
} | ||
|
||
export const getWeatherFromDescription = (description: string): Weather => { | ||
for (const [weather, descriptions] of Object.entries(weatherDescription)) { | ||
if (descriptions.includes(description)) { | ||
return weather as Weather; | ||
} | ||
} | ||
|
||
return 'sun'; | ||
} |
This file contains 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 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 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 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 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.