This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class PizzaService { | |
private url='http://pizzaService'; | |
private endpoint = 'pizzas'; | |
constructor( | |
protected httpClient: HttpClient) {} | |
public create(pizza: Pizza): Observable<Pizza> { | |
return this.httpClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class PizzaSerializer { | |
fromJson(json: any): Pizza { | |
const pizza = new Pizza(); | |
pizza.id = json.id; | |
pizza.name = json.name; | |
pizza.cookedOn = moment(json.cookedOn, 'mm-dd-yyyy hh:mm'); | |
return pizza; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class PizzaService { | |
private url='http://pizzaService'; | |
private endpoint = 'pizzas'; | |
private serializer = new PizzaSerializer(); | |
constructor( | |
protected httpClient: HttpClient) {} | |
public create(pizza: Pizza): Observable<Pizza> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Serializer { | |
fromJson(json: any): Resource; | |
toJson(resource: Resource): any; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class ResourceService<T extends Resource> { | |
constructor( | |
private httpClient: HttpClient, | |
private url: string, | |
private endpoint: string, | |
private serializer: Serializer) {} | |
public create(item: T): Observable<T> { | |
return this.httpClient | |
.post<T>(`${this.url}/${this.endpoint}`, this.serializer.toJson(item)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class PizzaService extends ResourceService<Pizza> { | |
constructor(httpClient: HttpClient) { | |
super( | |
httpClient, | |
'http://pizzaService', | |
'pizzas', | |
new PizzaSerializer()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class SubResourceService<T extends Resource> { | |
constructor( | |
private httpClient: HttpClient, | |
private url: string, | |
private parentEndpoint: string, | |
private endpoint: string, | |
private serializer: Serializer) { } | |
public create(item: T): Observable<T> { | |
return this.httpClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface QueryBuilder { | |
toQueryMap: () => Map<string, string>; | |
toQueryString: () => string; | |
} | |
export class QueryOptions implements QueryBuilder { | |
public pageNumber: number; | |
public pageSize: number; | |
constructor() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('TodosComponent', () => { | |
let component: TodosComponent; | |
let fixture: ComponentFixture<TodosComponent>; | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
declarations: [ TodosComponent ], | |
providers: [ | |
{ provide: TodoService, useClass: TodoServiceMock } | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('DashboardComponent', () => { | |
let component: DashboardComponent; | |
let fixture: ComponentFixture<DashboardComponent>; | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
declarations: [ | |
DashboardComponent, | |
TodosComponent | |
], |
OlderNewer