From 451c169ae68c59a82a32adda110e55ef5e360b28 Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 4 Jul 2017 14:33:39 +0900 Subject: [PATCH] added apikey read --- .../apikey/api/service/ApiKeyService.ts | 5 +++ src/ts/@overflow/apikey/redux/action/read.ts | 44 +++++++++++++++++++ .../apikey/redux/payload/ReadPayload.ts | 9 ++++ src/ts/@overflow/apikey/redux/saga/read.ts | 39 ++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/ts/@overflow/apikey/redux/action/read.ts create mode 100644 src/ts/@overflow/apikey/redux/payload/ReadPayload.ts create mode 100644 src/ts/@overflow/apikey/redux/saga/read.ts diff --git a/src/ts/@overflow/apikey/api/service/ApiKeyService.ts b/src/ts/@overflow/apikey/api/service/ApiKeyService.ts index 133ec42..f86bb71 100644 --- a/src/ts/@overflow/apikey/api/service/ApiKeyService.ts +++ b/src/ts/@overflow/apikey/api/service/ApiKeyService.ts @@ -1,5 +1,6 @@ import Service from '@overflow/commons/api/Service'; import ApiKey from '../model/ApiKey'; +import Domain from '@overflow/domain/api/model/Domain'; class ApiKeyService extends Service { @@ -12,6 +13,10 @@ class ApiKeyService extends Service { return null; } + public read(domain: Domain): ApiKey { + return null; + } + } diff --git a/src/ts/@overflow/apikey/redux/action/read.ts b/src/ts/@overflow/apikey/redux/action/read.ts new file mode 100644 index 0000000..5af6077 --- /dev/null +++ b/src/ts/@overflow/apikey/redux/action/read.ts @@ -0,0 +1,44 @@ +import Action from '@overflow/commons/redux/Action'; +import ApiKey from '../..//api/model/ApiKey'; +import Domain from '@overflow/domain/api/model/Domain'; + +import ReadPayload from '../payload/ReadPayload'; + +// Action Type +export type REQUEST = '@overflow/apikey/read/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/apikey/read/REQUEST_SUCCESS'; +export type REQUEST_FAILURE = '@overflow/apikey/read/REQUEST_FAILURE'; + +export const REQUEST: REQUEST = '@overflow/apikey/read/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/apikey/read/REQUEST_SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/apikey/read/REQUEST_FAILURE'; + +// Action Creater +export type request = (domain: Domain) => Action; +export type requestSuccess = (apiKey: ApiKey) => Action; +export type requestFailure = (error: Error) => Action; + + + +export const request: request = (domain: Domain): Action => { + return { + type: REQUEST, + payload: { + domain:domain, + }, + }; +}; + +export const requestSuccess: requestSuccess = (apiKey: ApiKey): Action => { + return { + type: REQUEST_SUCCESS, + payload: apiKey, + }; +}; + +export const requestFailure: requestFailure = (error: Error): Action => { + return { + type: REQUEST_FAILURE, + error: error, + }; +}; diff --git a/src/ts/@overflow/apikey/redux/payload/ReadPayload.ts b/src/ts/@overflow/apikey/redux/payload/ReadPayload.ts new file mode 100644 index 0000000..d42cc5d --- /dev/null +++ b/src/ts/@overflow/apikey/redux/payload/ReadPayload.ts @@ -0,0 +1,9 @@ + +import Domain from '@overflow/domain/api/model/Domain'; + +interface ReadPayload { + domain: Domain; +} + +export default ReadPayload; + diff --git a/src/ts/@overflow/apikey/redux/saga/read.ts b/src/ts/@overflow/apikey/redux/saga/read.ts new file mode 100644 index 0000000..3d1ecb9 --- /dev/null +++ b/src/ts/@overflow/apikey/redux/saga/read.ts @@ -0,0 +1,39 @@ +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 ApiKey from '../../api/model/ApiKey'; +import ApiKeyService from '../../api/service/ApiKeyService'; +import * as ReadActions from '../action/read'; +import ReadPayload from '../payload/ReadPayload'; + +function* read(action: Action): SagaIterator { + try { + const {domain} = action.payload; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + + const retApikey = yield call(AppContext.getService().read, domain); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(ReadActions.requestSuccess(retApikey)); + } catch (e) { + yield put(ReadActions.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchSignin(): SagaIterator { + yield takeLatest(ReadActions.REQUEST, read); +}