@@ -7,6 +7,7 @@ import { throwError } from 'rxjs';
7
7
8
8
import { Place } from '../models/place.model' ;
9
9
import { ErrorService } from './error.service' ;
10
+ import { environment as env } from '../../environments/environment.development' ;
10
11
11
12
@Injectable ( {
12
13
providedIn : 'root' ,
@@ -19,15 +20,15 @@ export class PlacesService {
19
20
private errorServ = inject ( ErrorService ) ;
20
21
21
22
loadAvailablePlaces ( ) {
22
- return this . fetchPlaces ( '/api/v2/ places', 'Error loading available places!' ) ;
23
+ return this . fetchPlaces ( env . backendUrl + ' places.json ', 'Error loading available places!' ) ;
23
24
}
24
25
25
26
loadUserPlaces ( ) {
26
- return this . fetchPlaces ( '/api/v2/ user-places', 'Error loading user places!' ) . pipe (
27
+ return this . fetchPlaces ( env . backendUrl + ' user-places.json ', 'Error loading user places!' ) . pipe (
27
28
tap ( {
28
29
next : resp => {
29
30
if ( resp ) {
30
- this . userPlaces . set ( resp . places ) ;
31
+ this . userPlaces . set ( resp ) ;
31
32
}
32
33
} ,
33
34
} ) ,
@@ -43,7 +44,7 @@ export class PlacesService {
43
44
}
44
45
45
46
return this . http
46
- . put ( '/api/v2/ user-places', {
47
+ . put ( env . backendUrl + ' user-places', {
47
48
placeId : place . id ,
48
49
} )
49
50
. pipe (
@@ -63,7 +64,7 @@ export class PlacesService {
63
64
this . userPlaces . set ( prevPlaces . filter ( pl => pl . id !== place . id ) ) ;
64
65
}
65
66
66
- return this . http . delete ( '/api/v2/ user-places/' + place . id ) . pipe (
67
+ return this . http . delete ( env . backendUrl + ' user-places/' + place . id ) . pipe (
67
68
catchError ( err => {
68
69
this . userPlaces . set ( prevPlaces ) ;
69
70
this . errorServ . showError ( 'Unable to remove the selected place!' ) ;
@@ -74,7 +75,7 @@ export class PlacesService {
74
75
75
76
private fetchPlaces ( url : string , errMsg : string ) {
76
77
return this . http
77
- . get < { places : Place [ ] } > ( url , {
78
+ . get < Place [ ] > ( url , {
78
79
observe : 'response' , // it'll give full response including status code
79
80
} )
80
81
. pipe (
0 commit comments