source: trip-planner-front/src/app/_services/location.service.ts

Last change on this file was 6fe77af, checked in by Ema <ema_spirova@…>, 2 years ago

add location feature

  • Property mode set to 100644
File size: 3.3 KB
Line 
1import { HttpClient, HttpHeaders } from "@angular/common/http";
2import { Injectable } from "@angular/core";
3import { Observable } from "rxjs";
4import { LocationDto } from "../_models/dto/locationDto";
5import { PlannerLocationDto } from "../_models/dto/plannerLocationDto";
6import { Location } from "../_models/location";
7
8@Injectable({
9 providedIn: 'root'
10})
11export 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}
Note: See TracBrowser for help on using the repository browser.