hhjk00
10 months ago
6 changed files with 197 additions and 1 deletions
@ -0,0 +1,35 @@
|
||||
import { AxiosError } from 'axios'; |
||||
import { createAsyncAction, ActionType } from 'typesafe-actions'; |
||||
import { Flight, FlightSearch, FlightSearchRq } from '../model'; |
||||
|
||||
// 비행 통계 (비행시간, 비행거리, 비행횟수)
|
||||
const FLIGHT_STCS_REQUEST = 'statistics/flight/FLIGHT_STCS_REQUEST'; |
||||
const FLIGHT_STCS_SUCCESS = 'statistics/flight/FLIGHT_STCS_SUCCESS'; |
||||
const FLIGHT_STCS_FAILURE = 'statistics/flight/FLIGHT_STCS_FAILURE'; |
||||
|
||||
// 비행 통계 카테고리별 검색
|
||||
const FLIGHT_STCS_SEARCH_REQUEST = |
||||
'statistics/flight/FLIGHT_STCS_SEARCH_REQUEST'; |
||||
const FLIGHT_STCS_SEARCH_SUCCESS = |
||||
'statistics/flight/FLIGHT_STCS_SEARCH_SUCCESS'; |
||||
const FLIGHT_STCS_SEARCH_FAILURE = |
||||
'statistics/flight/FLIGHT_STCS_SEARCH_FAILURE'; |
||||
|
||||
export const FLIGHT_STCS = createAsyncAction( |
||||
FLIGHT_STCS_REQUEST, |
||||
FLIGHT_STCS_SUCCESS, |
||||
FLIGHT_STCS_FAILURE |
||||
)<null, Flight, AxiosError>(); |
||||
|
||||
export const FLIGHT_STCS_SEARCH = createAsyncAction( |
||||
FLIGHT_STCS_SEARCH_REQUEST, |
||||
FLIGHT_STCS_SEARCH_SUCCESS, |
||||
FLIGHT_STCS_SEARCH_FAILURE |
||||
)<FlightSearchRq, FlightSearch, AxiosError>(); |
||||
|
||||
const actions = { |
||||
FLIGHT_STCS, |
||||
FLIGHT_STCS_SEARCH |
||||
}; |
||||
|
||||
export type StcsAction = ActionType<typeof actions>; |
@ -0,0 +1,24 @@
|
||||
import axios from '../../utils/customAxiosUtil'; |
||||
import qs from 'qs'; |
||||
import { FlightSearchRq } from '../model'; |
||||
|
||||
export const stcsAPI = { |
||||
flight: async () => { |
||||
return await axios.get('/api/main/dash/stcs/flight-static'); |
||||
}, |
||||
flightSearch: async (data: FlightSearchRq) => { |
||||
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/dash/stcs/flight/${type}${queryString}`); |
||||
} |
||||
}; |
@ -0,0 +1,46 @@
|
||||
export interface IStcsState { |
||||
flight: Flight; |
||||
flightSearch: FlightSearch; |
||||
} |
||||
|
||||
export interface Flight { |
||||
count: number; |
||||
data: { |
||||
name: string; |
||||
year: string; |
||||
month: string; |
||||
day: string; |
||||
}[]; |
||||
} |
||||
|
||||
export interface FlightSearch { |
||||
count: number; |
||||
data: { |
||||
graphData: SearchData[]; |
||||
topData: SearchData[]; |
||||
}; |
||||
} |
||||
export interface SearchData { |
||||
name: string; |
||||
value: number; |
||||
} |
||||
|
||||
export interface FlightSearchRq { |
||||
cate: string; |
||||
date: string; |
||||
type: string; |
||||
} |
||||
|
||||
export const initialState = { |
||||
flight: { |
||||
count: 0, |
||||
data: [] |
||||
}, |
||||
flightSearch: { |
||||
count: 0, |
||||
data: { |
||||
graphData: [], |
||||
topData: [] |
||||
} |
||||
} |
||||
}; |
@ -0,0 +1,23 @@
|
||||
import { createReducer } from 'typesafe-actions'; |
||||
import produce from 'immer'; |
||||
import * as Actions from '../actions'; |
||||
import { IStcsState, initialState } from '../model'; |
||||
|
||||
export const statisticsReducer = createReducer<IStcsState, Actions.StcsAction>( |
||||
initialState |
||||
) |
||||
// 비행 통계 (비행시간, 비행거리, 비행횟수)
|
||||
.handleAction(Actions.FLIGHT_STCS.success, (state, action) => |
||||
produce(state, draft => { |
||||
const data = action.payload; |
||||
draft.flight = data || state.flight; |
||||
}) |
||||
) |
||||
|
||||
// 비행 통계 카테고리별 검색
|
||||
.handleAction(Actions.FLIGHT_STCS_SEARCH.success, (state, action) => |
||||
produce(state, draft => { |
||||
const data = action.payload; |
||||
draft.flightSearch = data || state.flightSearch; |
||||
}) |
||||
); |
@ -0,0 +1,64 @@
|
||||
import { call, put, takeEvery } from '@redux-saga/core/effects'; |
||||
import * as MessageActions from '../../comn/message/actions/comnMessageAction'; |
||||
import * as Actions from '../actions'; |
||||
import * as Apis from '../apis'; |
||||
import { ActionType } from 'typesafe-actions'; |
||||
|
||||
function* flightStcsSaga( |
||||
action: ActionType<typeof Actions.FLIGHT_STCS.request> |
||||
) { |
||||
try { |
||||
const payload = action.payload; |
||||
const res = yield call(Apis.stcsAPI.flight); |
||||
const { data, errorCode } = res; |
||||
|
||||
if (errorCode) { |
||||
// 오류메시지 호출
|
||||
yield put( |
||||
MessageActions.IS_ERROR({ |
||||
errorCode: errorCode, |
||||
errorMessage: '처리중 오류가 발생하였습니다', |
||||
isHistoryBack: false, |
||||
isRefresh: false |
||||
}) |
||||
); |
||||
|
||||
return; |
||||
} |
||||
yield put(Actions.FLIGHT_STCS.success(data)); |
||||
} catch (error) { |
||||
yield put(Actions.FLIGHT_STCS.failure(error)); |
||||
} |
||||
} |
||||
|
||||
function* flightStcsSearchSaga( |
||||
action: ActionType<typeof Actions.FLIGHT_STCS_SEARCH.request> |
||||
) { |
||||
try { |
||||
const payload = action.payload; |
||||
const res = yield call(Apis.stcsAPI.flightSearch, payload); |
||||
const { data, errorCode } = res; |
||||
|
||||
if (errorCode) { |
||||
// 오류메시지 호출
|
||||
yield put( |
||||
MessageActions.IS_ERROR({ |
||||
errorCode: errorCode, |
||||
errorMessage: '처리중 오류가 발생하였습니다', |
||||
isHistoryBack: false, |
||||
isRefresh: false |
||||
}) |
||||
); |
||||
|
||||
return; |
||||
} |
||||
yield put(Actions.FLIGHT_STCS_SEARCH.success(data)); |
||||
} catch (error) { |
||||
yield put(Actions.FLIGHT_STCS_SEARCH.failure(error)); |
||||
} |
||||
} |
||||
|
||||
export function* statisticsSaga() { |
||||
yield takeEvery(Actions.FLIGHT_STCS.request, flightStcsSaga); |
||||
yield takeEvery(Actions.FLIGHT_STCS_SEARCH.request, flightStcsSearchSaga); |
||||
} |
Loading…
Reference in new issue