added apikey read

This commit is contained in:
snoop 2017-07-04 14:33:39 +09:00
parent cfa89c9948
commit 451c169ae6
4 changed files with 97 additions and 0 deletions

View File

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

View File

@ -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<ReadPayload>;
export type requestSuccess = (apiKey: ApiKey) => Action<ApiKey>;
export type requestFailure = (error: Error) => Action;
export const request: request = (domain: Domain): Action<ReadPayload> => {
return {
type: REQUEST,
payload: {
domain:domain,
},
};
};
export const requestSuccess: requestSuccess = (apiKey: ApiKey): Action<ApiKey> => {
return {
type: REQUEST_SUCCESS,
payload: apiKey,
};
};
export const requestFailure: requestFailure = (error: Error): Action => {
return {
type: REQUEST_FAILURE,
error: error,
};
};

View File

@ -0,0 +1,9 @@
import Domain from '@overflow/domain/api/model/Domain';
interface ReadPayload {
domain: Domain;
}
export default ReadPayload;

View File

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