mirror of https://github.com/abpframework/abp
				
				
				
			
							parent
							
								
									b324cbd2cc
								
							
						
					
					
						commit
						7d683b82d1
					
				| @ -0,0 +1,19 @@ | |||||||
|  | import { NgModule } from '@angular/core'; | ||||||
|  | import { Routes, RouterModule } from '@angular/router'; | ||||||
|  | 
 | ||||||
|  | import { BooksComponent } from './books.component'; | ||||||
|  | import { LayoutApplicationComponent } from '@abp/ng.theme.basic'; | ||||||
|  | 
 | ||||||
|  | const routes: Routes = [ | ||||||
|  |   { | ||||||
|  |     path: '', | ||||||
|  |     component: LayoutApplicationComponent, | ||||||
|  |     children: [{ path: '', component: BooksComponent }], | ||||||
|  |   }, | ||||||
|  | ]; | ||||||
|  | 
 | ||||||
|  | @NgModule({ | ||||||
|  |   imports: [RouterModule.forChild(routes)], | ||||||
|  |   exports: [RouterModule] | ||||||
|  | }) | ||||||
|  | export class BooksRoutingModule { } | ||||||
| @ -0,0 +1 @@ | |||||||
|  | <p>books works!</p> | ||||||
| @ -0,0 +1,25 @@ | |||||||
|  | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||||||
|  | 
 | ||||||
|  | import { BooksComponent } from './books.component'; | ||||||
|  | 
 | ||||||
|  | describe('BooksComponent', () => { | ||||||
|  |   let component: BooksComponent; | ||||||
|  |   let fixture: ComponentFixture<BooksComponent>; | ||||||
|  | 
 | ||||||
|  |   beforeEach(async(() => { | ||||||
|  |     TestBed.configureTestingModule({ | ||||||
|  |       declarations: [ BooksComponent ] | ||||||
|  |     }) | ||||||
|  |     .compileComponents(); | ||||||
|  |   })); | ||||||
|  | 
 | ||||||
|  |   beforeEach(() => { | ||||||
|  |     fixture = TestBed.createComponent(BooksComponent); | ||||||
|  |     component = fixture.componentInstance; | ||||||
|  |     fixture.detectChanges(); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   it('should create', () => { | ||||||
|  |     expect(component).toBeTruthy(); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
| @ -0,0 +1,13 @@ | |||||||
|  | import { Component, OnInit } from "@angular/core"; | ||||||
|  | import { Store } from "@ngxs/store"; | ||||||
|  | 
 | ||||||
|  | @Component({ | ||||||
|  |   selector: "app-books", | ||||||
|  |   templateUrl: "./books.component.html", | ||||||
|  |   styleUrls: ["./books.component.scss"] | ||||||
|  | }) | ||||||
|  | export class BooksComponent implements OnInit { | ||||||
|  |   constructor(private store: Store) {} | ||||||
|  | 
 | ||||||
|  |   ngOnInit() {} | ||||||
|  | } | ||||||
| @ -0,0 +1,17 @@ | |||||||
|  | import { NgModule } from '@angular/core'; | ||||||
|  | import { CommonModule } from '@angular/common'; | ||||||
|  | 
 | ||||||
|  | import { BooksRoutingModule } from './books-routing.module'; | ||||||
|  | import { BooksComponent } from './books.component'; | ||||||
|  | import { SharedModule } from '../shared/shared.module'; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @NgModule({ | ||||||
|  |   declarations: [BooksComponent], | ||||||
|  |   imports: [ | ||||||
|  |     CommonModule, | ||||||
|  |     BooksRoutingModule, | ||||||
|  |     SharedModule | ||||||
|  |   ] | ||||||
|  | }) | ||||||
|  | export class BooksModule { } | ||||||
| @ -0,0 +1,12 @@ | |||||||
|  | import { TestBed } from '@angular/core/testing'; | ||||||
|  | 
 | ||||||
|  | import { BooksService } from './books.service'; | ||||||
|  | 
 | ||||||
|  | describe('BooksService', () => { | ||||||
|  |   beforeEach(() => TestBed.configureTestingModule({})); | ||||||
|  | 
 | ||||||
|  |   it('should be created', () => { | ||||||
|  |     const service: BooksService = TestBed.get(BooksService); | ||||||
|  |     expect(service).toBeTruthy(); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
| @ -0,0 +1,15 @@ | |||||||
|  | import { Injectable } from '@angular/core'; | ||||||
|  | import { HttpClient } from '@angular/common/http'; | ||||||
|  | import { environment } from 'src/environments/environment'; | ||||||
|  | 
 | ||||||
|  | @Injectable({ | ||||||
|  |   providedIn: 'root' | ||||||
|  | }) | ||||||
|  | export class BooksService { | ||||||
|  | 
 | ||||||
|  |   constructor(private http: HttpClient) { } | ||||||
|  | 
 | ||||||
|  |   get() { | ||||||
|  |     return this.http.get(`${environment.apis.default.url}/app/book`) | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -0,0 +1,4 @@ | |||||||
|  | export class BooksGet { | ||||||
|  |   static readonly type = '[Books] Get'; | ||||||
|  |   constructor(public readonly payload?: any) { } | ||||||
|  | } | ||||||
| @ -0,0 +1 @@ | |||||||
|  | export * from './books.actions'; | ||||||
| @ -0,0 +1,5 @@ | |||||||
|  | export namespace Books { | ||||||
|  |   export interface State { | ||||||
|  |     data: any; | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -0,0 +1 @@ | |||||||
|  | export * from './books'; | ||||||
| @ -0,0 +1,27 @@ | |||||||
|  | import { State, Action, StateContext } from "@ngxs/store"; | ||||||
|  | import { BooksGet } from "../actions/books.actions"; | ||||||
|  | import { Books } from "../models/books"; | ||||||
|  | import { BooksService } from "src/app/shared/services/books.service"; | ||||||
|  | import { tap } from "rxjs/operators"; | ||||||
|  | 
 | ||||||
|  | @State<Books.State>({ | ||||||
|  |   name: "BooksState", | ||||||
|  |   defaults: {} as Books.State | ||||||
|  | }) | ||||||
|  | export class BooksState { | ||||||
|  |   constructor(private booksService: BooksService) {} | ||||||
|  | 
 | ||||||
|  |   @Action(BooksGet) | ||||||
|  |   booksAction( | ||||||
|  |     { getState, patchState }: StateContext<Books.State>, | ||||||
|  |     { payload }: BooksGet | ||||||
|  |   ) { | ||||||
|  |     return this.booksService.get().pipe( | ||||||
|  |       tap(data => { | ||||||
|  |         patchState({ | ||||||
|  |           data | ||||||
|  |         }); | ||||||
|  |       }) | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -0,0 +1 @@ | |||||||
|  | export * from "./books.state"; | ||||||
					Loading…
					
					
				
		Reference in new issue
	
	 Halil İbrahim Kalkan
						Halil İbrahim Kalkan