From df0f482f0d93e99d29d696b9138fe2fa3dc148bf Mon Sep 17 00:00:00 2001
From: Priyanka Upadhye <92uppr1mst@hft-stuttgart.de>
Date: Thu, 28 Nov 2019 15:06:05 +0100
Subject: [PATCH 1/2] Added bike reservation api call.
---
src/app/home/home.page.ts | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts
index 16fd7c2..35ef028 100644
--- a/src/app/home/home.page.ts
+++ b/src/app/home/home.page.ts
@@ -24,7 +24,7 @@ export class HomePage {
public is3DChecked = false;
public isDetailsVisible = false;
- public selectedBike ={};
+ public selectedBike ={id: 0};
public tempArr = [1, 2];
public locationArr = [{ lat: 48.778409, lng: 9.179252 },
@@ -229,7 +229,23 @@ export class HomePage {
showBikeDetails(bike) {
this.selectedBike=bike;
+ this.selectedBike.id=bike.id;
this.isDetailsVisible = true;
}
+ reserveBike()
+ {
+ //this.selectedBike=bikeS;
+ this.storage.get('token').then((token) => {
+ let url = 'http://193.196.52.237:8081/reservation' + '?bikeId=' + this.selectedBike.id;
+ const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
+ this.bikeApi = this.httpClient.get(url, { headers });
+ this.bikeApi.subscribe((resp) => {
+ console.log('my data: ', resp);
+ this.bikes = resp;
+ }, (error) => console.log(error));
+ });
+
+
+ }
}
--
GitLab
From 2241fc3874dcc3e7e53a861582ae32dd1a5c16b4 Mon Sep 17 00:00:00 2001
From: Priyanka Upadhye <92uppr1mst@hft-stuttgart.de>
Date: Thu, 28 Nov 2019 17:19:32 +0100
Subject: [PATCH 2/2] Bike Reservation functionality with Bike cancellation
---
src/app/app-routing.module.ts | 62 ++++++++++++++++++-----------------
src/app/home/home.page.html | 38 ++++++++++++---------
src/app/home/home.page.ts | 28 +++++++++++++---
3 files changed, 78 insertions(+), 50 deletions(-)
diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts
index c85d5d2..d394142 100644
--- a/src/app/app-routing.module.ts
+++ b/src/app/app-routing.module.ts
@@ -1,34 +1,36 @@
-import { NgModule } from '@angular/core';
-import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
-
-const routes: Routes = [
- {
- path: '',
- redirectTo: 'login',
- pathMatch: 'full'
- },
- {
- path: 'home',
- loadChildren: () => import('./home/home.module').then(m => m.HomePageModule)
- },
- {
- path: 'list',
- loadChildren: () => import('./list/list.module').then(m => m.ListPageModule)
- },
- {
- path: 'login',
- loadChildren: () => import('./auth/login/login.module').then( m => m.LoginPageModule)
- },
{
+import { NgModule } from '@angular/core';
+import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
+
+const routes: Routes = [
+ {
+ path: '',
+ redirectTo: 'login',
+ pathMatch: 'full'
+ },
+ {
+ path: 'home',
+ loadChildren: () => import('./home/home.module').then(m => m.HomePageModule)
+ },
+ {
+ path: 'list',
+ loadChildren: () => import('./list/list.module').then(m => m.ListPageModule)
+ },
+ {
+ path: 'login',
+ loadChildren: () => import('./auth/login/login.module').then( m => m.LoginPageModule)
+ },
+ {
path: 'register',
loadChildren: () => import('./auth/register/register.module').then( m => m.RegisterPageModule)
}
+
+
+];
-];
-
-@NgModule({
- imports: [
- RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
- ],
- exports: [RouterModule]
-})
-export class AppRoutingModule {}
+@NgModule({
+ imports: [
+ RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
+ ],
+ exports: [RouterModule]
+})
+export class AppRoutingModule {}
diff --git a/src/app/home/home.page.html b/src/app/home/home.page.html
index 0b5ff18..59baf69 100644
--- a/src/app/home/home.page.html
+++ b/src/app/home/home.page.html
@@ -80,22 +80,22 @@
-
- Bike Location
-
-
- {{selectedBike.address}}
-
-
-
-
- Bike Distance
-
-
- {{selectedBike.distance + "m"}}
-
-
+
+ Bike Location
+
+
+ {{selectedBike.address}}
+
+
+
+ Bike Distance
+
+
+ {{selectedBike.distance + "m"}}
+
+
+
Reserve
@@ -103,6 +103,14 @@
Navigate
+
+
+ Hire
+
+
+ Cancel Reservation
+
+
diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts
index 35ef028..1df890b 100644
--- a/src/app/home/home.page.ts
+++ b/src/app/home/home.page.ts
@@ -4,6 +4,7 @@ import { RestService } from '../rest.service';
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Storage } from '@ionic/storage';
+import { ToastService } from '../services/toast.service';
declare var H: any;
@@ -25,6 +26,7 @@ export class HomePage {
public is3DChecked = false;
public isDetailsVisible = false;
public selectedBike ={id: 0};
+ public isBikeReserved= false;
public tempArr = [1, 2];
public locationArr = [{ lat: 48.778409, lng: 9.179252 },
@@ -45,7 +47,8 @@ export class HomePage {
constructor(private geolocation: Geolocation,
public restService: RestService,
public httpClient: HttpClient,
- private storage: Storage) {
+ private storage: Storage,
+ private toastService: ToastService) {
this.platform = new H.service.Platform({
'apikey': 'tiVTgBnPbgV1spie5U2MSy-obhD9r2sGiOCbBzFY2_k'
@@ -232,8 +235,7 @@ export class HomePage {
this.selectedBike.id=bike.id;
this.isDetailsVisible = true;
}
- reserveBike()
- {
+ reserveBike() {
//this.selectedBike=bikeS;
this.storage.get('token').then((token) => {
let url = 'http://193.196.52.237:8081/reservation' + '?bikeId=' + this.selectedBike.id;
@@ -241,11 +243,27 @@ export class HomePage {
this.bikeApi = this.httpClient.get(url, { headers });
this.bikeApi.subscribe((resp) => {
console.log('my data: ', resp);
- this.bikes = resp;
- }, (error) => console.log(error));
+ this.isBikeReserved=true;
+ this.toastService.showToast("Reservation Successful!");
+ }, (error) => {
+ console.log(error)
+ this.toastService.showToast("Only one bike may be reserved or rented at a time")
+ });
});
}
+ cancelReservation() {
+ this.storage.get('token').then((token) => {
+ let url = 'http://193.196.52.237:8081/reservation' + '?bikeId=' + this.selectedBike.id;
+ const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
+ this.bikeApi = this.httpClient.delete(url, { headers });
+ this.bikeApi.subscribe((resp) => {
+ console.log('my data: ', resp);
+ this.isBikeReserved=false;
+ }, (error) => console.log(error));
+ });
+
+ }
}
--
GitLab