2018-10-30 16:31:16 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Http, Response, Headers, RequestOptions } from '@angular/http';
|
|
|
|
import { Observable } from 'rxjs/Rx';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class SubjectsService {
|
|
|
|
|
2019-03-07 16:43:10 +01:00
|
|
|
constructor(private http: Http) {
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-07 16:43:10 +01:00
|
|
|
addSubjects(url: string, subjects: any) {
|
|
|
|
const headers = new Headers({'Content-Type': 'application/json'});
|
|
|
|
const options = new RequestOptions({headers: headers});
|
2018-10-30 16:31:16 +01:00
|
|
|
|
2019-03-07 16:43:10 +01:00
|
|
|
const body = JSON.stringify(subjects);
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
return this.http.post(url, body, options)
|
2019-03-07 16:43:10 +01:00
|
|
|
// .do(request => console.log("Insert Response:"+request.status))
|
2018-10-30 16:31:16 +01:00
|
|
|
.map(res => res.json())
|
|
|
|
.map(res => {
|
2019-03-07 16:43:10 +01:00
|
|
|
res['method'] = 'post';
|
2018-10-30 16:31:16 +01:00
|
|
|
return res;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-07 16:43:10 +01:00
|
|
|
removeSubjects(url: string, subjects: any) {
|
|
|
|
const headers = new Headers({'Content-Type': 'application/json'});
|
2018-10-30 16:31:16 +01:00
|
|
|
|
2019-03-07 16:43:10 +01:00
|
|
|
const body = JSON.stringify(subjects);
|
|
|
|
const options = new RequestOptions({headers: headers, body: body});
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
return this.http.delete(url, options)
|
2019-03-07 16:43:10 +01:00
|
|
|
// .do(request => console.log("Delete Response:"+request.status))
|
2018-10-30 16:31:16 +01:00
|
|
|
.map(res => res.json())
|
|
|
|
.map(res => {
|
2019-03-07 16:43:10 +01:00
|
|
|
res['method'] = 'delete';
|
2018-10-30 16:31:16 +01:00
|
|
|
return res;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|