import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs/Observable' ; import { Todo } from '@Models/todo' ; import { HttpClient } from '@angular/common/http' ; import { environment } from 'environments/environment' ; import { map } from 'rxjs/operators' ; @ Injectable ( ) export class TodoListService { constructor ( private http ) { } getTodos ( ) { return this . http . get < Todo [ ] > ( `${ environment . apiUrl }/todos` ) ; } createTodo ( body ) { return this . http . post < Todo > ( `${ environment . apiUrl }/todos` , body ) ; } patchTodo ( changes , id ) { return this . http . patch < Todo > ( `${ environment . apiUrl }/todos/${ id }` , changes ) ; } deleteTodo ( id ) { return this . http . delete < Todo > ( `${ environment . apiUrl }/todos/${ id }` ) . pipe ( map ( response => id ) ) ; } }