1 | import { HttpClient, HttpHeaders } from "@angular/common/http";
|
---|
2 | import { Injectable } from "@angular/core";
|
---|
3 | import { Observable } from "rxjs";
|
---|
4 | import { PlannerDto } from "../_models/dto/plannerDto";
|
---|
5 | import { PlannerLocationDto } from "../_models/dto/plannerLocationDto";
|
---|
6 | import { Planner } from "../_models/planner";
|
---|
7 |
|
---|
8 | @Injectable({
|
---|
9 | providedIn: 'root'
|
---|
10 | })
|
---|
11 | export class PlannerService {
|
---|
12 |
|
---|
13 | httpHeaders: HttpHeaders = new HttpHeaders({
|
---|
14 | 'Authorization': '' + sessionStorage.getItem("token"),
|
---|
15 | 'Accept': 'application/json',
|
---|
16 | 'Content-Type': 'application/json'
|
---|
17 | });
|
---|
18 |
|
---|
19 | constructor(private httpClient: HttpClient) {
|
---|
20 | }
|
---|
21 |
|
---|
22 |
|
---|
23 | getAllPlanners(): Observable<Planner[]> {
|
---|
24 | let url = "http://localhost:8080/api/planners/user";
|
---|
25 | console.log("SERVID: " + sessionStorage.getItem("token"));
|
---|
26 | console.log(this.httpHeaders.get('Authorization'));
|
---|
27 | return this.httpClient.get<Planner[]>(url, { headers: this.httpHeaders });
|
---|
28 | }
|
---|
29 |
|
---|
30 | postInitialPlanner(plannerDto: PlannerDto): Observable<Planner> {
|
---|
31 | let url = "http://localhost:8080/api/planner/new";
|
---|
32 | return this.httpClient.post<Planner>(url, plannerDto, {headers: this.httpHeaders});
|
---|
33 | }
|
---|
34 |
|
---|
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 });
|
---|
38 | }
|
---|
39 |
|
---|
40 | getPlannerById(id: number): Observable<Planner> {
|
---|
41 | let url = "http://localhost:8080/api/planner/" + id;
|
---|
42 | return this.httpClient.get<Planner>(url);
|
---|
43 | }
|
---|
44 |
|
---|
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 | }
|
---|
49 |
|
---|
50 | deleteLocationFromPlanner(plannerLocationDto : PlannerLocationDto) {
|
---|
51 | let url = "http://localhost:8080/api/delete-location";
|
---|
52 | const options = {
|
---|
53 | body: {
|
---|
54 | "plannerId": plannerLocationDto.plannerId,
|
---|
55 | "locationId": plannerLocationDto.locationId
|
---|
56 | }
|
---|
57 | }
|
---|
58 | return this.httpClient.request('delete', url, options);
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | } |
---|