Commit 2241fc38 authored by Priyanka Upadhye's avatar Priyanka Upadhye
Browse files

Bike Reservation functionality with Bike cancellation

parent 922bced7
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
const routes: Routes = [ const routes: Routes = [
{ {
path: '', path: '',
redirectTo: 'login', redirectTo: 'login',
pathMatch: 'full' pathMatch: 'full'
}, },
{ {
path: 'home', path: 'home',
loadChildren: () => import('./home/home.module').then(m => m.HomePageModule) loadChildren: () => import('./home/home.module').then(m => m.HomePageModule)
}, },
{ {
path: 'list', path: 'list',
loadChildren: () => import('./list/list.module').then(m => m.ListPageModule) loadChildren: () => import('./list/list.module').then(m => m.ListPageModule)
}, },
{ {
path: 'login', path: 'login',
loadChildren: () => import('./auth/login/login.module').then( m => m.LoginPageModule) loadChildren: () => import('./auth/login/login.module').then( m => m.LoginPageModule)
}, { },
{
path: 'register', path: 'register',
loadChildren: () => import('./auth/register/register.module').then( m => m.RegisterPageModule) loadChildren: () => import('./auth/register/register.module').then( m => m.RegisterPageModule)
} }
];
]; @NgModule({
imports: [
@NgModule({ RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
imports: [ ],
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules }) exports: [RouterModule]
], })
exports: [RouterModule] export class AppRoutingModule {}
})
export class AppRoutingModule {}
...@@ -80,22 +80,22 @@ ...@@ -80,22 +80,22 @@
</ion-col> </ion-col>
</ion-row> </ion-row>
<ion-row> <ion-row>
<ion-col> <ion-col>
Bike Location Bike Location
</ion-col> </ion-col>
<ion-col> <ion-col>
{{selectedBike.address}} {{selectedBike.address}}
</ion-col> </ion-col>
</ion-row> </ion-row>
<ion-row>
<ion-col>
Bike Distance
</ion-col>
<ion-col>
{{selectedBike.distance + "m"}}
</ion-col>
</ion-row>
<ion-row> <ion-row>
<ion-col>
Bike Distance
</ion-col>
<ion-col>
{{selectedBike.distance + "m"}}
</ion-col>
</ion-row>
<ion-row *ngIf="!isBikeReserved">
<ion-col> <ion-col>
<ion-button size="medium" expand="block" (click)="reserveBike()">Reserve</ion-button> <ion-button size="medium" expand="block" (click)="reserveBike()">Reserve</ion-button>
</ion-col> </ion-col>
...@@ -103,6 +103,14 @@ ...@@ -103,6 +103,14 @@
<ion-button size="medium" expand="block" (click)="navigatetoBike()">Navigate</ion-button> <ion-button size="medium" expand="block" (click)="navigatetoBike()">Navigate</ion-button>
</ion-col> </ion-col>
</ion-row> </ion-row>
<ion-row *ngIf="isBikeReserved">
<ion-col>
<ion-button size="medium" expand="block" (click)="hireBike()">Hire</ion-button>
</ion-col>
<ion-col>
<ion-button size="medium" expand="block" (click)="cancelReservation()">Cancel Reservation</ion-button>
</ion-col>
</ion-row>
</ion-grid> </ion-grid>
</div> </div>
</div> </div>
......
...@@ -4,6 +4,7 @@ import { RestService } from '../rest.service'; ...@@ -4,6 +4,7 @@ import { RestService } from '../rest.service';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Storage } from '@ionic/storage'; import { Storage } from '@ionic/storage';
import { ToastService } from '../services/toast.service';
declare var H: any; declare var H: any;
...@@ -25,6 +26,7 @@ export class HomePage { ...@@ -25,6 +26,7 @@ export class HomePage {
public is3DChecked = false; public is3DChecked = false;
public isDetailsVisible = false; public isDetailsVisible = false;
public selectedBike ={id: 0}; public selectedBike ={id: 0};
public isBikeReserved= false;
public tempArr = [1, 2]; public tempArr = [1, 2];
public locationArr = [{ lat: 48.778409, lng: 9.179252 }, public locationArr = [{ lat: 48.778409, lng: 9.179252 },
...@@ -45,7 +47,8 @@ export class HomePage { ...@@ -45,7 +47,8 @@ export class HomePage {
constructor(private geolocation: Geolocation, constructor(private geolocation: Geolocation,
public restService: RestService, public restService: RestService,
public httpClient: HttpClient, public httpClient: HttpClient,
private storage: Storage) { private storage: Storage,
private toastService: ToastService) {
this.platform = new H.service.Platform({ this.platform = new H.service.Platform({
'apikey': 'tiVTgBnPbgV1spie5U2MSy-obhD9r2sGiOCbBzFY2_k' 'apikey': 'tiVTgBnPbgV1spie5U2MSy-obhD9r2sGiOCbBzFY2_k'
...@@ -232,8 +235,7 @@ export class HomePage { ...@@ -232,8 +235,7 @@ export class HomePage {
this.selectedBike.id=bike.id; this.selectedBike.id=bike.id;
this.isDetailsVisible = true; this.isDetailsVisible = true;
} }
reserveBike() reserveBike() {
{
//this.selectedBike=bikeS; //this.selectedBike=bikeS;
this.storage.get('token').then((token) => { this.storage.get('token').then((token) => {
let url = 'http://193.196.52.237:8081/reservation' + '?bikeId=' + this.selectedBike.id; let url = 'http://193.196.52.237:8081/reservation' + '?bikeId=' + this.selectedBike.id;
...@@ -241,11 +243,27 @@ export class HomePage { ...@@ -241,11 +243,27 @@ export class HomePage {
this.bikeApi = this.httpClient.get(url, { headers }); this.bikeApi = this.httpClient.get(url, { headers });
this.bikeApi.subscribe((resp) => { this.bikeApi.subscribe((resp) => {
console.log('my data: ', resp); console.log('my data: ', resp);
this.bikes = resp; this.isBikeReserved=true;
}, (error) => console.log(error)); 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));
});
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment