@uniai-fe/uds-templates 0.5.29 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +3 -6
  2. package/package.json +1 -1
  3. package/src/weather/_legacy/apis/index.ts +4 -0
  4. package/src/weather/_legacy/data/response.ts +36 -0
  5. package/src/weather/_legacy/hooks/index.ts +5 -0
  6. package/src/weather/{hooks → _legacy/hooks}/useOpenWeatherMap.ts +1 -1
  7. package/src/weather/{hooks → _legacy/hooks}/useWeatherKorea.ts +4 -7
  8. package/src/weather/{hooks → _legacy/hooks}/useWeatherKoreaAlert.ts +2 -4
  9. package/src/weather/_legacy/types/api.ts +221 -0
  10. package/src/weather/_legacy/types/base.ts +70 -0
  11. package/src/weather/_legacy/types/index.ts +4 -0
  12. package/src/weather/_legacy/utils/index.ts +5 -0
  13. package/src/weather/_legacy/utils/locale.ts +28 -0
  14. package/src/weather/_legacy/utils/location.ts +139 -0
  15. package/src/weather/_legacy/utils/weather.ts +460 -0
  16. package/src/weather/apis/client.ts +459 -0
  17. package/src/weather/apis/index.ts +2 -4
  18. package/src/weather/apis/server.ts +373 -0
  19. package/src/weather/components/icon/Address.tsx +7 -0
  20. package/src/weather/components/icon/Weather.tsx +7 -6
  21. package/src/weather/components/page-header/Address.tsx +14 -0
  22. package/src/weather/components/page-header/Alert.tsx +17 -13
  23. package/src/weather/components/page-header/Container.tsx +12 -19
  24. package/src/weather/components/page-header/Forecast.tsx +21 -28
  25. package/src/weather/components/page-header/NextDays.tsx +10 -0
  26. package/src/weather/components/page-header/Today.tsx +86 -158
  27. package/src/weather/components/page-header/index.ts +5 -0
  28. package/src/weather/data/response.ts +4 -23
  29. package/src/weather/hooks/index.ts +3 -3
  30. package/src/weather/hooks/useWeather.ts +52 -0
  31. package/src/weather/hooks/useWeatherAlert.ts +35 -0
  32. package/src/weather/index.tsx +2 -2
  33. package/src/weather/jotai/coordinate.ts +4 -0
  34. package/src/weather/jotai/farm-idx.ts +4 -0
  35. package/src/weather/types/api.ts +442 -114
  36. package/src/weather/types/base.ts +31 -32
  37. package/src/weather/types/index.ts +0 -3
  38. package/src/weather/types/page-header.ts +118 -68
  39. package/src/weather/utils/index.ts +6 -4
  40. package/src/weather/utils/locale.ts +7 -69
  41. package/src/weather/utils/location.ts +47 -102
  42. package/src/weather/utils/weather.ts +53 -456
  43. package/src/weather/data/alert-regions-meta.json +0 -1286
  44. package/src/weather/data/weather-regions-meta.json +0 -9833
  45. package/src/weather/types/provider.ts +0 -34
  46. package/src/weather/utils/alert.ts +0 -30
  47. /package/src/weather/{apis → _legacy/apis}/korea/client.ts +0 -0
  48. /package/src/weather/{apis → _legacy/apis}/korea/server.ts +0 -0
  49. /package/src/weather/{apis → _legacy/apis}/open-weather-map/client.ts +0 -0
  50. /package/src/weather/{apis → _legacy/apis}/open-weather-map/server.ts +0 -0
  51. /package/src/weather/{types → _legacy/types}/korea.ts +0 -0
  52. /package/src/weather/{types → _legacy/types}/open-weather-map.ts +0 -0
  53. /package/src/weather/{utils → _legacy/utils}/date-time.ts +0 -0
  54. /package/src/weather/{utils → _legacy/utils}/validate.ts +0 -0
