Project

General

Profile

« Previous | Next » 

Revision 50086

tried to pull repositories of user

View differences:

repository.service.ts
1
import {Injectable} from '@angular/core';
2
import {HttpClient, HttpHeaders} from '@angular/common/http';
3
import {Observable} from 'rxjs/Observable';
4
import {catchError, tap} from 'rxjs/operators';
1
/*
2
* Created by myrto on 12/05/2017
3
*/
5 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

  
6 18
const httpOptions = {
7
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
19
  headers: new HttpHeaders({ 'Content-Type': 'application/json','Access-Control-Allow-Origin': '*' })
8 20
};
9 21

  
10 22
@Injectable ()
......
13 25

  
14 26
  constructor(private http: HttpClient){}
15 27

  
16
  getRepositoriesOfUser(userEmail: string) : Observable<string[]> {
17
    return this.http.get(`${this.apiUrl}/users/${userEmail}`)
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`)
18 31
      .pipe(
19
      console.log(`accessing repositories of user with email ${userEmail}`)
20
    );
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
      );
21 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
  }
22 45
}

Also available in: Unified diff