Files
LudosData/src/app/games.service.ts
2018-04-25 20:12:10 -04:00

103 lines
2.3 KiB
TypeScript

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<any> {
return this.http.get( this.APIURL + "/games?filter=Title,cs," + searchText + "&transform=1" )
.map(res => {
return(
res
);
});
}
getGames( queryFilters, querryPage, queryOrder, queryRecordMax ): Observable<any> {
return this.http.get( this.APIURL + "/games?filter="+ queryFilters +"&page="+ querryPage + "," + queryRecordMax +"&order="+ queryOrder +"&transform=1" )
.map(res => {
return(
res
);
});
}
postGame( gameData ): Observable<any> {
return this.http.post( this.APIURL + "/games/", gameData, httpOptions )
.map(res => {
return(
res
);
});
}
getGameById( gameId ): Observable<any> {
return this.http.get( this.APIURL + "/games/" + gameId )
.map(res => {
return(
res
);
});
}
putGameById( gameData, gameId ): Observable<any> {
return this.http.get( this.APIURL + "/games/" + gameId )
.map(res => {
return(
res
);
});
}
deleteGameById( gameId ): Observable<any> {
return this.http.delete( this.APIURL + "/games/" + gameId )
.map(res => {
return(
res
);
});
}
postFile(fileToUpload: File): Observable<any> {
//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
);
});
}
}