-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 現在の天気情報取得処理を新しいAPI方式に移行した(#14)
- Loading branch information
1 parent
a574919
commit 5341831
Showing
7 changed files
with
71 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Options } from 'ky-universal'; | ||
import { getExtendKy } from '@/config/ky'; | ||
import { isCurrentWeather } from '@/models/Weather'; | ||
|
||
const units = ['standard', 'metric', 'imperial'] as const; | ||
|
||
export type CurrentWeatherQuery = { | ||
/** 緯度 */ | ||
lat: number; | ||
/** 経度 */ | ||
lon: number; | ||
/** 測定単位 デフォルトは standard */ | ||
units?: (typeof units)[number]; | ||
}; | ||
|
||
export const getCurrentWeather = async ( | ||
options: Options & { searchParams: CurrentWeatherQuery }, | ||
) => { | ||
const response = await getExtendKy('inner', options).get('weather'); | ||
const currentWeather = (await response.json()) as unknown[]; | ||
|
||
if (!isCurrentWeather(currentWeather)) { | ||
throw Error('API type error'); | ||
} | ||
|
||
return currentWeather; | ||
}; |
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,3 @@ | ||
import { getCurrentWeather } from './getCurrentWeather'; | ||
|
||
export { getCurrentWeather }; |
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