From 695acac19d9b29bea6362badff27812e9c9332f3 Mon Sep 17 00:00:00 2001 From: geek Date: Tue, 4 Jul 2017 16:00:51 +0900 Subject: [PATCH] email redux push --- src/ts/@overflow/email/redux/action/modify.ts | 42 +++++++++++++++++ src/ts/@overflow/email/redux/action/read.ts | 45 +++++++++++++++++-- .../email/redux/action/read_by_auth_key.ts | 44 ++++++++++++++++-- .../email/redux/action/read_by_member.ts | 44 ++++++++++++++++-- .../redux/action/send_email_by_member.ts | 43 ++++++++++++++++++ .../email/redux/payload/ModifyPayload.ts | 10 +++-- .../redux/payload/ReadByAuthKeyPayload.ts | 8 ++-- .../redux/payload/ReadByMemberPayload.ts | 8 ++-- .../email/redux/payload/ReadPayload.ts | 6 +++ .../redux/payload/SendEmailByMemberPayload.ts | 6 +++ src/ts/@overflow/email/redux/saga/modify.ts | 41 +++++++++++++++++ src/ts/@overflow/email/redux/saga/read.ts | 43 ++++++++++++++++-- .../email/redux/saga/read_by_auth_key.ts | 43 ++++++++++++++++-- .../email/redux/saga/read_by_member.ts | 43 ++++++++++++++++-- .../email/redux/saga/send_email_by_member.ts | 40 +++++++++++++++++ 15 files changed, 439 insertions(+), 27 deletions(-) diff --git a/src/ts/@overflow/email/redux/action/modify.ts b/src/ts/@overflow/email/redux/action/modify.ts index 4062be4..55c322d 100644 --- a/src/ts/@overflow/email/redux/action/modify.ts +++ b/src/ts/@overflow/email/redux/action/modify.ts @@ -1,3 +1,45 @@ /** * Created by geek on 17. 7. 4. */ +import Action from '@overflow/commons/redux/Action'; +import EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import ModifyPayload from '../payload/ModifyPayload'; + +// Action Type +export type REQUEST = '@overflow/email/modify/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/email/modify/REQUEST_SUCCESS'; +export type REQUEST_FAILURE = '@overflow/email/modify/REQUEST_FAILURE'; + +export const REQUEST: REQUEST = '@overflow/email/modify/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/email/modify/REQUEST_SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/email/modify/REQUEST_FAILURE'; + +// Action Creater +export type request = (emailAuth:EmailAuth) => Action; +export type requestSuccess = (emailAuth: EmailAuth) => Action; +export type requestFailure = (error: Error) => Action; + +export const request: request = (emailAuth:EmailAuth): Action => { + return { + type: REQUEST, + payload: { + emailAuth: emailAuth, + }, + }; +}; + +export const requestSuccess: requestSuccess = (emailAuth: EmailAuth): Action => { + return { + type: REQUEST_SUCCESS, + payload: emailAuth, + }; +}; + +export const requestFailure: requestFailure = (error: Error): Action => { + return { + type: REQUEST_FAILURE, + error: error, + }; +}; + diff --git a/src/ts/@overflow/email/redux/action/read.ts b/src/ts/@overflow/email/redux/action/read.ts index 4062be4..6eb24ff 100644 --- a/src/ts/@overflow/email/redux/action/read.ts +++ b/src/ts/@overflow/email/redux/action/read.ts @@ -1,3 +1,42 @@ -/** - * Created by geek on 17. 7. 4. - */ +import Action from '@overflow/commons/redux/Action'; +import EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import ReadPayload from '../payload/ReadPayload'; + +// Action Type +export type REQUEST = '@overflow/email/read/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/email/read/REQUEST_SUCCESS'; +export type REQUEST_FAILURE = '@overflow/email/read/REQUEST_FAILURE'; + +export const REQUEST: REQUEST = '@overflow/email/read/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/email/read/REQUEST_SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/email/read/REQUEST_FAILURE'; + +// Action Creater +export type request = (id: number) => Action; +export type requestSuccess = (emailAuth: EmailAuth) => Action; +export type requestFailure = (error: Error) => Action; + +export const request: request = (id: number): Action => { + return { + type: REQUEST, + payload: { + id: id, + }, + }; +}; + +export const requestSuccess: requestSuccess = (emailAuth: EmailAuth): Action => { + return { + type: REQUEST_SUCCESS, + payload: emailAuth, + }; +}; + +export const requestFailure: requestFailure = (error: Error): Action => { + return { + type: REQUEST_FAILURE, + error: error, + }; +}; + diff --git a/src/ts/@overflow/email/redux/action/read_by_auth_key.ts b/src/ts/@overflow/email/redux/action/read_by_auth_key.ts index 4062be4..732d805 100644 --- a/src/ts/@overflow/email/redux/action/read_by_auth_key.ts +++ b/src/ts/@overflow/email/redux/action/read_by_auth_key.ts @@ -1,3 +1,41 @@ -/** - * Created by geek on 17. 7. 4. - */ +import Action from '@overflow/commons/redux/Action'; +import EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import ReadByAuthKeyPayload from '../payload/ReadByAuthKeyPayload'; + +// Action Type +export type REQUEST = '@overflow/email/read_by_auth_key/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/email/read_by_auth_key/REQUEST_SUCCESS'; +export type REQUEST_FAILURE = '@overflow/email/read_by_auth_key/REQUEST_FAILURE'; + +export const REQUEST: REQUEST = '@overflow/email/read_by_auth_key/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/email/read_by_auth_key/REQUEST_SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/email/read_by_auth_key/REQUEST_FAILURE'; + +// Action Creater +export type request = (authKey: string) => Action; +export type requestSuccess = (emailAuth: EmailAuth) => Action; +export type requestFailure = (error: Error) => Action; + +export const request: request = (authKey: string): Action => { + return { + type: REQUEST, + payload: { + authKey: authKey, + }, + }; +}; + +export const requestSuccess: requestSuccess = (emailAuth: EmailAuth): Action => { + return { + type: REQUEST_SUCCESS, + payload: emailAuth, + }; +}; + +export const requestFailure: requestFailure = (error: Error): Action => { + return { + type: REQUEST_FAILURE, + error: error, + }; +}; diff --git a/src/ts/@overflow/email/redux/action/read_by_member.ts b/src/ts/@overflow/email/redux/action/read_by_member.ts index 4062be4..005823f 100644 --- a/src/ts/@overflow/email/redux/action/read_by_member.ts +++ b/src/ts/@overflow/email/redux/action/read_by_member.ts @@ -1,3 +1,41 @@ -/** - * Created by geek on 17. 7. 4. - */ +import Action from '@overflow/commons/redux/Action'; +import EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import ReadByMemberPayload from '../payload/ReadByMemberPayload'; + +// Action Type +export type REQUEST = '@overflow/email/read_by_member/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/email/read_by_member/REQUEST_SUCCESS'; +export type REQUEST_FAILURE = '@overflow/email/read_by_member/REQUEST_FAILURE'; + +export const REQUEST: REQUEST = '@overflow/email/read_by_member/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/email/read_by_member/REQUEST_SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/email/read_by_member/REQUEST_FAILURE'; + +// Action Creater +export type request = (memberId: number) => Action; +export type requestSuccess = (emailAuths: EmailAuth[]) => Action; +export type requestFailure = (error: Error) => Action; + +export const request: request = (memberId: number): Action => { + return { + type: REQUEST, + payload: { + memberId: memberId, + }, + }; +}; + +export const requestSuccess: requestSuccess = (emailAuths: EmailAuth[]): Action => { + return { + type: REQUEST_SUCCESS, + payload: emailAuths, + }; +}; + +export const requestFailure: requestFailure = (error: Error): Action => { + return { + type: REQUEST_FAILURE, + error: error, + }; +}; diff --git a/src/ts/@overflow/email/redux/action/send_email_by_member.ts b/src/ts/@overflow/email/redux/action/send_email_by_member.ts index e69de29..3719ef7 100644 --- a/src/ts/@overflow/email/redux/action/send_email_by_member.ts +++ b/src/ts/@overflow/email/redux/action/send_email_by_member.ts @@ -0,0 +1,43 @@ +import Action from '@overflow/commons/redux/Action'; +import EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import SendEmailPayload from '../payload/SendEmailByMemberPayload'; + +// Action Type +export type REQUEST = '@overflow/email/send_email_by_member/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/email/send_email_by_member/REQUEST_SUCCESS'; +export type REQUEST_FAILURE = '@overflow/email/send_email_by_member/REQUEST_FAILURE'; + +export const REQUEST: REQUEST = '@overflow/email/send_email_by_member/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/email/send_email_by_member/REQUEST_SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/email/send_email_by_member/REQUEST_FAILURE'; + +// Action Creater +export type request = (memberId: number, email: string) => Action; +export type requestSuccess = (emailAuth: EmailAuth) => Action; +export type requestFailure = (error: Error) => Action; + +export const request: request = (memberId: number, email: string): Action => { + return { + type: REQUEST, + payload: { + memberId: memberId, + email: email, + }, + }; +}; + +export const requestSuccess: requestSuccess = (emailAuth: EmailAuth): Action => { + return { + type: REQUEST_SUCCESS, + payload: emailAuth, + }; +}; + +export const requestFailure: requestFailure = (error: Error): Action => { + return { + type: REQUEST_FAILURE, + error: error, + }; +}; + diff --git a/src/ts/@overflow/email/redux/payload/ModifyPayload.ts b/src/ts/@overflow/email/redux/payload/ModifyPayload.ts index 4062be4..abb9ca2 100644 --- a/src/ts/@overflow/email/redux/payload/ModifyPayload.ts +++ b/src/ts/@overflow/email/redux/payload/ModifyPayload.ts @@ -1,3 +1,7 @@ -/** - * Created by geek on 17. 7. 4. - */ +import EmailAuth from '../../api/model/EmailAuth'; + +interface ModifyPayload { + emailAuth: EmailAuth; +} + +export default ModifyPayload; diff --git a/src/ts/@overflow/email/redux/payload/ReadByAuthKeyPayload.ts b/src/ts/@overflow/email/redux/payload/ReadByAuthKeyPayload.ts index 4062be4..0d0c644 100644 --- a/src/ts/@overflow/email/redux/payload/ReadByAuthKeyPayload.ts +++ b/src/ts/@overflow/email/redux/payload/ReadByAuthKeyPayload.ts @@ -1,3 +1,5 @@ -/** - * Created by geek on 17. 7. 4. - */ +interface ReadByAuthKeyPayload { + authKey: string; +} + +export default ReadByAuthKeyPayload; diff --git a/src/ts/@overflow/email/redux/payload/ReadByMemberPayload.ts b/src/ts/@overflow/email/redux/payload/ReadByMemberPayload.ts index 4062be4..31a436b 100644 --- a/src/ts/@overflow/email/redux/payload/ReadByMemberPayload.ts +++ b/src/ts/@overflow/email/redux/payload/ReadByMemberPayload.ts @@ -1,3 +1,5 @@ -/** - * Created by geek on 17. 7. 4. - */ +interface ReadByMemberPayload { + memberId: number; +} + +export default ReadByMemberPayload; diff --git a/src/ts/@overflow/email/redux/payload/ReadPayload.ts b/src/ts/@overflow/email/redux/payload/ReadPayload.ts index 4062be4..ea66cb2 100644 --- a/src/ts/@overflow/email/redux/payload/ReadPayload.ts +++ b/src/ts/@overflow/email/redux/payload/ReadPayload.ts @@ -1,3 +1,9 @@ /** * Created by geek on 17. 7. 4. */ + +interface ReadPayload { + id: number; +} + +export default ReadPayload; diff --git a/src/ts/@overflow/email/redux/payload/SendEmailByMemberPayload.ts b/src/ts/@overflow/email/redux/payload/SendEmailByMemberPayload.ts index e69de29..fe8af1b 100644 --- a/src/ts/@overflow/email/redux/payload/SendEmailByMemberPayload.ts +++ b/src/ts/@overflow/email/redux/payload/SendEmailByMemberPayload.ts @@ -0,0 +1,6 @@ +interface SendEmailByMemberPayload { + memberId: number; + email: string; +} + +export default SendEmailByMemberPayload; diff --git a/src/ts/@overflow/email/redux/saga/modify.ts b/src/ts/@overflow/email/redux/saga/modify.ts index 4062be4..3d7bc05 100644 --- a/src/ts/@overflow/email/redux/saga/modify.ts +++ b/src/ts/@overflow/email/redux/saga/modify.ts @@ -1,3 +1,44 @@ /** * Created by geek on 17. 7. 4. */ + +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 EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import EmailAuthService from '@overflow/email/api/service/EmailAuthService'; +import * as ModifyAction from '../action/modify'; +import ModifyPayload from '../payload/ModifyPayload'; + +function* modify(action: Action): SagaIterator { + try { + const ea = action.payload.emailAuth; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + + const emailAuth = yield call(AppContext.getService().modify, ea); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(ModifyAction.requestSuccess(emailAuth)); + } catch (e) { + yield put(ModifyAction.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchEmailModify(): SagaIterator { + yield takeLatest(ModifyAction.REQUEST, modify); +} diff --git a/src/ts/@overflow/email/redux/saga/read.ts b/src/ts/@overflow/email/redux/saga/read.ts index 4062be4..9efad75 100644 --- a/src/ts/@overflow/email/redux/saga/read.ts +++ b/src/ts/@overflow/email/redux/saga/read.ts @@ -1,3 +1,40 @@ -/** - * Created by geek on 17. 7. 4. - */ +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 EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import EmailAuthService from '@overflow/email/api/service/EmailAuthService'; +import * as ReadAction 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 emailAuth = yield call(AppContext.getService().read, id); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(ReadAction.requestSuccess(emailAuth)); + } catch (e) { + yield put(ReadAction.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchEmailRead(): SagaIterator { + yield takeLatest(ReadAction.REQUEST, read); +} diff --git a/src/ts/@overflow/email/redux/saga/read_by_auth_key.ts b/src/ts/@overflow/email/redux/saga/read_by_auth_key.ts index 4062be4..aaaef5b 100644 --- a/src/ts/@overflow/email/redux/saga/read_by_auth_key.ts +++ b/src/ts/@overflow/email/redux/saga/read_by_auth_key.ts @@ -1,3 +1,40 @@ -/** - * Created by geek on 17. 7. 4. - */ +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 EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import EmailAuthService from '@overflow/email/api/service/EmailAuthService'; +import * as ReadByAuthKeyAction from '../action/read_by_auth_key'; +import ReadByAuthKeyPayload from '../payload/ReadByAuthKeyPayload'; + +function* readByAuthKey(action: Action): SagaIterator { + try { + const authKey = action.payload.authKey; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + + const emailAuth = yield call(AppContext.getService().readByAuthKey, authKey); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(ReadByAuthKeyAction.requestSuccess(emailAuth)); + } catch (e) { + yield put(ReadByAuthKeyAction.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchReadByAuthKey(): SagaIterator { + yield takeLatest(ReadByAuthKeyAction.REQUEST, readByAuthKey); +} diff --git a/src/ts/@overflow/email/redux/saga/read_by_member.ts b/src/ts/@overflow/email/redux/saga/read_by_member.ts index 4062be4..749b0b7 100644 --- a/src/ts/@overflow/email/redux/saga/read_by_member.ts +++ b/src/ts/@overflow/email/redux/saga/read_by_member.ts @@ -1,3 +1,40 @@ -/** - * Created by geek on 17. 7. 4. - */ +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 EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import EmailAuthService from '@overflow/email/api/service/EmailAuthService'; +import * as ReadByMemberAction from '../action/read_by_member'; +import ReadByMemberPayload from '../payload/ReadByMemberPayload'; + +function* readByMember(action: Action): SagaIterator { + try { + const id = action.payload.memberId; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + + const emailAuths = yield call(AppContext.getService().readByMember, id); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(ReadByMemberAction.requestSuccess(emailAuths)); + } catch (e) { + yield put(ReadByMemberAction.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchReadByMember(): SagaIterator { + yield takeLatest(ReadByMemberAction.REQUEST, readByMember); +} diff --git a/src/ts/@overflow/email/redux/saga/send_email_by_member.ts b/src/ts/@overflow/email/redux/saga/send_email_by_member.ts index e69de29..dbc71a9 100644 --- a/src/ts/@overflow/email/redux/saga/send_email_by_member.ts +++ b/src/ts/@overflow/email/redux/saga/send_email_by_member.ts @@ -0,0 +1,40 @@ +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 EmailAuth from '@overflow/email/api/model/EmailAuth'; + +import EmailAuthService from '@overflow/email/api/service/EmailAuthService'; +import * as SendEmailAction from '../action/send_email_by_member'; +import SendEmailPayload from '../payload/SendEmailByMemberPayload'; + +function* sendEmail(action: Action): SagaIterator { + try { + const {memberId, email} = action.payload; + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: true}, + // }); + + const emailAuth = yield call(AppContext.getService().sendEmailByMember, memberId, email); + + // if (responseBody.token === undefined) { + // throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE); + // } + yield put(SendEmailAction.requestSuccess(emailAuth)); + } catch (e) { + yield put(SendEmailAction.requestFailure(e)); + } finally { + // yield put({ + // type: types.SENDING_REQUEST, + // payload: {sendingRequest: false}, + // }); + } +} + +export function* watchSendEmail(): SagaIterator { + yield takeLatest(SendEmailAction.REQUEST, sendEmail); +}