1 | import { HttpClient, HttpHeaders } from "@angular/common/http";
|
---|
2 | import { Injectable } from "@angular/core";
|
---|
3 | import { Observable } from "rxjs";
|
---|
4 | import { LocationDto } from "../_models/dto/locationDto";
|
---|
5 | import { PlannerLocationDto } from "../_models/dto/plannerLocationDto";
|
---|
6 | import { Location } from "../_models/location";
|
---|
7 |
|
---|
8 | @Injectable({
|
---|
9 | providedIn: 'root'
|
---|
10 | })
|
---|
11 | export class LocationService{
|
---|
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 | getLocationsFromCity(cityId: number, companionId: number, lengthOfStay: number, categoryIds: string): Observable<Location[]>{
|
---|
22 | let url = "http://localhost:8080/api/city/locations";
|
---|
23 | return this.httpClient.get<Location[]>(url + '?cityId=' + cityId + '&companionId=' + companionId + '&lengthOfStay=' + lengthOfStay + '&categoryIds='+ categoryIds);
|
---|
24 | }
|
---|
25 |
|
---|
26 | getLocationsFromRegion(regionId: number, companionId: number, lengthOfStay: number, categoryIds: string):Observable<Object[]>{
|
---|
27 | let url = "http://localhost:8080/api/region/locations";
|
---|
28 | return this.httpClient.get<Location[]>(url + '?regionId=' + regionId + '&companionId=' + companionId + '&lengthOfStay=' + lengthOfStay + '&categoryIds='+ categoryIds);
|
---|
29 | }
|
---|
30 |
|
---|
31 | postLocationToPlanner(plannerLocationDto : PlannerLocationDto) : Observable<Location>{
|
---|
32 | let url = "http://localhost:8080/api/add-location";
|
---|
33 | return this.httpClient.post<Location>(url, plannerLocationDto);
|
---|
34 | }
|
---|
35 |
|
---|
36 | getLocationsForPlanner(plannerId : number) : Observable<Location[]>{
|
---|
37 | let url = "http://localhost:8080/api/planner/locations";
|
---|
38 | return this.httpClient.get<Location[]>(url + '?plannerId=' + plannerId);
|
---|
39 | }
|
---|
40 |
|
---|
41 | getAllLocations() : Observable<Location[]> {
|
---|
42 | let url = "http://localhost:8080/api/locations";
|
---|
43 | return this.httpClient.get<Location[]>(url);
|
---|
44 | }
|
---|
45 |
|
---|
46 | getWeekendGetaways() : Observable<Location[]>{
|
---|
47 | let url = "http://localhost:8080/api/weekend";
|
---|
48 | return this.httpClient.get<Location[]>(url);
|
---|
49 | }
|
---|
50 |
|
---|
51 | getVillages() : Observable<Location[]>{
|
---|
52 | let url = "http://localhost:8080/api/villages";
|
---|
53 | return this.httpClient.get<Location[]>(url);
|
---|
54 | }
|
---|
55 |
|
---|
56 | getLocation(id : number) :Observable<Location>{
|
---|
57 | let url = "http://localhost:8080/api/location/" + id;
|
---|
58 | return this.httpClient.get<Location>(url);
|
---|
59 | }
|
---|
60 |
|
---|
61 | getAllLocationsForPlanner(id: number): Observable<Location[]>{
|
---|
62 | let url = "http://localhost:8080/api/planner/locations";
|
---|
63 | return this.httpClient.get<Location[]>(url + "?plannerId=" + id);
|
---|
64 | }
|
---|
65 |
|
---|
66 | getAllLocationIdsForPlanner(id:number):Observable<number[]>{
|
---|
67 | let url = "http://localhost:8080/api/planner/locationIds";
|
---|
68 | return this.httpClient.get<number[]>(url + "?plannerId="+id);
|
---|
69 | }
|
---|
70 |
|
---|
71 | getAllLocationsSearch(place : string) : Observable<Location[]>{
|
---|
72 | let url="http://localhost:8080/api/all";
|
---|
73 | return this.httpClient.get<Location[]>(url + "?place=" + place);
|
---|
74 | }
|
---|
75 |
|
---|
76 | save(locationDto : LocationDto) : Observable<Location>{
|
---|
77 | let url = "http://localhost:8080/api/add";
|
---|
78 | return this.httpClient.post<Location>(url, locationDto, {headers: this.httpHeaders});
|
---|
79 | }
|
---|
80 | } |
---|