Revision 50139
Added by Myrto Koukouli over 6 years ago
repository.service.ts | ||
---|---|---|
7 | 7 |
*/ |
8 | 8 |
|
9 | 9 |
import { Injectable } from '@angular/core'; |
10 |
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
10 |
import { HttpHeaders } from '@angular/common/http'; |
|
11 | 11 |
|
12 | 12 |
import { Observable } from 'rxjs/Observable'; |
13 | 13 |
|
14 |
import {PiwikInfo, Repository} from '../domain/typeScriptClasses'; |
|
15 |
import {of} from "rxjs/observable/of"; |
|
14 |
import { Country, PiwikInfo, Repository } from '../domain/typeScriptClasses'; |
|
16 | 15 |
import 'rxjs/add/operator/map'; |
17 |
import {Http, Response} from '@angular/http';
|
|
16 |
import { Http, Response } from '@angular/http';
|
|
18 | 17 |
|
19 | 18 |
const httpOptions = { |
20 | 19 |
headers: new HttpHeaders().set('Content-Type', 'application/json') |
... | ... | |
27 | 26 |
|
28 | 27 |
constructor(private http: Http) { } |
29 | 28 |
|
29 |
getRepositoriesOfCountry (country: string, mode: string): Observable<Repository[]> { |
|
30 |
let url = `${this.apiUrl}/repository/getRepositoriesByCountry/${country}/${mode}`; |
|
31 |
console.log(`knocking on: ${url}`); |
|
32 |
return this.http.get(url) |
|
33 |
.map( res => <Repository[]>res.json()) |
|
34 |
.catch(this.handleError); |
|
35 |
} |
|
36 |
|
|
30 | 37 |
getRepositoriesOfUser (userEmail: string): Observable<Repository[]> { |
31 | 38 |
let url = `${this.apiUrl}/repository/getRepositoriesOfUser/${userEmail}/0/10`; |
32 | 39 |
console.log(`knocking on: ${url}`); |
... | ... | |
35 | 42 |
.catch(this.handleError); |
36 | 43 |
} |
37 | 44 |
|
45 |
getCountries (): Observable<Country[]> { |
|
46 |
let url = `${this.apiUrl}/repository/getCountries`; |
|
47 |
console.log(`knocking on: ${url}`); |
|
48 |
return this.http.get(url) |
|
49 |
.map( res => <Country[]>res.json()) |
|
50 |
.catch(this.handleError); |
|
51 |
} |
|
52 |
|
|
38 | 53 |
private handleError(error: Response | any) { |
39 | 54 |
// In a real world app, we might use a remote logging infrastructure |
40 | 55 |
// We'd also dig deeper into the error to get a better message |
Also available in: Unified diff
continued adding services without api!