[6fe77af] | 1 | import { HttpClient, HttpHeaders } from "@angular/common/http";
|
---|
[eed0bf8] | 2 | import { Injectable } from "@angular/core";
|
---|
| 3 | import { Observable } from "rxjs";
|
---|
[6fe77af] | 4 | import { LocationDto } from "../_models/dto/locationDto";
|
---|
[ceaed42] | 5 | import { PlannerLocationDto } from "../_models/dto/plannerLocationDto";
|
---|
| 6 | import { Location } from "../_models/location";
|
---|
[eed0bf8] | 7 |
|
---|
| 8 | @Injectable({
|
---|
| 9 | providedIn: 'root'
|
---|
| 10 | })
|
---|
| 11 | export class LocationService{
|
---|
[6fe77af] | 12 |
|
---|
| 13 | httpHeaders: HttpHeaders = new HttpHeaders({
|
---|
| 14 | 'Authorization': '' + sessionStorage.getItem("token"),
|
---|
| 15 | 'Accept': 'application/json',
|
---|
| 16 | 'Content-Type': 'application/json'
|
---|
| 17 | });
|
---|
| 18 |
|
---|
[eed0bf8] | 19 | constructor(private httpClient : HttpClient){}
|
---|
| 20 |
|
---|
[ceaed42] | 21 | getLocationsFromCity(cityId: number, companionId: number, lengthOfStay: number, categoryIds: string): Observable<Location[]>{
|
---|
[188ee53] | 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);
|
---|
[eed0bf8] | 29 | }
|
---|
[ceaed42] | 30 |
|
---|
| 31 | postLocationToPlanner(plannerLocationDto : PlannerLocationDto) : Observable<Location>{
|
---|
| 32 | let url = "http://localhost:8080/api/add-location";
|
---|
[b738035] | 33 | return this.httpClient.post<Location>(url, plannerLocationDto);
|
---|
[ceaed42] | 34 | }
|
---|
| 35 |
|
---|
[59329aa] | 36 | getLocationsForPlanner(plannerId : number) : Observable<Location[]>{
|
---|
[ceaed42] | 37 | let url = "http://localhost:8080/api/planner/locations";
|
---|
| 38 | return this.httpClient.get<Location[]>(url + '?plannerId=' + plannerId);
|
---|
| 39 | }
|
---|
[59329aa] | 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 | }
|
---|
[8d391a1] | 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 | }
|
---|
[59329aa] | 70 |
|
---|
[76712b2] | 71 | getAllLocationsSearch(place : string) : Observable<Location[]>{
|
---|
| 72 | let url="http://localhost:8080/api/all";
|
---|
| 73 | return this.httpClient.get<Location[]>(url + "?place=" + place);
|
---|
| 74 | }
|
---|
[6fe77af] | 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 | }
|
---|
[eed0bf8] | 80 | } |
---|