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
|
import { catchError, map, tap } from 'rxjs/operators'
|
14
|
|
15
|
import {PiwikInfo, Repository} from '../domain/typeScriptClasses';
|
16
|
import {of} from "rxjs/observable/of";
|
17
|
|
18
|
const httpOptions = {
|
19
|
headers: new HttpHeaders({ 'Content-Type': 'application/json','Access-Control-Allow-Origin': '*' })
|
20
|
};
|
21
|
|
22
|
@Injectable ()
|
23
|
export class RepositoryService {
|
24
|
private apiUrl = process.env.API_ENDPOINT;
|
25
|
|
26
|
constructor(private http: HttpClient){}
|
27
|
|
28
|
getRepositoriesOfUser (userEmail: string): Observable<PiwikInfo[]> {
|
29
|
console.log(`knocking on: ${this.apiUrl}/repository/getRepositoriesOfUser/${userEmail}/0/10`);
|
30
|
return this.http.get<Repository[]>(`${this.apiUrl}/repositories/getRepositoryOfUser/${userEmail}/0/10`)
|
31
|
.pipe(
|
32
|
tap( _ => console.log(`got respositories of user with email" ${userEmail}`)),
|
33
|
map( (rep: Repository) => rep.piwikInfo),
|
34
|
catchError(this.handleError(`get repositories of user with email: ${userEmail}`))
|
35
|
);
|
36
|
}
|
37
|
|
38
|
private handleError<T> (operation = 'operation', result?: T) {
|
39
|
return (error: any): Observable<T> => {
|
40
|
console.error(error);
|
41
|
console.log(`${operation} failed: ${error.message}`);
|
42
|
return of(result as T);
|
43
|
};
|
44
|
}
|
45
|
}
|