diff --git a/src/packages/meta/meta-store.module.ts b/src/packages/meta/meta-store.module.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/packages/meta/meta.constant.ts b/src/packages/meta/meta.constant.ts new file mode 100644 index 0000000..d9302c8 --- /dev/null +++ b/src/packages/meta/meta.constant.ts @@ -0,0 +1,3 @@ +export const MODULE = { + name: 'meta' + }; diff --git a/src/packages/meta/meta.module.ts b/src/packages/meta/meta.module.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/packages/meta/service/crawler.service.spec.ts b/src/packages/meta/service/crawler.service.spec.ts new file mode 100644 index 0000000..2d1aaec --- /dev/null +++ b/src/packages/meta/service/crawler.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { CrawlerService } from './crawler.service'; + +describe('MemberService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [CrawlerService] + }); + }); + + it('should be created', inject([CrawlerService], (service: CrawlerService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/packages/meta/service/crawler.service.ts b/src/packages/meta/service/crawler.service.ts new file mode 100644 index 0000000..560fbc4 --- /dev/null +++ b/src/packages/meta/service/crawler.service.ts @@ -0,0 +1,32 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; + +import 'rxjs/add/operator/map'; + +import { RESTService } from 'packages/commons/service/rest.service'; + + +import { MetaCrawler } from '../model'; + +@Injectable() +export class CrawlerService { + + public constructor( + private restService: RESTService, + ) { + + } + + public signin(email: string, password: string): Observable { + const body = { + signinId: email, + signinPw: password, + }; + + return this.restService.post('/account/signin', body); + } + + public readAll(): Observable { + return this.restService.post('/account/signup', null); + } +} diff --git a/src/packages/meta/service/index.ts b/src/packages/meta/service/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/packages/meta/store/crawler-readall/index.ts b/src/packages/meta/store/crawler-readall/index.ts new file mode 100644 index 0000000..a1cbe91 --- /dev/null +++ b/src/packages/meta/store/crawler-readall/index.ts @@ -0,0 +1,4 @@ +export * from './readall.action'; +export * from './readall.effect'; +export * from './readall.reducer'; +export * from './readall.state'; diff --git a/src/packages/meta/store/crawler-readall/readall.action.ts b/src/packages/meta/store/crawler-readall/readall.action.ts new file mode 100644 index 0000000..c647f86 --- /dev/null +++ b/src/packages/meta/store/crawler-readall/readall.action.ts @@ -0,0 +1,37 @@ +import { Action } from '@ngrx/store'; + +import { ErrorResponse } from 'packages/commons/service/error-response'; + + +import { MetaCrawler } from '../../model'; + +export enum ActionType { + ReadAll = '[meta.crawler-readall] ReadAll', + ReadAllSuccess = '[meta.crawler-readall] ReadAllSuccess', + ReadAllFailure = '[meta.crawler-readall] ReadAllFailure', +} + +export class ReadAll implements Action { + readonly type = ActionType.ReadAll; + + constructor(public payload: {}) {} +} + +export class ReadAllSuccess implements Action { + readonly type = ActionType.ReadAllSuccess; + + constructor(public payload: MetaCrawler[]) {} +} + +export class ReadAllFailure implements Action { + readonly type = ActionType.ReadAllFailure; + + constructor(public payload: ErrorResponse) {} +} + +export type Actions = + | ReadAll + | ReadAllSuccess + | ReadAllFailure + +; diff --git a/src/packages/meta/store/crawler-readall/readall.effect.spec.ts b/src/packages/meta/store/crawler-readall/readall.effect.spec.ts new file mode 100644 index 0000000..4d528c3 --- /dev/null +++ b/src/packages/meta/store/crawler-readall/readall.effect.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { Effects } from './readall.effect'; + +describe('Auth.Effects', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [Effects] + }); + }); + + it('should be created', inject([Effects], (effects: Effects) => { + expect(effects).toBeTruthy(); + })); +}); diff --git a/src/packages/meta/store/crawler-readall/readall.effect.ts b/src/packages/meta/store/crawler-readall/readall.effect.ts new file mode 100644 index 0000000..223df1f --- /dev/null +++ b/src/packages/meta/store/crawler-readall/readall.effect.ts @@ -0,0 +1,57 @@ +import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; + +import { Effect, Actions, ofType } from '@ngrx/effects'; +import { Action } from '@ngrx/store'; + +import { Observable } from 'rxjs/Observable'; +import { of } from 'rxjs/observable/of'; + +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/exhaustMap'; +import 'rxjs/add/operator/switchMap'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/take'; + +import { ErrorResponse } from 'packages/commons/service/error-response'; + +import { DomainMember } from 'packages/domain/model'; + +import { MetaCrawler } from '../../model'; +import { CrawlerService } from '../../service/crawler.service'; + +import { + ReadAll, + ReadAllSuccess, + ReadAllFailure, + ActionType, +} from './readall.action'; + +@Injectable() +export class Effects { + + constructor( + private actions$: Actions, + private crawlerService: CrawlerService, + private router: Router + ) { } + + @Effect() + signin$: Observable = this.actions$ + .ofType(ActionType.ReadAll) + .map((action: ReadAll) => action.payload) + .switchMap(payload => this.crawlerService.readAll()) + .map((metaCrawlerList: MetaCrawler[]) => { + return new ReadAllSuccess(metaCrawlerList); + }) + .catch((error: ErrorResponse) => { + return of(new ReadAllFailure(error)); + }); + + @Effect({ dispatch: false }) + signinSuccess$ = this.actions$ + .ofType(ActionType.ReadAllSuccess) + .do(() => this.router.navigate(['/'])); + +} diff --git a/src/packages/meta/store/crawler-readall/readall.reducer.ts b/src/packages/meta/store/crawler-readall/readall.reducer.ts new file mode 100644 index 0000000..0fac605 --- /dev/null +++ b/src/packages/meta/store/crawler-readall/readall.reducer.ts @@ -0,0 +1,47 @@ +import { ErrorResponse } from 'packages/commons/service/error-response'; + +import { + Actions, + ActionType, +} from './readall.action'; + +import { + State, + initialState, +} from './readall.state'; + +import { MetaCrawler } from '../../model'; + +export function reducer(state = initialState, action: Actions): State { + switch (action.type) { + case ActionType.ReadAll: { + return { + ...state, + error: null, + pending: true, + }; + } + + case ActionType.ReadAllSuccess: { + return { + ...state, + error: null, + pending: false, + metaCrawlerList: action.payload + }; + } + + case ActionType.ReadAllFailure: { + return { + ...state, + error: action.payload, + pending: false, + metaCrawlerList: null, + }; + } + + default: { + return state; + } + } +} diff --git a/src/packages/meta/store/crawler-readall/readall.state.ts b/src/packages/meta/store/crawler-readall/readall.state.ts new file mode 100644 index 0000000..7de7dc6 --- /dev/null +++ b/src/packages/meta/store/crawler-readall/readall.state.ts @@ -0,0 +1,15 @@ +import { ErrorResponse } from 'packages/commons/service/error-response'; + +import { MetaCrawler } from '../../model'; + +export interface State { + error: ErrorResponse | null; + pending: boolean; + metaCrawlerList: MetaCrawler[] | null; +} + +export const initialState: State = { + error: null, + pending: false, + metaCrawlerList: null, +}; diff --git a/src/packages/meta/store/index.ts b/src/packages/meta/store/index.ts new file mode 100644 index 0000000..26c26ff --- /dev/null +++ b/src/packages/meta/store/index.ts @@ -0,0 +1,31 @@ +import { + createSelector, + createFeatureSelector, + ActionReducerMap, + } from '@ngrx/store'; + + import { StateSelector } from 'packages/commons/util/ngrx/store'; + + import { MODULE } from '../meta.constant'; + + import * as CrawlerReadAllStore from './crawler-readall'; + + export interface State { + readAll: CrawlerReadAllStore.State; + } + + export const REDUCERS = { + readAll: CrawlerReadAllStore.reducer, + }; + + export const EFFECTS = [ + CrawlerReadAllStore.Effects, + ]; + + export const selectCrawlerReadAllState = createFeatureSelector(MODULE.name); + + export const CrawlerReadAllSelector = new StateSelector(createSelector( + selectCrawlerReadAllState, + (state: State) => state.readAll + )); +