import { Injectable } from '@angular/core' ; import { HttpClient , HttpHeaders } from '@angular/common/http' ; import { Observable } from 'rxjs/Observable' ; import { environment } from '../../environments/environment' ; import { VehiclesApiResponse , VehicleApiResponse , TokenApiResponse , UserApiResponse , UsersApiResponse , GenericApiResponse , FuelTypesApiResponse , FuelListApiResponse , FuelApiResponse , FuelUnitsApiResponse , FuelConsumptionUnitsApiResponse , DistanceUnitsApiResponse , CurrencyUnitsApiResponse , DashboardTopStatsApiResponse , DashboardMonthlyFuelCostsApiResponse } from '../model/api' ; import { AuthCredentials } from '../model/auth-credentials' ; import { User } from '../model/user' ; import { UserPreferences } from '../model/user-preferences' ; import { Vehicle } from '../model/vehicle' ; import { Fuel } from '../model/fuel' ; @ Injectable ( ) export class ApiService { private baseUrl : String ; constructor ( private httpClient ) { this . baseUrl = `${ environment . apiBaseUrl }` ; } public getVehicles ( ) { return this . httpClient . get < VehiclesApiResponse > ( `${ this . baseUrl }/vehicle` ) ; } public getVehicle ( vehicleId ) { return this . httpClient . get < VehicleApiResponse > ( `${ this . baseUrl }/vehicle/${ vehicleId }` ) ; } public createVehicle ( vehicle ) { return this . httpClient . post < VehicleApiResponse > ( `${ this . baseUrl }/vehicle` , vehicle ) ; } public updateVehicle ( vehicle ) { return this . httpClient . put < VehicleApiResponse > ( `${ this . baseUrl }/vehicle/${ vehicle . id }` , vehicle ) ; } public deleteVehicle ( vehicleId ) { return this . httpClient . delete < GenericApiResponse > ( `${ this . baseUrl }/vehicle/${ vehicleId }` ) ; } public getFuelForVehicle ( vehicleId ) { return this . httpClient . get < FuelListApiResponse > ( `${ this . baseUrl }/vehicle/${ vehicleId }/fuel` ) ; } public createFuelLog ( fuelLog ) { return this . httpClient . post < FuelApiResponse > ( `${ this . baseUrl }/vehicle/${ fuelLog . vehicle }/fuel` , fuelLog ) ; } public getFuelLog ( fuelLogId ) { return this . httpClient . get < FuelApiResponse > ( `${ this . baseUrl }/fuel/${ fuelLogId }` ) ; } public updateFuelLog ( fuelLog ) { return this . httpClient . put < FuelApiResponse > ( `${ this . baseUrl }/fuel/${ fuelLog . id }` , fuelLog ) ; } public deleteFuelLog ( fuelLogId ) { return this . httpClient . delete < GenericApiResponse > ( `${ this . baseUrl }/fuel/${ fuelLogId }` ) ; } public login ( credentials ) { return this . httpClient . post < TokenApiResponse > ( `${ this . baseUrl }/auth/authenticate` , credentials ) ; } public registerUser ( user ) { return this . httpClient . post < UserApiResponse > ( `${ this . baseUrl }/user` , user ) ; } public getUser ( userId ) { return this . httpClient . get < UserApiResponse > ( `${ this . baseUrl }/user/${ userId }` ) ; } public getAllUsers ( ) { return this . httpClient . get < UsersApiResponse > ( `${ this . baseUrl }/user` ) ; } public deleteUser ( userId ) { return this . httpClient . delete < GenericApiResponse > ( `${ this . baseUrl }/user/${ userId }` ) ; } public clearUserData ( userId ) { return this . httpClient . delete < GenericApiResponse > ( `${ this . baseUrl }/user/${ userId }/data` ) ; } public promoteUser ( userId ) { return this . httpClient . post < UserApiResponse > ( `${ this . baseUrl }/user/${ userId }/promote` , { } ) ; } public demoteUser ( userId ) { return this . httpClient . post < UserApiResponse > ( `${ this . baseUrl }/user/${ userId }/demote` , { } ) ; } public updateUserPreferences ( userId , userPreferences ) { return this . httpClient . put < UserApiResponse > ( `${ this . baseUrl }/user/${ userId }/updatePreferences` , userPreferences ) ; } public getFuelTypes ( ) { return this . httpClient . get < FuelTypesApiResponse > ( `${ this . baseUrl }/units/fuelTypes` ) ; } public getFuelUnits ( ) { return this . httpClient . get < FuelUnitsApiResponse > ( `${ this . baseUrl }/units/fuelUnits` ) ; } public getFuelConsumptionUnits ( ) { return this . httpClient . get < FuelConsumptionUnitsApiResponse > ( `${ this . baseUrl }/units/fuelConsumptionUnits` ) ; } public getDistanceUnits ( ) { return this . httpClient . get < DistanceUnitsApiResponse > ( `${ this . baseUrl }/units/distanceUnits` ) ; } public getCurrencyUnits ( ) { return this . httpClient . get < CurrencyUnitsApiResponse > ( `${ this . baseUrl }/units/currencyUnits` ) ; } public getDashboardTopStats ( ) { return this . httpClient . get < DashboardTopStatsApiResponse > ( `${ this . baseUrl }/dashboard` ) ; } public getMonthlyFuelCosts ( ) { return this . httpClient . get < DashboardMonthlyFuelCostsApiResponse > ( `${ this . baseUrl }/dashboard/monthlyFuelCosts` ) ; } }