@@ -0,0 +1,459 @@
1
+ "use client";
2
+
3
+ import { useQuery, type UseQueryResult } from "@tanstack/react-query";
4
+ import { getQueryString } from "@uniai-fe/util-api";
5
+ import { isValidNumber } from "@uniai-fe/util-functions";
6
+ import type {
7
+ API_Req_Weather,
8
+ API_Req_WeatherAlert,
9
+ API_Res_WeatherAlert,
10
+ API_Res_WeatherForecast,
11
+ API_Res_WeatherNow,
12
+ API_Res_WeatherSummary,
13
+ WeatherClientQueryOptions,
14
+ WeatherClientRouteOptions,
15
+ } from "../types";
16
+
17
+ const WEATHER_CLIENT_ROUTE_PATH = {
18
+ now: "/api/weather/now",
19
+ forecast: "/api/weather/forecast",
20
+ summary: "/api/weather/summary",
21
+ alert: "/api/weather/alert",
22
+ } as const;
23
+
24
+ /**
25
+ * Weather Client; query string에 포함 가능한 값인지 확인.
26
+ * @param {unknown} value 확인할 query 값
27
+ * @return {boolean} query 포함 가능 여부
28
+ */
29
+ const hasQueryValue = (value: unknown): boolean =>
30
+ value !== null && typeof value !== "undefined" && value !== "";
31
+
32
+ /**
33
+ * Weather Client; backend weather route query로 전달할 값만 정리.
34
+ * @param {API_Req_Weather} params 날씨 요청 파라미터
35
+ * @param {number|string|null} [params.farm_idx] 농장 식별자
36
+ * @param {number|null} [params.lat] 위도
37
+ * @param {number|null} [params.lng] 경도
38
+ * @param {number|null} [params.nx] backend 격자 X
39
+ * @param {number|null} [params.ny] backend 격자 Y
40
+ * @param {string} [params.base_date] 현재/예보 단일 route 재현용 날짜
41
+ * @param {string} [params.base_time] 현재/예보 단일 route 재현용 시각
42
+ * @param {string} [params.now_base_date] summary 현재 날씨 재현용 날짜
43
+ * @param {string} [params.now_base_time] summary 현재 날씨 재현용 시각
44
+ * @param {string} [params.forecast_base_date] summary 예보 날씨 재현용 날짜
45
+ * @param {string} [params.forecast_base_time] summary 예보 날씨 재현용 시각
46
+ * @param {string} [params.locale] 요청 언어 코드
47
+ * @param {boolean} [params.include_raw] 원본 응답 포함 여부
48
+ * @return {API_Req_Weather} local route query 파라미터
49
+ */
50
+ export const getWeatherClientParams = ({
51
+ farm_idx,
52
+ lat,
53
+ lng,
54
+ nx,
55
+ ny,
56
+ base_date,
57
+ base_time,
58
+ now_base_date,
59
+ now_base_time,
60
+ forecast_base_date,
61
+ forecast_base_time,
62
+ locale,
63
+ include_raw,
64
+ }: API_Req_Weather): API_Req_Weather => ({
65
+ ...(hasQueryValue(farm_idx) ? { farm_idx } : {}),
66
+ ...(hasQueryValue(lat) ? { lat } : {}),
67
+ ...(hasQueryValue(lng) ? { lng } : {}),
68
+ ...(hasQueryValue(nx) ? { nx } : {}),
69
+ ...(hasQueryValue(ny) ? { ny } : {}),
70
+ ...(hasQueryValue(base_date) ? { base_date } : {}),
71
+ ...(hasQueryValue(base_time) ? { base_time } : {}),
72
+ ...(hasQueryValue(now_base_date) ? { now_base_date } : {}),
73
+ ...(hasQueryValue(now_base_time) ? { now_base_time } : {}),
74
+ ...(hasQueryValue(forecast_base_date) ? { forecast_base_date } : {}),
75
+ ...(hasQueryValue(forecast_base_time) ? { forecast_base_time } : {}),
76
+ ...(locale ? { locale } : {}),
77
+ ...(typeof include_raw === "boolean" ? { include_raw } : {}),
78
+ });
79
+
80
+ /**
81
+ * Weather Client; route override 또는 기본 local route 경로 선택.
82
+ * @param {string} [routePath] service app의 local weather route 경로
83
+ * @param {string} fallbackRoutePath 기본 local weather route 경로
84
+ * @return {string} fetch에 사용할 local route 경로
85
+ */
86
+ const getWeatherRoutePath = (
87
+ routePath: string | undefined,
88
+ fallbackRoutePath: string,
89
+ ): string => routePath || fallbackRoutePath;
90
+
91
+ /**
92
+ * Weather Client; 현재/예보 조회가 가능한 위치 입력인지 확인.
93
+ * @param {API_Req_Weather} params 날씨 요청 파라미터
94
+ * @param {number|null} [params.lat] 위도
95
+ * @param {number|null} [params.lng] 경도
96
+ * @param {number|null} [params.nx] backend 격자 X
97
+ * @param {number|null} [params.ny] backend 격자 Y
98
+ * @return {boolean} 위치 기반 weather query 실행 가능 여부
99
+ */
100
+ const isWeatherLocationAvailable = ({ lat, lng }: API_Req_Weather): boolean =>
101
+ lat !== null &&
102
+ lng !== null &&
103
+ typeof lat !== "undefined" &&
104
+ typeof lng !== "undefined" &&
105
+ isValidNumber(lat) &&
106
+ isValidNumber(lng);
107
+
108
+ /**
109
+ * Weather Client; backend 격자 입력이 사용 가능한지 확인.
110
+ * @param {API_Req_Weather} params 날씨 요청 파라미터
111
+ * @param {number|null} [params.nx] backend 격자 X
112
+ * @param {number|null} [params.ny] backend 격자 Y
113
+ * @return {boolean} 격자 기반 weather query 실행 가능 여부
114
+ */
115
+ const isWeatherGridAvailable = ({ nx, ny }: API_Req_Weather): boolean =>
116
+ nx !== null &&
117
+ ny !== null &&
118
+ typeof nx !== "undefined" &&
119
+ typeof ny !== "undefined" &&
120
+ isValidNumber(nx) &&
121
+ isValidNumber(ny) &&
122
+ Number(nx) > 0 &&
123
+ Number(ny) > 0;
124
+
125
+ /**
126
+ * Weather Client; 특보 조회가 가능한 농장 식별자인지 확인.
127
+ * @param {API_Req_WeatherAlert} params 특보 요청 파라미터
128
+ * @param {number|string|null} params.farm_idx 농장 식별자
129
+ * @return {boolean} 특보 query 실행 가능 여부
130
+ */
131
+ const isWeatherFarmAvailable = ({ farm_idx }: API_Req_WeatherAlert): boolean =>
132
+ hasQueryValue(farm_idx) && Number(farm_idx) > 0;
133
+
134
+ /**
135
+ * Weather Client; summary 조회에 필요한 입력인지 확인.
136
+ * @param {API_Req_Weather} params summary 요청 파라미터
137
+ * @param {number|string|null} [params.farm_idx] 농장 식별자
138
+ * @return {boolean} summary query 실행 가능 여부
139
+ */
140
+ const isWeatherSummaryAvailable = (params: API_Req_Weather): boolean =>
141
+ isWeatherFarmAvailable({ farm_idx: params.farm_idx ?? null }) &&
142
+ (isWeatherLocationAvailable(params) || isWeatherGridAvailable(params));
143
+
144
+ /**
145
+ * Weather Client; React Query key에 사용할 weather 요청 값을 정렬.
146
+ * @param {API_Req_Weather} params 날씨 요청 파라미터
147
+ * @param {number|string|null} [params.farm_idx] 농장 식별자
148
+ * @param {number|null} [params.lat] 위도
149
+ * @param {number|null} [params.lng] 경도
150
+ * @param {number|null} [params.nx] backend 격자 X
151
+ * @param {number|null} [params.ny] backend 격자 Y
152
+ * @param {string} [params.base_date] 현재/예보 단일 route 재현용 날짜
153
+ * @param {string} [params.base_time] 현재/예보 단일 route 재현용 시각
154
+ * @param {string} [params.now_base_date] summary 현재 날씨 재현용 날짜
155
+ * @param {string} [params.now_base_time] summary 현재 날씨 재현용 시각
156
+ * @param {string} [params.forecast_base_date] summary 예보 날씨 재현용 날짜
157
+ * @param {string} [params.forecast_base_time] summary 예보 날씨 재현용 시각
158
+ * @param {string} [params.locale] 요청 언어 코드
159
+ * @param {boolean} [params.include_raw] 원본 응답 포함 여부
160
+ * @return {readonly unknown[]} React Query key 값
161
+ */
162
+ const getWeatherQueryKeyValues = (params: API_Req_Weather) => {
163
+ const {
164
+ farm_idx,
165
+ lat,
166
+ lng,
167
+ nx,
168
+ ny,
169
+ base_date,
170
+ base_time,
171
+ now_base_date,
172
+ now_base_time,
173
+ forecast_base_date,
174
+ forecast_base_time,
175
+ locale,
176
+ include_raw,
177
+ } = getWeatherClientParams(params);
178
+
179
+ return [
180
+ farm_idx,
181
+ lat,
182
+ lng,
183
+ nx,
184
+ ny,
185
+ base_date,
186
+ base_time,
187
+ now_base_date,
188
+ now_base_time,
189
+ forecast_base_date,
190
+ forecast_base_time,
191
+ locale,
192
+ include_raw,
193
+ ] as const;
194
+ };
195
+
196
+ /**
197
+ * Weather Client; 현재 날씨 fetch.
198
+ * @method GET
199
+ * @param {API_Req_WeatherNow} params 현재 날씨 요청 파라미터
200
+ * @param {number|string|null} [params.farm_idx] 농장 식별자
201
+ * @param {number|null} [params.lat] 위도
202
+ * @param {number|null} [params.lng] 경도
203
+ * @param {number|null} [params.nx] backend 격자 X
204
+ * @param {number|null} [params.ny] backend 격자 Y
205
+ * @param {string} [params.base_date] 현재 날씨 재현용 날짜
206
+ * @param {string} [params.base_time] 현재 날씨 재현용 시각
207
+ * @param {string} [params.locale] 요청 언어 코드
208
+ * @param {boolean} [params.include_raw] 원본 응답 포함 여부
209
+ * @param {WeatherClientRouteOptions} [options] local route 옵션
210
+ * @param {string} [options.routePath] service app의 local weather route 경로
211
+ * @return {Promise<Data>} 현재 날씨 응답
212
+ */
213
+ export const getWeatherNow = async <Data = API_Res_WeatherNow>(
214
+ params: API_Req_Weather,
215
+ options: WeatherClientRouteOptions = {},
216
+ ): Promise<Data> =>
217
+ await (
218
+ await fetch(
219
+ `${getWeatherRoutePath(
220
+ options.routePath,
221
+ WEATHER_CLIENT_ROUTE_PATH.now,
222
+ )}${getQueryString(getWeatherClientParams(params))}`,
223
+ )
224
+ ).json();
225
+
226
+ /**
227
+ * Weather Client; 예보 날씨 fetch.
228
+ * @method GET
229
+ * @param {API_Req_WeatherForecast} params 예보 날씨 요청 파라미터
230
+ * @param {number|string|null} [params.farm_idx] 농장 식별자
231
+ * @param {number|null} [params.lat] 위도
232
+ * @param {number|null} [params.lng] 경도
233
+ * @param {number|null} [params.nx] backend 격자 X
234
+ * @param {number|null} [params.ny] backend 격자 Y
235
+ * @param {string} [params.base_date] 예보 날씨 재현용 날짜
236
+ * @param {string} [params.base_time] 예보 날씨 재현용 시각
237
+ * @param {string} [params.locale] 요청 언어 코드
238
+ * @param {boolean} [params.include_raw] 원본 응답 포함 여부
239
+ * @param {WeatherClientRouteOptions} [options] local route 옵션
240
+ * @param {string} [options.routePath] service app의 local weather route 경로
241
+ * @return {Promise<Data>} 예보 날씨 응답
242
+ */
243
+ export const getWeatherForecast = async <Data = API_Res_WeatherForecast>(
244
+ params: API_Req_Weather,
245
+ options: WeatherClientRouteOptions = {},
246
+ ): Promise<Data> =>
247
+ await (
248
+ await fetch(
249
+ `${getWeatherRoutePath(
250
+ options.routePath,
251
+ WEATHER_CLIENT_ROUTE_PATH.forecast,
252
+ )}${getQueryString(getWeatherClientParams(params))}`,
253
+ )
254
+ ).json();
255
+
256
+ /**
257
+ * Weather Client; summary fetch.
258
+ * @method GET
259
+ * @param {API_Req_WeatherSummary} params summary 요청 파라미터
260
+ * @param {number|string|null} [params.farm_idx] 농장 식별자
261
+ * @param {number|null} [params.lat] 위도
262
+ * @param {number|null} [params.lng] 경도
263
+ * @param {number|null} [params.nx] backend 격자 X
264
+ * @param {number|null} [params.ny] backend 격자 Y
265
+ * @param {string} [params.now_base_date] summary 현재 날씨 재현용 날짜
266
+ * @param {string} [params.now_base_time] summary 현재 날씨 재현용 시각
267
+ * @param {string} [params.forecast_base_date] summary 예보 날씨 재현용 날짜
268
+ * @param {string} [params.forecast_base_time] summary 예보 날씨 재현용 시각
269
+ * @param {string} [params.locale] 요청 언어 코드
270
+ * @param {boolean} [params.include_raw] 원본 응답 포함 여부
271
+ * @param {WeatherClientRouteOptions} [options] local route 옵션
272
+ * @param {string} [options.routePath] service app의 local weather route 경로
273
+ * @return {Promise<Data>} summary 응답
274
+ */
275
+ export const getWeatherSummary = async <Data = API_Res_WeatherSummary>(
276
+ params: API_Req_Weather,
277
+ options: WeatherClientRouteOptions = {},
278
+ ): Promise<Data> =>
279
+ await (
280
+ await fetch(
281
+ `${getWeatherRoutePath(
282
+ options.routePath,
283
+ WEATHER_CLIENT_ROUTE_PATH.summary,
284
+ )}${getQueryString(getWeatherClientParams(params))}`,
285
+ )
286
+ ).json();
287
+
288
+ /**
289
+ * Weather Client; 특보 fetch.
290
+ * @method GET
291
+ * @param {API_Req_WeatherAlert} params 특보 요청 파라미터
292
+ * @param {number|string|null} params.farm_idx 농장 식별자
293
+ * @param {WeatherClientRouteOptions} [options] local route 옵션
294
+ * @param {string} [options.routePath] service app의 local weather route 경로
295
+ * @return {Promise<Data>} 특보 응답
296
+ */
297
+ export const getWeatherAlert = async <Data = API_Res_WeatherAlert>(
298
+ params: API_Req_WeatherAlert,
299
+ options: WeatherClientRouteOptions = {},
300
+ ): Promise<Data> =>
301
+ await (
302
+ await fetch(
303
+ `${getWeatherRoutePath(
304
+ options.routePath,
305
+ WEATHER_CLIENT_ROUTE_PATH.alert,
306
+ )}${getQueryString(params)}`,
307
+ )
308
+ ).json();
309
+
310
+ /**
311
+ * Weather Client; 현재 날씨 react query.
312
+ * @method GET
313
+ * @param {API_Req_WeatherNow} params 현재 날씨 요청 파라미터
314
+ * @param {number|string|null} [params.farm_idx] 농장 식별자
315
+ * @param {number|null} [params.lat] 위도
316
+ * @param {number|null} [params.lng] 경도
317
+ * @param {number|null} [params.nx] backend 격자 X
318
+ * @param {number|null} [params.ny] backend 격자 Y
319
+ * @param {string} [params.base_date] 현재 날씨 재현용 날짜
320
+ * @param {string} [params.base_time] 현재 날씨 재현용 시각
321
+ * @param {string} [params.locale] 요청 언어 코드
322
+ * @param {boolean} [params.include_raw] 원본 응답 포함 여부
323
+ * @param {WeatherClientQueryOptions} [options] query 옵션
324
+ * @param {boolean} [options.enabled] query 실행 여부
325
+ * @param {string} [options.routePath] service app의 local weather route 경로
326
+ * @return {UseQueryResult<Data>} 현재 날씨 query 결과
327
+ */
328
+ export const useQueryWeatherNow = <Data = API_Res_WeatherNow>(
329
+ params: API_Req_Weather,
330
+ options: WeatherClientQueryOptions = {},
331
+ ): UseQueryResult<Data> => {
332
+ const routePath = getWeatherRoutePath(
333
+ options.routePath,
334
+ WEATHER_CLIENT_ROUTE_PATH.now,
335
+ );
336
+
337
+ return useQuery({
338
+ queryKey: ["weather_now", routePath, ...getWeatherQueryKeyValues(params)],
339
+ queryFn: () => getWeatherNow<Data>(params, { routePath }),
340
+ enabled:
341
+ (options.enabled ?? true) &&
342
+ (isWeatherLocationAvailable(params) || isWeatherGridAvailable(params)),
343
+ staleTime: 10 * 60 * 1000,
344
+ refetchInterval: 5 * 60 * 1000,
345
+ refetchOnWindowFocus: true,
346
+ });
347
+ };
348
+
349
+ /**
350
+ * Weather Client; 예보 날씨 react query.
351
+ * @method GET
352
+ * @param {API_Req_WeatherForecast} params 예보 날씨 요청 파라미터
353
+ * @param {number|string|null} [params.farm_idx] 농장 식별자
354
+ * @param {number|null} [params.lat] 위도
355
+ * @param {number|null} [params.lng] 경도
356
+ * @param {number|null} [params.nx] backend 격자 X
357
+ * @param {number|null} [params.ny] backend 격자 Y
358
+ * @param {string} [params.base_date] 예보 날씨 재현용 날짜
359
+ * @param {string} [params.base_time] 예보 날씨 재현용 시각
360
+ * @param {string} [params.locale] 요청 언어 코드
361
+ * @param {boolean} [params.include_raw] 원본 응답 포함 여부
362
+ * @param {WeatherClientQueryOptions} [options] query 옵션
363
+ * @param {boolean} [options.enabled] query 실행 여부
364
+ * @param {string} [options.routePath] service app의 local weather route 경로
365
+ * @return {UseQueryResult<Data>} 예보 날씨 query 결과
366
+ */
367
+ export const useQueryWeatherForecast = <Data = API_Res_WeatherForecast>(
368
+ params: API_Req_Weather,
369
+ options: WeatherClientQueryOptions = {},
370
+ ): UseQueryResult<Data> => {
371
+ const routePath = getWeatherRoutePath(
372
+ options.routePath,
373
+ WEATHER_CLIENT_ROUTE_PATH.forecast,
374
+ );
375
+
376
+ return useQuery({
377
+ queryKey: [
378
+ "weather_forecast",
379
+ routePath,
380
+ ...getWeatherQueryKeyValues(params),
381
+ ],
382
+ queryFn: () => getWeatherForecast<Data>(params, { routePath }),
383
+ enabled:
384
+ (options.enabled ?? true) &&
385
+ (isWeatherLocationAvailable(params) || isWeatherGridAvailable(params)),
386
+ staleTime: 30 * 60 * 1000,
387
+ });
388
+ };
389
+
390
+ /**
391
+ * Weather Client; summary react query.
392
+ * @method GET
393
+ * @param {API_Req_WeatherSummary} params summary 요청 파라미터
394
+ * @param {number|string|null} [params.farm_idx] 농장 식별자
395
+ * @param {number|null} [params.lat] 위도
396
+ * @param {number|null} [params.lng] 경도
397
+ * @param {number|null} [params.nx] backend 격자 X
398
+ * @param {number|null} [params.ny] backend 격자 Y
399
+ * @param {string} [params.now_base_date] summary 현재 날씨 재현용 날짜
400
+ * @param {string} [params.now_base_time] summary 현재 날씨 재현용 시각
401
+ * @param {string} [params.forecast_base_date] summary 예보 날씨 재현용 날짜
402
+ * @param {string} [params.forecast_base_time] summary 예보 날씨 재현용 시각
403
+ * @param {string} [params.locale] 요청 언어 코드
404
+ * @param {boolean} [params.include_raw] 원본 응답 포함 여부
405
+ * @param {WeatherClientQueryOptions} [options] query 옵션
406
+ * @param {boolean} [options.enabled] query 실행 여부
407
+ * @param {string} [options.routePath] service app의 local weather route 경로
408
+ * @return {UseQueryResult<Data>} summary query 결과
409
+ */
410
+ export const useQueryWeatherSummary = <Data = API_Res_WeatherSummary>(
411
+ params: API_Req_Weather,
412
+ options: WeatherClientQueryOptions = {},
413
+ ): UseQueryResult<Data> => {
414
+ const routePath = getWeatherRoutePath(
415
+ options.routePath,
416
+ WEATHER_CLIENT_ROUTE_PATH.summary,
417
+ );
418
+
419
+ return useQuery({
420
+ queryKey: [
421
+ "weather_summary",
422
+ routePath,
423
+ ...getWeatherQueryKeyValues(params),
424
+ ],
425
+ queryFn: () => getWeatherSummary<Data>(params, { routePath }),
426
+ enabled: (options.enabled ?? true) && isWeatherSummaryAvailable(params),
427
+ staleTime: 10 * 60 * 1000,
428
+ });
429
+ };
430
+
431
+ /**
432
+ * Weather Client; 특보 react query.
433
+ * @method GET
434
+ * @param {API_Req_WeatherAlert} params 특보 요청 파라미터
435
+ * @param {number|string|null} params.farm_idx 농장 식별자
436
+ * @param {WeatherClientQueryOptions} [options] query 옵션
437
+ * @param {boolean} [options.enabled] query 실행 여부
438
+ * @param {string} [options.routePath] service app의 local weather route 경로
439
+ * @return {UseQueryResult<Data>} 특보 query 결과
440
+ */
441
+ export const useQueryWeatherAlert = <Data = API_Res_WeatherAlert>(
442
+ params: API_Req_WeatherAlert,
443
+ options: WeatherClientQueryOptions = {},
444
+ ): UseQueryResult<Data> => {
445
+ const farmIdx = params.farm_idx;
446
+ const routePath = getWeatherRoutePath(
447
+ options.routePath,
448
+ WEATHER_CLIENT_ROUTE_PATH.alert,
449
+ );
450
+
451
+ return useQuery({
452
+ queryKey: ["weather_alert", routePath, farmIdx],
453
+ queryFn: () => getWeatherAlert<Data>({ farm_idx: farmIdx }, { routePath }),
454
+ enabled:
455
+ (options.enabled ?? true) &&
456
+ isWeatherFarmAvailable({ farm_idx: farmIdx }),
457
+ staleTime: 60 * 60 * 1000,
458
+ });
459
+ };
@@ -1,4 +1,2 @@
1
- export * from "./korea/client";
2
- export * from "./korea/server";
3
- export * from "./open-weather-map/client";
4
- export * from "./open-weather-map/server";
1
+ export * from "./client";
2
+ export * from "./server";