Skip to content

Commit 3f605cf

Browse files
committed
deployable
1 parent ec2f14d commit 3f605cf

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

src/app/places/available-places/available-places.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ export class AvailablePlacesComponent implements OnInit {
2525

2626
const availablePlaceSub = this.placeServ.loadAvailablePlaces().subscribe({
2727
next: resp => {
28-
this.places.set(resp?.places);
29-
this.errorMsg.set('');
28+
if (resp) {
29+
this.places.set(resp);
30+
this.errorMsg.set('');
31+
}
3032
},
3133
complete: () => {
3234
this.isFetching.set(false);

src/app/places/places.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class PlacesComponent {
1414
places = input.required<Place[]>();
1515
selectPlace = output<Place>();
1616

17-
protected url = env.backendUrl;
17+
protected url = env.backendImgUrl;
1818

1919
onSelectPlace(place: Place) {
2020
this.selectPlace.emit(place);

src/app/services/places.service.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { throwError } from 'rxjs';
77

88
import { Place } from '../models/place.model';
99
import { ErrorService } from './error.service';
10+
import { environment as env } from '../../environments/environment.development';
1011

1112
@Injectable({
1213
providedIn: 'root',
@@ -19,15 +20,15 @@ export class PlacesService {
1920
private errorServ = inject(ErrorService);
2021

2122
loadAvailablePlaces() {
22-
return this.fetchPlaces('/api/v2/places', 'Error loading available places!');
23+
return this.fetchPlaces(env.backendUrl + 'places.json', 'Error loading available places!');
2324
}
2425

2526
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(
2728
tap({
2829
next: resp => {
2930
if (resp) {
30-
this.userPlaces.set(resp.places);
31+
this.userPlaces.set(resp);
3132
}
3233
},
3334
}),
@@ -43,7 +44,7 @@ export class PlacesService {
4344
}
4445

4546
return this.http
46-
.put('/api/v2/user-places', {
47+
.put(env.backendUrl + 'user-places', {
4748
placeId: place.id,
4849
})
4950
.pipe(
@@ -63,7 +64,7 @@ export class PlacesService {
6364
this.userPlaces.set(prevPlaces.filter(pl => pl.id !== place.id));
6465
}
6566

66-
return this.http.delete('/api/v2/user-places/' + place.id).pipe(
67+
return this.http.delete(env.backendUrl + 'user-places/' + place.id).pipe(
6768
catchError(err => {
6869
this.userPlaces.set(prevPlaces);
6970
this.errorServ.showError('Unable to remove the selected place!');
@@ -74,7 +75,7 @@ export class PlacesService {
7475

7576
private fetchPlaces(url: string, errMsg: string) {
7677
return this.http
77-
.get<{ places: Place[] }>(url, {
78+
.get<Place[]>(url, {
7879
observe: 'response', // it'll give full response including status code
7980
})
8081
.pipe(
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export const environment = {
2-
backendUrl: 'https://3000-actionanand-angularhttp-six5y8k89a8.ws-us116.gitpod.io/',
2+
// backendUrl: 'https://3000-actionanand-angularhttp-six5y8k89a8.ws-us116.gitpod.io/',
33
// backendUrl: 'http://localhost:3000/',
4+
backendUrl: 'https://raw.githubusercontent.com/actionanand/angular-http-project/master/backend/data/',
5+
backendImgUrl: 'https://raw.githubusercontent.com/actionanand/angular-http-project/refs/heads/master/backend/images/',
46
};

src/environments/environment.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const environment = {
2-
backendUrl: 'http://localhost:3000/',
2+
backendUrl: 'https://raw.githubusercontent.com/actionanand/angular-http-project/master/backend/data/',
3+
backendImgUrl: 'https://raw.githubusercontent.com/actionanand/angular-http-project/refs/heads/master/backend/images/',
34
};

0 commit comments

Comments
 (0)