add meta crawler
This commit is contained in:
parent
08319ebc1d
commit
208231d3d6
0
src/packages/meta/meta-store.module.ts
Normal file
0
src/packages/meta/meta-store.module.ts
Normal file
3
src/packages/meta/meta.constant.ts
Normal file
3
src/packages/meta/meta.constant.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const MODULE = {
|
||||||
|
name: 'meta'
|
||||||
|
};
|
0
src/packages/meta/meta.module.ts
Normal file
0
src/packages/meta/meta.module.ts
Normal file
15
src/packages/meta/service/crawler.service.spec.ts
Normal file
15
src/packages/meta/service/crawler.service.spec.ts
Normal 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();
|
||||||
|
}));
|
||||||
|
});
|
32
src/packages/meta/service/crawler.service.ts
Normal file
32
src/packages/meta/service/crawler.service.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
0
src/packages/meta/service/index.ts
Normal file
0
src/packages/meta/service/index.ts
Normal file
4
src/packages/meta/store/crawler-readall/index.ts
Normal file
4
src/packages/meta/store/crawler-readall/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export * from './readall.action';
|
||||||
|
export * from './readall.effect';
|
||||||
|
export * from './readall.reducer';
|
||||||
|
export * from './readall.state';
|
37
src/packages/meta/store/crawler-readall/readall.action.ts
Normal file
37
src/packages/meta/store/crawler-readall/readall.action.ts
Normal 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
|
||||||
|
|
||||||
|
;
|
|
@ -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();
|
||||||
|
}));
|
||||||
|
});
|
57
src/packages/meta/store/crawler-readall/readall.effect.ts
Normal file
57
src/packages/meta/store/crawler-readall/readall.effect.ts
Normal 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(['/']));
|
||||||
|
|
||||||
|
}
|
47
src/packages/meta/store/crawler-readall/readall.reducer.ts
Normal file
47
src/packages/meta/store/crawler-readall/readall.reducer.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
src/packages/meta/store/crawler-readall/readall.state.ts
Normal file
15
src/packages/meta/store/crawler-readall/readall.state.ts
Normal 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,
|
||||||
|
};
|
31
src/packages/meta/store/index.ts
Normal file
31
src/packages/meta/store/index.ts
Normal 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
|
||||||
|
));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user