[84d0fbb] | 1 | import { HttpClient, HttpHeaders } from "@angular/common/http";
|
---|
[6a3a178] | 2 | import { Injectable } from "@angular/core";
|
---|
| 3 | import { Observable } from "rxjs";
|
---|
[6a80231] | 4 | import { PlannerDto } from "../_models/dto/plannerDto";
|
---|
[6a3a178] | 5 | import { Planner } from "../_models/planner";
|
---|
| 6 |
|
---|
| 7 | @Injectable({
|
---|
| 8 | providedIn: 'root'
|
---|
| 9 | })
|
---|
[84d0fbb] | 10 | export class PlannerService {
|
---|
| 11 |
|
---|
| 12 | httpHeaders: HttpHeaders = new HttpHeaders({
|
---|
[bdd6491] | 13 | 'Authorization': '' + sessionStorage.getItem("token"),
|
---|
[84d0fbb] | 14 | 'Accept': 'application/json',
|
---|
| 15 | 'Content-Type': 'application/json'
|
---|
[bdd6491] | 16 | });
|
---|
[84d0fbb] | 17 |
|
---|
[bdd6491] | 18 |
|
---|
| 19 | constructor(private httpClient: HttpClient) {
|
---|
[6a3a178] | 20 | }
|
---|
[ceaed42] | 21 |
|
---|
[bdd6491] | 22 |
|
---|
| 23 | getAllPlanners(): Observable<Planner[]> {
|
---|
[84d0fbb] | 24 | let url = "http://localhost:8080/api/planners/user";
|
---|
| 25 | console.log("SERVID: " + sessionStorage.getItem("token"));
|
---|
[bdd6491] | 26 | console.log(this.httpHeaders.get('Authorization'));
|
---|
| 27 | return this.httpClient.get<Planner[]>(url, { headers: this.httpHeaders });
|
---|
[6a3a178] | 28 | }
|
---|
[6a80231] | 29 |
|
---|
[bdd6491] | 30 | postInitialPlanner(plannerDto: PlannerDto): Observable<Planner> {
|
---|
[6a80231] | 31 | let url = "http://localhost:8080/api/planner/new";
|
---|
[bdd6491] | 32 | return this.httpClient.post<Planner>(url, plannerDto);
|
---|
[6a80231] | 33 | }
|
---|
| 34 |
|
---|
[bdd6491] | 35 | updatePlanner(id: number, plannerDto: PlannerDto): Observable<Planner> {
|
---|
| 36 | let url = "http://localhost:8080/api/edit/planner/" + id;
|
---|
| 37 | return this.httpClient.put<Planner>(url, plannerDto, { headers: this.httpHeaders });
|
---|
[6c1585f] | 38 | }
|
---|
| 39 |
|
---|
[bdd6491] | 40 | getPlannerById(id: number): Observable<Planner> {
|
---|
[6c1585f] | 41 | let url = "http://localhost:8080/api/planner/" + id;
|
---|
| 42 | return this.httpClient.get<Planner>(url);
|
---|
[6a80231] | 43 | }
|
---|
[ceaed42] | 44 |
|
---|
[bdd6491] | 45 | deletePlannerById(id: number): Observable<Planner> {
|
---|
| 46 | let url = "http://localhost:8080/api/delete/" + id;
|
---|
| 47 | return this.httpClient.delete<Planner>(url, { headers: this.httpHeaders });
|
---|
| 48 | }
|
---|
[6a3a178] | 49 | } |
---|