1
|
/*
|
2
|
* Created by myrto on 12/05/2017
|
3
|
*/
|
4
|
|
5
|
/*
|
6
|
* !!! USING TEMPORARY API ADDRESS AND USER
|
7
|
*/
|
8
|
|
9
|
import { Injectable } from '@angular/core';
|
10
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
11
|
|
12
|
import { Observable } from 'rxjs/Observable';
|
13
|
|
14
|
import {PiwikInfo, Repository} from '../domain/typeScriptClasses';
|
15
|
import {of} from "rxjs/observable/of";
|
16
|
import 'rxjs/add/operator/map';
|
17
|
import {Http, Response} from '@angular/http';
|
18
|
|
19
|
const httpOptions = {
|
20
|
headers: new HttpHeaders().set('Content-Type', 'application/json')
|
21
|
};
|
22
|
|
23
|
@Injectable ()
|
24
|
export class RepositoryService {
|
25
|
private apiUrl = 'http://195.134.66.230:8380/uoa-repository-manager-service';
|
26
|
|
27
|
constructor(private http: Http){}
|
28
|
|
29
|
getRepositoriesOfUser (userEmail: string): Observable<Repository[]> {
|
30
|
let url = `${this.apiUrl}/repository/getRepositoriesOfUser/${userEmail}/0/10`;
|
31
|
console.log(`knocking on: ${url}`);
|
32
|
return this.http.get(url)
|
33
|
.map( res => <Repository[]>res.json())
|
34
|
.catch(this.handleError);
|
35
|
}
|
36
|
|
37
|
private handleError(error: Response | any) {
|
38
|
// In a real world app, we might use a remote logging infrastructure
|
39
|
// We'd also dig deeper into the error to get a better message
|
40
|
let errMsg = "";
|
41
|
console.log(error);
|
42
|
if (error instanceof Response) {
|
43
|
const body = error.text() || '';
|
44
|
//const err = body.error || JSON.stringify(body);
|
45
|
errMsg = `${error.status} - ${error.statusText || ''} ${body}`;
|
46
|
} else {
|
47
|
errMsg = (error.message) ? error.message :
|
48
|
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
|
49
|
console.error(errMsg); // log to console instead
|
50
|
}
|
51
|
return Observable.throw(errMsg);
|
52
|
}
|
53
|
}
|