Skip to content

Commit

Permalink
Replace dummy data
Browse files Browse the repository at this point in the history
  • Loading branch information
Popovkov57 committed Sep 28, 2022
1 parent c31310e commit 66e14fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/model/model.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import { StaticDataSource } from "./static.datasource";
import { Cart } from "./cart.model";
import { Order } from "./order.model";
import { OrderRepository } from "./order.repository";
import { RestDataSource } from "./rest.datasource";
import { HttpClientModule } from "@angular/common/http";

@NgModule({
providers: [ProductRepository, StaticDataSource, Cart, Order, OrderRepository]
imports: [HttpClientModule],
providers: [ProductRepository, Cart, Order, OrderRepository,
{ provide: StaticDataSource, useClass: RestDataSource }]
})

export class ModelModule {}
28 changes: 28 additions & 0 deletions src/app/model/rest.datasource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs";
import { Product } from "./product.model";
import { Cart } from "./cart.model";
import { Order } from "./order.model";

const PROTOCOL = "http";
const PORT = 3500;

@Injectable()
export class RestDataSource {

baseUrl: string;

constructor(private http: HttpClient) {
this.baseUrl = `${PROTOCOL}://${location.hostname}:${PORT}/`
}

getProducts(): Observable<Product[]> {
return this.http.get<Product[]>(this.baseUrl + "products");
}

saveOrder(order: Order): Observable<Order> {
console.log(JSON.stringify(order));
return this.http.post<Order>(this.baseUrl + "orders", order);
}
}

0 comments on commit 66e14fd

Please sign in to comment.