-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from Apes2getherStrong/100-mozliwosc-dodania-…
…istniejacego-punktu-do-trasy feat: can add existing point (map location) to your route
- Loading branch information
Showing
5 changed files
with
87 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,49 @@ | ||
import {Injectable} from "@angular/core"; | ||
import {HttpClient} from "@angular/common/http"; | ||
import {backendUrl} from "../shared/http.config"; | ||
import { Injectable } from "@angular/core"; | ||
import { HttpClient } from "@angular/common/http"; | ||
import { backendUrl } from "../shared/http.config"; | ||
import {Observable, of, switchMap} from "rxjs"; | ||
import { map } from "rxjs/operators"; | ||
|
||
@Injectable({providedIn: 'root'}) | ||
@Injectable({ providedIn: 'root' }) | ||
export class RouteMapLocationService { | ||
|
||
constructor(private http: HttpClient) {} | ||
|
||
postRouteMapLocation(routeId: string, mapLocationId: string) { | ||
let newRouteMapLocation = { | ||
postRouteMapLocation(routeId: string, mapLocationId: string): Observable<any> | null { | ||
const newRouteMapLocation = { | ||
mapLocation: { | ||
id: mapLocationId | ||
}, | ||
route: { | ||
id: routeId | ||
}, | ||
sequenceNr: 1 | ||
} | ||
const url = `${backendUrl}/routeMapLocations` | ||
return this.http.post(url, newRouteMapLocation) | ||
}; | ||
|
||
return this.checkIfIsAlreadyCreated(routeId, mapLocationId).pipe( | ||
switchMap(isCreated => { | ||
if (!isCreated) { | ||
const url = `${backendUrl}/routeMapLocations`; | ||
return this.http.post(url, newRouteMapLocation); | ||
} else { | ||
alert('This map Location is already in your route!') | ||
return of(null); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
|
||
checkIfIsAlreadyCreated(routeId: string, mapLocationId: string): Observable<boolean> { | ||
return this.getRouteMapLocationByMapLocationId(mapLocationId).pipe( | ||
map((response: any[]) => { | ||
return response.some(location => location.route.id === routeId); | ||
}) | ||
); | ||
} | ||
|
||
getRouteMapLocationByMapLocationId(mapLocationId: string): Observable<any> { | ||
const url = `${backendUrl}/mapLocation/${mapLocationId}/routeMapLocations`; | ||
return this.http.get(url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters