Browse Source

비행 실적 api 작성

pull/2/head
hhjk00 10 months ago
parent
commit
0672a547b1
  1. 34
      src/modules/statistics/actions/index.ts
  2. 26
      src/modules/statistics/apis/index.ts
  3. 37
      src/modules/statistics/models/index.ts
  4. 16
      src/modules/statistics/reducers/index.ts
  5. 60
      src/modules/statistics/sagas/index.ts

34
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
)<null, Flight, AxiosError>();
)<null, IStcsRs[], AxiosError>();
export const FLIGHT_STCS_SEARCH = createAsyncAction(
FLIGHT_STCS_SEARCH_REQUEST,
FLIGHT_STCS_SEARCH_SUCCESS,
FLIGHT_STCS_SEARCH_FAILURE
)<FlightSearchRq, FlightSearch, AxiosError>();
)<IStcsSearchRq, IStcsSearchRs, AxiosError>();
export const RESULT_STCS = createAsyncAction(
RESULT_STCS_REQUEST,
RESULT_STCS_SUCCESS,
RESULT_STCS_FAILURE
)<null, IStcsRs[], AxiosError>();
export const RESULT_STCS_SEARCH = createAsyncAction(
RESULT_STCS_SEARCH_REQUEST,
RESULT_STCS_SEARCH_SUCCESS,
RESULT_STCS_SEARCH_FAILURE
)<IStcsSearchRq, IStcsSearchRs, AxiosError>();
const actions = {
FLIGHT_STCS,
FLIGHT_STCS_SEARCH
FLIGHT_STCS_SEARCH,
RESULT_STCS,
RESULT_STCS_SEARCH
};
export type StatisticsAction = ActionType<typeof actions>;

26
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}`
);
}
};

37
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: {
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: []
}
},
result: [],
resultSearch: {
graphData: [],
topData: []
}
};

16
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;
})
);

60
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<typeof Actions.RESULT_STCS.request>
) {
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<typeof Actions.RESULT_STCS_SEARCH.request>
) {
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);
}

Loading…
Cancel
Save