From ba2037bad53801bcf7d4e3eb8933994122278e5f Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 4 Jul 2017 12:37:34 +0900 Subject: [PATCH] added apikey --- .../apikey/api/service/ApiKeyService.ts | 2 +- .../@overflow/apikey/redux/action/regist.ts | 27 ++++++++++++- .../apikey/redux/payload/RegistPayload.ts | 5 ++- src/ts/@overflow/apikey/redux/saga/regist.ts | 39 +++++++++++++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/ts/@overflow/apikey/api/service/ApiKeyService.ts b/src/ts/@overflow/apikey/api/service/ApiKeyService.ts index f833ba8..133ec42 100644 --- a/src/ts/@overflow/apikey/api/service/ApiKeyService.ts +++ b/src/ts/@overflow/apikey/api/service/ApiKeyService.ts @@ -7,7 +7,7 @@ class ApiKeyService extends Service { super('ApiKeyService'); } - public regist(apikey: ApiKey): void { + public regist(apikey: ApiKey): ApiKey { return null; } diff --git a/src/ts/@overflow/apikey/redux/action/regist.ts b/src/ts/@overflow/apikey/redux/action/regist.ts index 04e2220..cc5faf9 100644 --- a/src/ts/@overflow/apikey/redux/action/regist.ts +++ b/src/ts/@overflow/apikey/redux/action/regist.ts @@ -13,6 +13,31 @@ export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/apikey/regist/REQUEST export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/apikey/regist/REQUEST_FAILURE'; // Action Creater -export type request = () => Action; +export type request = (ApiKey: ApiKey) => Action; export type requestSuccess = (apiKey: ApiKey) => Action; export type requestFailure = (error: Error) => Action; + + + +export const request: request = (apiKey: ApiKey): Action => { + return { + type: REQUEST, + payload: { + apiKey:apiKey, + }, + }; +}; + +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/RegistPayload.ts b/src/ts/@overflow/apikey/redux/payload/RegistPayload.ts index cad8bb3..8dce773 100644 --- a/src/ts/@overflow/apikey/redux/payload/RegistPayload.ts +++ b/src/ts/@overflow/apikey/redux/payload/RegistPayload.ts @@ -1,6 +1,7 @@ +import ApiKey from '../../api/model/ApiKey'; + interface RegistPayload { - signinId: string; - signinPw: string; + apiKey: ApiKey; } export default RegistPayload; diff --git a/src/ts/@overflow/apikey/redux/saga/regist.ts b/src/ts/@overflow/apikey/redux/saga/regist.ts index e69de29..33fec61 100644 --- a/src/ts/@overflow/apikey/redux/saga/regist.ts +++ b/src/ts/@overflow/apikey/redux/saga/regist.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 RegistActions from '../action/regist'; +import RegistPayload from '../payload/RegistPayload'; + +function* regist(action: Action): SagaIterator { + try { + const {apiKey} = action.payload; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + + const retApikey = yield call(AppContext.getService().regist, apiKey); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(RegistActions.requestSuccess(retApikey)); + } catch (e) { + yield put(RegistActions.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchSignin(): SagaIterator { + yield takeLatest(RegistActions.REQUEST, regist); +}