TargetDiscoveryService..

This commit is contained in:
insanity 2017-07-04 18:14:16 +09:00
parent f3025d59cc
commit 2d1338e0a7
3 changed files with 91 additions and 0 deletions

View File

@ -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<RegistDiscoveredTargetPayload>;
export type requestSuccess = () => Action<void>;
export type requestFailure = (error: Error) => Action;
export const request: request = (hosts: Host[], probe: Probe): Action<RegistDiscoveredTargetPayload> => {
return {
type: REQUEST,
payload: {
hosts: hosts,
probe: probe,
},
};
};
export const requestSuccess: requestSuccess = (): Action<void> => {
return {
type: REQUEST_SUCCESS,
};
};
export const requestFailure: requestFailure = (error: Error): Action => {
return {
type: REQUEST_FAILURE,
error: error,
};
};

View File

@ -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;

View File

@ -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<RegistPayload>): SagaIterator {
try {
const {target} = action.payload;
// yield put({
// type: types.SENDING_REQUEST,
// payload: {sendingRequest: true},
// });
const retTarget = yield call(AppContext.getService<TargetService>().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);
}