import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) //headers: new HttpHeaders({ 'Content-Type': 'application/json' }) } const httpOptionsImage = { headers: new HttpHeaders({ 'Content-Type': 'multipart/form-data; charset=UTF-8' }) //headers: new HttpHeaders({ 'Content-Type': 'application/json' }) } const httpOptionsPut = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) } @Injectable() export class GamesService { APIURL = "http://192.241.155.78/api.php"; constructor( private http: HttpClient ){ } searchGamesByText( searchText ): Observable { return this.http.get( this.APIURL + "/games?filter=Title,cs," + searchText + "&transform=1" ) .map(res => { return( res ); }); } getGames( queryFilters, querryPage, queryOrder, queryRecordMax ): Observable { return this.http.get( this.APIURL + "/games?filter="+ queryFilters +"&page="+ querryPage + "," + queryRecordMax +"&order="+ queryOrder +"&transform=1" ) .map(res => { return( res ); }); } postGame( gameData ): Observable { return this.http.post( this.APIURL + "/games/", gameData, httpOptions ) .map(res => { return( res ); }); } getGameById( gameId ): Observable { return this.http.get( this.APIURL + "/games/" + gameId ) .map(res => { return( res ); }); } putGameById( gameData, gameId ): Observable { return this.http.get( this.APIURL + "/games/" + gameId ) .map(res => { return( res ); }); } deleteGameById( gameId ): Observable { return this.http.delete( this.APIURL + "/games/" + gameId ) .map(res => { return( res ); }); } postFile(fileToUpload: File): Observable { //const endpoint = 'http://192.241.155.78/ludosdata/imageUpload.php'; const endpoint = 'http://localhost/ludosdata/imageUpload.php'; const formData: FormData = new FormData(); formData.append('fileToUpload', fileToUpload, fileToUpload.name); return this.http.post(endpoint, formData) .map(res => { return( res ); }); } }