add meta crawler

This commit is contained in:
snoop 2018-03-08 19:25:18 +09:00
parent 08319ebc1d
commit 208231d3d6
13 changed files with 256 additions and 0 deletions

View File

View File

@ -0,0 +1,3 @@
export const MODULE = {
name: 'meta'
};

View File

View File

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

View File

@ -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<MetaCrawler> {
const body = {
signinId: email,
signinPw: password,
};
return this.restService.post<MetaCrawler>('/account/signin', body);
}
public readAll(): Observable<MetaCrawler[]> {
return this.restService.post<MetaCrawler[]>('/account/signup', null);
}
}

View File

View File

@ -0,0 +1,4 @@
export * from './readall.action';
export * from './readall.effect';
export * from './readall.reducer';
export * from './readall.state';

View File

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

View File

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

View File

@ -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<Action> = 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(['/']));
}

View File

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

View File

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

View File

@ -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<State>(MODULE.name);
export const CrawlerReadAllSelector = new StateSelector<CrawlerReadAllStore.State>(createSelector(
selectCrawlerReadAllState,
(state: State) => state.readAll
));