From 0acc9791dc9bcfe5db48ee4bb481af9e4294a563 Mon Sep 17 00:00:00 2001 From: snoop Date: Fri, 28 Jul 2017 18:35:24 +0900 Subject: [PATCH] add sensor list --- .../sensor/api/service/SensorService.ts | 10 +++++ .../redux/reducer/read_all_by_target.ts | 25 ++++++++++++ .../sensor/redux/reducer/read_by_target.ts | 3 -- .../sensor/redux/saga/read_all_by_domain.ts | 38 +++++++++++++++++++ .../sensor/redux/saga/read_all_by_probe.ts | 0 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/ts/@overflow/sensor/redux/reducer/read_all_by_target.ts delete mode 100644 src/ts/@overflow/sensor/redux/reducer/read_by_target.ts create mode 100644 src/ts/@overflow/sensor/redux/saga/read_all_by_domain.ts create mode 100644 src/ts/@overflow/sensor/redux/saga/read_all_by_probe.ts diff --git a/src/ts/@overflow/sensor/api/service/SensorService.ts b/src/ts/@overflow/sensor/api/service/SensorService.ts index 47906c6..f77727c 100644 --- a/src/ts/@overflow/sensor/api/service/SensorService.ts +++ b/src/ts/@overflow/sensor/api/service/SensorService.ts @@ -2,6 +2,8 @@ import Service from '@overflow/commons/api/Service'; import Sensor from '../model/Sensor'; import Target from '@overflow/target/api/model/Target'; +import Probe from '@overflow/probe/api/model/Probe'; +import Domain from '@overflow/domain/api/model/Domain'; export class SensorService extends Service { @@ -17,6 +19,14 @@ export class SensorService extends Service { return null; } + public readAllByProbe(probe: Probe): Promise { + return null; + } + + public readAllByDomain(domain: Domain): Promise { + return null; + } + public read(id:number): Promise { return null; } diff --git a/src/ts/@overflow/sensor/redux/reducer/read_all_by_target.ts b/src/ts/@overflow/sensor/redux/reducer/read_all_by_target.ts new file mode 100644 index 0000000..1ccd143 --- /dev/null +++ b/src/ts/@overflow/sensor/redux/reducer/read_all_by_target.ts @@ -0,0 +1,25 @@ +/** + * Created by geek on 17. 7. 3. + */ + +import Action from '@overflow/commons/redux/Action'; +import { ReducersMapObject } from 'redux'; +import Target from '@overflow/target/api/model/Target'; + +import * as ReadAllByDomainActionTypes from '../action/read_all_by_domain'; +import ReadAllByTargetState, { defaultState as readAllByTargetDefaultState } from '../state/ReadAllByTarget'; + +const reducer: ReducersMapObject = { + [ReadAllByDomainActionTypes.REQUEST_SUCCESS]: + (state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action): + ReadAllByTargetState => { + return state; + }, + [ReadAllByDomainActionTypes.REQUEST_FAILURE]: + (state: ReadAllByTargetState = readAllByTargetDefaultState, action: Action): + ReadAllByTargetState => { + return state; + }, +}; + +export default reducer; diff --git a/src/ts/@overflow/sensor/redux/reducer/read_by_target.ts b/src/ts/@overflow/sensor/redux/reducer/read_by_target.ts deleted file mode 100644 index 5c15c15..0000000 --- a/src/ts/@overflow/sensor/redux/reducer/read_by_target.ts +++ /dev/null @@ -1,3 +0,0 @@ -/** - * Created by geek on 17. 7. 3. - */ diff --git a/src/ts/@overflow/sensor/redux/saga/read_all_by_domain.ts b/src/ts/@overflow/sensor/redux/saga/read_all_by_domain.ts new file mode 100644 index 0000000..0586c5e --- /dev/null +++ b/src/ts/@overflow/sensor/redux/saga/read_all_by_domain.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/AppContext'; +import Action from '@overflow/commons/redux/Action'; + +import Sensor from '../../api/model/Sensor'; +import SensorService from '../../api/service/SensorService'; +import * as ReadAllByDomainActions from '../action/read_all_by_domain'; +import ReadAllByDomainPayload from '../payload/ReadAllByDomainPayload'; + +function* readAllByDomain(action: Action): SagaIterator { + try { + const {domain} = action.payload; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + let sensorService = AppContext.getInstance().getPouch(SensorService); + const ret = yield call({context: sensorService, fn: sensorService.readAllByDomain}, domain); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(ReadAllByDomainActions.requestSuccess(ret)); + } catch (e) { + yield put(ReadAllByDomainActions.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchReadAllByTarget(): SagaIterator { + yield takeLatest(ReadAllByDomainActions.REQUEST, readAllByDomain); +} diff --git a/src/ts/@overflow/sensor/redux/saga/read_all_by_probe.ts b/src/ts/@overflow/sensor/redux/saga/read_all_by_probe.ts new file mode 100644 index 0000000..e69de29