From 6c31de500dc009ca8c60acba4db773708e3220c5 Mon Sep 17 00:00:00 2001 From: geek Date: Tue, 4 Jul 2017 16:14:21 +0900 Subject: [PATCH] member redux push --- .../member/api/service/MemberService.ts | 3 ++ .../@overflow/member/redux/action/modify.ts | 44 +++++++++++++++++-- src/ts/@overflow/member/redux/action/read.ts | 44 +++++++++++++++++-- .../member/redux/payload/ModifyPayload.ts | 9 ++-- .../member/redux/payload/ReadPayload.ts | 8 ++-- src/ts/@overflow/member/redux/saga/modify.ts | 42 ++++++++++++++++-- src/ts/@overflow/member/redux/saga/read.ts | 42 ++++++++++++++++-- 7 files changed, 174 insertions(+), 18 deletions(-) diff --git a/src/ts/@overflow/member/api/service/MemberService.ts b/src/ts/@overflow/member/api/service/MemberService.ts index 7d9f71f..0a20dbc 100644 --- a/src/ts/@overflow/member/api/service/MemberService.ts +++ b/src/ts/@overflow/member/api/service/MemberService.ts @@ -36,6 +36,9 @@ export class MemberService extends Service { return null; } + public modify(member: Member): Member { + return null; + } } export default MemberService; diff --git a/src/ts/@overflow/member/redux/action/modify.ts b/src/ts/@overflow/member/redux/action/modify.ts index 5c15c15..e5a70d9 100644 --- a/src/ts/@overflow/member/redux/action/modify.ts +++ b/src/ts/@overflow/member/redux/action/modify.ts @@ -1,3 +1,41 @@ -/** - * Created by geek on 17. 7. 3. - */ +import Action from '@overflow/commons/redux/Action'; +import Member from '@overflow/member/api/model/Member'; + +import ModifyPayload from '../payload/ModifyPayload'; + +// Action Type +export type REQUEST = '@overflow/member/modify/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/member/modify/REQUEST_SUCCESS'; +export type REQUEST_FAILURE = '@overflow/member/modify/REQUEST_FAILURE'; + +export const REQUEST: REQUEST = '@overflow/member/modify/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/member/modify/REQUEST_SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/member/modify/REQUEST_FAILURE'; + +// Action Creater +export type request = (member: Member) => Action; +export type requestSuccess = (member: Member) => Action; +export type requestFailure = (error: Error) => Action; + +export const request: request = (member: Member): Action => { + return { + type: REQUEST, + payload: { + member: member, + }, + }; +}; + +export const requestSuccess: requestSuccess = (member: Member): Action => { + return { + type: REQUEST_SUCCESS, + payload: member, + }; +}; + +export const requestFailure: requestFailure = (error: Error): Action => { + return { + type: REQUEST_FAILURE, + error: error, + }; +}; diff --git a/src/ts/@overflow/member/redux/action/read.ts b/src/ts/@overflow/member/redux/action/read.ts index 5c15c15..e6ede60 100644 --- a/src/ts/@overflow/member/redux/action/read.ts +++ b/src/ts/@overflow/member/redux/action/read.ts @@ -1,3 +1,41 @@ -/** - * Created by geek on 17. 7. 3. - */ +import Action from '@overflow/commons/redux/Action'; +import Member from '@overflow/member/api/model/Member'; + +import ReadPayload from '../payload/ReadPayload'; + +// Action Type +export type REQUEST = '@overflow/member/read/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/member/read/REQUEST_SUCCESS'; +export type REQUEST_FAILURE = '@overflow/member/read/REQUEST_FAILURE'; + +export const REQUEST: REQUEST = '@overflow/member/read/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/member/read/REQUEST_SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/member/read/REQUEST_FAILURE'; + +// Action Creater +export type request = (id: number) => Action; +export type requestSuccess = (member: Member) => Action; +export type requestFailure = (error: Error) => Action; + +export const request: request = (id: number): Action => { + return { + type: REQUEST, + payload: { + id: id, + }, + }; +}; + +export const requestSuccess: requestSuccess = (member: Member): Action => { + return { + type: REQUEST_SUCCESS, + payload: member, + }; +}; + +export const requestFailure: requestFailure = (error: Error): Action => { + return { + type: REQUEST_FAILURE, + error: error, + }; +}; diff --git a/src/ts/@overflow/member/redux/payload/ModifyPayload.ts b/src/ts/@overflow/member/redux/payload/ModifyPayload.ts index 5c15c15..e237815 100644 --- a/src/ts/@overflow/member/redux/payload/ModifyPayload.ts +++ b/src/ts/@overflow/member/redux/payload/ModifyPayload.ts @@ -1,3 +1,6 @@ -/** - * Created by geek on 17. 7. 3. - */ +import Member from '../../api/model/Member'; +interface ModifyPayload { + member: Member; +} + +export default ModifyPayload; diff --git a/src/ts/@overflow/member/redux/payload/ReadPayload.ts b/src/ts/@overflow/member/redux/payload/ReadPayload.ts index 5c15c15..dc4df99 100644 --- a/src/ts/@overflow/member/redux/payload/ReadPayload.ts +++ b/src/ts/@overflow/member/redux/payload/ReadPayload.ts @@ -1,3 +1,5 @@ -/** - * Created by geek on 17. 7. 3. - */ +interface ReadPayload { + id: number; +} + +export default ReadPayload; diff --git a/src/ts/@overflow/member/redux/saga/modify.ts b/src/ts/@overflow/member/redux/saga/modify.ts index 5c15c15..1905bb4 100644 --- a/src/ts/@overflow/member/redux/saga/modify.ts +++ b/src/ts/@overflow/member/redux/saga/modify.ts @@ -1,3 +1,39 @@ -/** - * Created by geek on 17. 7. 3. - */ +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 Member from '../../api/model/Member'; +import MemberService from '../../api/service/MemberService'; +import * as ModifyActions from '../action/modify'; +import ModifyPayload from '../payload/ModifyPayload'; + +function* modify(action: Action): SagaIterator { + try { + const tempMember = action.payload.member; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + + const member = yield call(AppContext.getService().modify, tempMember); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(ModifyActions.requestSuccess(member)); + } catch (e) { + yield put(ModifyActions.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchMemberModify(): SagaIterator { + yield takeLatest(ModifyActions.REQUEST, modify); +} diff --git a/src/ts/@overflow/member/redux/saga/read.ts b/src/ts/@overflow/member/redux/saga/read.ts index 5c15c15..c81ddd3 100644 --- a/src/ts/@overflow/member/redux/saga/read.ts +++ b/src/ts/@overflow/member/redux/saga/read.ts @@ -1,3 +1,39 @@ -/** - * Created by geek on 17. 7. 3. - */ +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 Member from '../../api/model/Member'; +import MemberService from '../../api/service/MemberService'; +import * as ReadActions from '../action/read'; +import ReadPayload from '../payload/ReadPayload'; + +function* read(action: Action): SagaIterator { + try { + const id = action.payload.id; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + + const member = yield call(AppContext.getService().read, id); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(ReadActions.requestSuccess(member)); + } catch (e) { + yield put(ReadActions.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchMemberRead(): SagaIterator { + yield takeLatest(ReadActions.REQUEST, read); +}