import { Injectable } from '@angular/core' ; import { HttpClient , HttpHeaders } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { Task } from './task' ; import { AuthService } from './auth/auth.service' ; import { environment } from '../environments/environment' ; @ Injectable ( { providedIn : 'root' } ) export class ApiService { API_URL = environment . apiUrl ; constructor ( private http , private auth ) { } public getTasks ( ) { return this . http . get < Task [ ] > ( `${ this . API_URL }/task/` , { headers : new HttpHeaders ( ) . set ( 'Authorization' , `Bearer ${ this . auth . accessToken }` ) } ) ; } public postTask ( new_task ) { return this . http . post ( `${ this . API_URL }/task/` , new_task , { headers : new HttpHeaders ( ) . set ( 'Authorization' , `Bearer ${ this . auth . accessToken }` ) } ) ; } public putTask ( the_task ) { return this . http . put ( `${ this . API_URL }/task/${ the_task . id }/` , the_task , { headers : new HttpHeaders ( ) . set ( 'Authorization' , `Bearer ${ this . auth . accessToken }` ) } ) ; } public deleteTask ( task_id ) { return this . http . delete ( `${ this . API_URL }/task/${ task_id }/` , { headers : new HttpHeaders ( ) . set ( 'Authorization' , `Bearer ${ this . auth . accessToken }` ) } ) ; } }