Last active
May 23, 2019 05:17
-
-
Save krishna-acondy/5ebc9746a451a212a4319575fba132a7 to your computer and use it in GitHub Desktop.
Advanced Pizza Service with Serializer
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> { | |
return this.httpClient | |
.post<Pizza>(`${this.url}/${this.endpoint}`, this.serializer.toJson(pizza)) | |
.pipe(map(data => this.serializer.fromJson(data))); | |
} | |
public update(pizza: Pizza): Observable<Pizza> { | |
return this.httpClient | |
.put<Pizza>(`${this.url}/${this.endpoint}/${pizza.id}`, pizza) | |
.pipe(map(data => this.serializer.fromJson(data))); | |
} | |
read(id: number): Observable<Pizza> { | |
return this.httpClient | |
.get<Pizza>(`${this.url}/${this.endpoint}/${id}`) | |
.pipe(map(data => this.serializer.fromJson(data))); | |
} | |
list(): Observable<Pizza[]> { | |
return this.httpClient | |
.get<Pizza[]>(`${this.url}/${this.endpoint}`) | |
.pipe(map(data => this.serializer.fromJson(data))) | |
delete(id: number) { | |
return this.httpClient | |
.delete(`${this.url}/${this.endpoint}/${id}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment