From 0672a547b1d31de359842f396af581a53a4fd492 Mon Sep 17 00:00:00 2001 From: hhjk00 Date: Mon, 13 Nov 2023 16:32:43 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B9=84=ED=96=89=20=EC=8B=A4=EC=A0=81=20api?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/statistics/actions/index.ts | 34 ++++++++++++-- src/modules/statistics/apis/index.ts | 26 ++++++++-- src/modules/statistics/models/index.ts | 49 +++++++++---------- src/modules/statistics/reducers/index.ts | 16 +++++++ src/modules/statistics/sagas/index.ts | 60 +++++++++++++++++++++++- 5 files changed, 149 insertions(+), 36 deletions(-) diff --git a/src/modules/statistics/actions/index.ts b/src/modules/statistics/actions/index.ts index 54357b78..50a2e4a1 100644 --- a/src/modules/statistics/actions/index.ts +++ b/src/modules/statistics/actions/index.ts @@ -1,6 +1,6 @@ import { AxiosError } from 'axios'; import { createAsyncAction, ActionType } from 'typesafe-actions'; -import { Flight, FlightSearch, FlightSearchRq } from '../models'; +import { IStcsRs, IStcsSearchRq, IStcsSearchRs } from '../models'; // 비행 통계 (비행시간, 비행거리, 비행횟수) const FLIGHT_STCS_REQUEST = 'statistics/flight/FLIGHT_STCS_REQUEST'; @@ -15,21 +15,47 @@ const FLIGHT_STCS_SEARCH_SUCCESS = const FLIGHT_STCS_SEARCH_FAILURE = 'statistics/flight/FLIGHT_STCS_SEARCH_FAILURE'; +// 비행 실적 통계 (비행실적, 비행계획, 비행승인) +const RESULT_STCS_REQUEST = 'statistics/flight/RESULT_STCS_REQUEST'; +const RESULT_STCS_SUCCESS = 'statistics/flight/RESULT_STCS_SUCCESS'; +const RESULT_STCS_FAILURE = 'statistics/flight/RESULT_STCS_FAILURE'; + +// 비행 실적 통계 카테고리별 검색 +const RESULT_STCS_SEARCH_REQUEST = 'statistics/RESULT_STCS_SEARCH_REQUEST'; +const RESULT_STCS_SEARCH_SUCCESS = + 'statistics/flight/RESULT_STCS_SEARCH_SUCCESS'; +const RESULT_STCS_SEARCH_FAILURE = + 'statistics/flight/RESULT_STCS_SEARCH_FAILURE'; + export const FLIGHT_STCS = createAsyncAction( FLIGHT_STCS_REQUEST, FLIGHT_STCS_SUCCESS, FLIGHT_STCS_FAILURE -)(); +)(); export const FLIGHT_STCS_SEARCH = createAsyncAction( FLIGHT_STCS_SEARCH_REQUEST, FLIGHT_STCS_SEARCH_SUCCESS, FLIGHT_STCS_SEARCH_FAILURE -)(); +)(); + +export const RESULT_STCS = createAsyncAction( + RESULT_STCS_REQUEST, + RESULT_STCS_SUCCESS, + RESULT_STCS_FAILURE +)(); + +export const RESULT_STCS_SEARCH = createAsyncAction( + RESULT_STCS_SEARCH_REQUEST, + RESULT_STCS_SEARCH_SUCCESS, + RESULT_STCS_SEARCH_FAILURE +)(); const actions = { FLIGHT_STCS, - FLIGHT_STCS_SEARCH + FLIGHT_STCS_SEARCH, + RESULT_STCS, + RESULT_STCS_SEARCH }; export type StatisticsAction = ActionType; diff --git a/src/modules/statistics/apis/index.ts b/src/modules/statistics/apis/index.ts index af20220f..51198792 100644 --- a/src/modules/statistics/apis/index.ts +++ b/src/modules/statistics/apis/index.ts @@ -1,12 +1,12 @@ import axios from '../../utils/customAxiosUtil'; import qs from 'qs'; -import { FlightSearchRq } from '../models'; +import { IStcsSearchRq } from '../models'; -export const stcsAPI = { +export const statisticsAPI = { flight: async () => { return await axios.get('/api/main/statistics/flight-static'); }, - flightSearch: async (data: FlightSearchRq) => { + flightSearch: async (data: IStcsSearchRq) => { const { type } = data; const params = {}; Object.keys(data).forEach(i => { @@ -20,5 +20,25 @@ export const stcsAPI = { }); return await axios.get(`api/main/statistics/flight/${type}${queryString}`); + }, + result: async () => { + return await axios.get('/api/main/statistics/flight/result-static'); + }, + resultSearch: async (data: IStcsSearchRq) => { + const { type } = data; + const params = {}; + Object.keys(data).forEach(i => { + if (data[i] && i !== 'type') { + params[`${i}`] = data[i]; + } + }); + const queryString = qs.stringify(params, { + addQueryPrefix: true, + arrayFormat: 'repeat' + }); + + return await axios.get( + `/api/main/statistics/flight/result/${type}${queryString}` + ); } }; diff --git a/src/modules/statistics/models/index.ts b/src/modules/statistics/models/index.ts index 7a066ba4..5d90bb1c 100644 --- a/src/modules/statistics/models/index.ts +++ b/src/modules/statistics/models/index.ts @@ -1,46 +1,41 @@ export interface IStatisticsState { - flight: Flight; - flightSearch: FlightSearch; + flight: IStcsRs[]; + flightSearch: IStcsSearchRs; + result: IStcsRs[]; + resultSearch: IStcsSearchRs; } -export interface Flight { - count: number; - data: { - name: string; - year: string; - month: string; - day: string; - }[]; +export interface IStcsRs { + name: string; + year: string; + month: string; + day: string; } -export interface FlightSearch { - count: number; - data: { - graphData: SearchData[]; - topData: SearchData[]; - }; +export interface IStcsSearchRs { + graphData: IStcsSearchData[]; + topData: IStcsSearchData[]; } -export interface SearchData { +export interface IStcsSearchData { name: string; value: number; } -export interface FlightSearchRq { +export interface IStcsSearchRq { cate: string; date: string; type: string; } export const initialState = { - flight: { - count: 0, - data: [] - }, + flight: [], flightSearch: { - count: 0, - data: { - graphData: [], - topData: [] - } + graphData: [], + topData: [] + }, + result: [], + resultSearch: { + graphData: [], + topData: [] } }; diff --git a/src/modules/statistics/reducers/index.ts b/src/modules/statistics/reducers/index.ts index ecad560b..8db03e20 100644 --- a/src/modules/statistics/reducers/index.ts +++ b/src/modules/statistics/reducers/index.ts @@ -21,4 +21,20 @@ export const statisticsReducer = createReducer< const data = action.payload; draft.flightSearch = data || state.flightSearch; }) + ) + + // 비행 실적 통계 (비행실적, 비행계획, 비행승인) + .handleAction(Actions.RESULT_STCS.success, (state, action) => + produce(state, draft => { + const data = action.payload; + draft.result = data || state.result; + }) + ) + + // 비행 실적 통계 카테고리별 검색 + .handleAction(Actions.RESULT_STCS_SEARCH.success, (state, action) => + produce(state, draft => { + const data = action.payload; + draft.resultSearch = data || state.resultSearch; + }) ); diff --git a/src/modules/statistics/sagas/index.ts b/src/modules/statistics/sagas/index.ts index eb616a0c..d03a88b1 100644 --- a/src/modules/statistics/sagas/index.ts +++ b/src/modules/statistics/sagas/index.ts @@ -9,7 +9,7 @@ function* flightStcsSaga( ) { try { const payload = action.payload; - const res = yield call(Apis.stcsAPI.flight); + const res = yield call(Apis.statisticsAPI.flight); const { data, errorCode } = res; if (errorCode) { @@ -36,7 +36,7 @@ function* flightStcsSearchSaga( ) { try { const payload = action.payload; - const res = yield call(Apis.stcsAPI.flightSearch, payload); + const res = yield call(Apis.statisticsAPI.flightSearch, payload); const { data, errorCode } = res; if (errorCode) { @@ -58,7 +58,63 @@ function* flightStcsSearchSaga( } } +function* resultStcsSaga( + action: ActionType +) { + try { + const payload = action.payload; + const res = yield call(Apis.statisticsAPI.result); + const { data, errorCode } = res; + + if (errorCode) { + // 오류메시지 호출 + yield put( + MessageActions.IS_ERROR({ + errorCode: errorCode, + errorMessage: '처리중 오류가 발생하였습니다', + isHistoryBack: false, + isRefresh: false + }) + ); + + return; + } + yield put(Actions.RESULT_STCS.success(data)); + } catch (error) { + yield put(Actions.RESULT_STCS.failure(error)); + } +} + +function* resultStcsSearchSaga( + action: ActionType +) { + try { + const payload = action.payload; + const res = yield call(Apis.statisticsAPI.resultSearch, payload); + const { data, errorCode } = res; + + if (errorCode) { + // 오류메시지 호출 + yield put( + MessageActions.IS_ERROR({ + errorCode: errorCode, + errorMessage: '처리중 오류가 발생하였습니다', + isHistoryBack: false, + isRefresh: false + }) + ); + + return; + } + yield put(Actions.RESULT_STCS_SEARCH.success(data)); + } catch (error) { + yield put(Actions.RESULT_STCS_SEARCH.failure(error)); + } +} + export function* statisticsSaga() { yield takeEvery(Actions.FLIGHT_STCS.request, flightStcsSaga); yield takeEvery(Actions.FLIGHT_STCS_SEARCH.request, flightStcsSearchSaga); + yield takeEvery(Actions.RESULT_STCS.request, resultStcsSaga); + yield takeEvery(Actions.RESULT_STCS_SEARCH.request, resultStcsSearchSaga); }