From 2d1338e0a75574751bc5845d451dafb8fb412065 Mon Sep 17 00:00:00 2001 From: insanity Date: Tue, 4 Jul 2017 18:14:16 +0900 Subject: [PATCH] TargetDiscoveryService.. --- .../redux/action/regist_discovered_target.ts | 44 +++++++++++++++++++ .../payload/RegistDiscoveredTargetPayload.ts | 9 ++++ .../redux/saga/regist_discovered_target.ts | 38 ++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/ts/@overflow/target/redux/action/regist_discovered_target.ts create mode 100644 src/ts/@overflow/target/redux/payload/RegistDiscoveredTargetPayload.ts create mode 100644 src/ts/@overflow/target/redux/saga/regist_discovered_target.ts diff --git a/src/ts/@overflow/target/redux/action/regist_discovered_target.ts b/src/ts/@overflow/target/redux/action/regist_discovered_target.ts new file mode 100644 index 0000000..e3a8b95 --- /dev/null +++ b/src/ts/@overflow/target/redux/action/regist_discovered_target.ts @@ -0,0 +1,44 @@ +import Action from '@overflow/commons/redux/Action'; +import Target from '../../api/model/Target'; +import RegistDiscoveredTargetPayload from '../payload/RegistDiscoveredTargetPayload'; +import Host from '@overflow/discovery/api/model/Host'; +import Probe from '@overflow/probe/api/model/Probe'; + +// Action Type +export type REQUEST = '@overflow/target/regist_discoved_target/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/target/regist_discoved_target/REQUEST_SUCCESS'; +export type REQUEST_FAILURE = '@overflow/target/regist_discoved_target/REQUEST_FAILURE'; + +export const REQUEST: REQUEST = '@overflow/target/regist_discoved_target/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/target/regist_discoved_target/REQUEST_SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/target/regist_discoved_target/REQUEST_FAILURE'; + +// Action Creater +export type request = (hosts: Host[], probe: Probe) => Action; +export type requestSuccess = () => Action; +export type requestFailure = (error: Error) => Action; + + + +export const request: request = (hosts: Host[], probe: Probe): Action => { + return { + type: REQUEST, + payload: { + hosts: hosts, + probe: probe, + }, + }; +}; + +export const requestSuccess: requestSuccess = (): Action => { + return { + type: REQUEST_SUCCESS, + }; +}; + +export const requestFailure: requestFailure = (error: Error): Action => { + return { + type: REQUEST_FAILURE, + error: error, + }; +}; diff --git a/src/ts/@overflow/target/redux/payload/RegistDiscoveredTargetPayload.ts b/src/ts/@overflow/target/redux/payload/RegistDiscoveredTargetPayload.ts new file mode 100644 index 0000000..0c85fa6 --- /dev/null +++ b/src/ts/@overflow/target/redux/payload/RegistDiscoveredTargetPayload.ts @@ -0,0 +1,9 @@ +import Host from '@overflow/discovery/api/model/Host'; +import Probe from '@overflow/probe/api/model/Probe'; + +interface RegistDiscoveredTargetPayload { + hosts: Host[]; + probe: Probe; +} + +export default RegistDiscoveredTargetPayload; diff --git a/src/ts/@overflow/target/redux/saga/regist_discovered_target.ts b/src/ts/@overflow/target/redux/saga/regist_discovered_target.ts new file mode 100644 index 0000000..6970d8d --- /dev/null +++ b/src/ts/@overflow/target/redux/saga/regist_discovered_target.ts @@ -0,0 +1,38 @@ +import { SagaIterator } from 'redux-saga'; +import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects'; + +import AppContext from '@overflow/commons/context'; +import Action from '@overflow/commons/redux/Action'; + +import Target from '../../api/model/Target'; +import TargetService from '../../api/service/TargetService'; +import * as RegistActions from '../action/regist'; +import RegistPayload from '../payload/RegistPayload'; + +function* registDiscoveredTarget(action: Action): SagaIterator { + try { + const {target} = action.payload; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + + const retTarget = yield call(AppContext.getService().regist, target); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(RegistActions.requestSuccess(retTarget)); + } catch (e) { + yield put(RegistActions.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchRegist(): SagaIterator { + yield takeLatest(RegistActions.REQUEST, regist); +}