<commit_before>/**
 * Created by Khémon on 21/11/2016.
 */
import {Injectable, Inject} from '@angular/core';
import {Http, Headers, Response, RequestOptions} from '@angular/http';
import {User} from '../model/user';
import {Observable} from 'rxjs/Observable';
import {AppConfig, APP_CONFIG} from '../app-config';
import 'rxjs/Rx';

@Injectable()
export class UserService {
  private userUrl = 'user'
  private apiEndPoint;

  constructor(@Inject(APP_CONFIG) private config: AppConfig, private http: Http) {
    // Base URL for Talented API
    this.apiEndPoint = config.apiEndPoint;
  }

  getUsers(): Observable<User[]>{
    return this.http.get(this.apiEndPoint + this.userUrl)
      .map(this.extractData)
      .catch(this.handleError);
  }

  addUser(user: User): Observable<User> {
    let userString = JSON.stringify(user);
    let headers = new Headers({'Content-Type': 'application/json'});
    let options = new RequestOptions({headers: headers});
    return this.http.post(this.apiEndPoint + 'user/add', userString, options)
      .map(this.extractData)
      .catch(this.handleError);
  }
/*
  (id: numgetUserber): Observable<User> {
    return this.getUsers().
    subscribe(
      users => users.find(user => user.id === id)
    )
  }


  update(user: User): Observable<User> {
    const url = `${this.usersUrl}/${user.id}`;
    return this.http
      .put(url, JSON.stringify(user), {headers: this.headers})
      .map(this.extractData)
      .catch(this.handleError);
  }

  addUser(user: User): Observable<User> {<commit_msg>Ajout template fonctions du user.service<commit_after>/**
 * Created by Khémon on 21/11/2016.
 */
import {Injectable, Inject} from '@angular/core';
import {Http, Headers, Response, RequestOptions} from '@angular/http';
import {User} from '../model/user';
import {Observable} from 'rxjs/Observable';
import {AppConfig, APP_CONFIG} from '../app-config';
import 'rxjs/Rx';

@Injectable()
export class UserService {
  private userUrl = 'user'
  private apiEndPoint;

  constructor(@Inject(APP_CONFIG) private config: AppConfig, private http: Http) {
    // Base URL for Talented API
    this.apiEndPoint = config.apiEndPoint;
  }

  /**
   * Retourne la liste des utilisateurs de la BDD
   */
  getUsers(): Observable<User[]>{
    return this.http.get(this.apiEndPoint + this.userUrl)
      .map(this.extractData)
      .catch(this.handleError);
  }

  /**
   * Retourne la liste des utilisateurs disponibles
   * aux alentours d'un job donné
   * Signature : getUsersAvailableByJob(Job job);
   */
  //getUsersAvailableByJob() : Observable<User[]>{}


  /**
   * Notifie l'utilisateur donné avec le message passé en paramètre
   * A réfléchir si on ajoute un type de message pour pouvoir créer des
   * templates de messages a envoyer aux utilisateurs
   * Signature : notifyUser(User user, String message)
   * Signature 2 : notifyUser(User user, int typeMessage)
   */
   //notifyUser() : void {}

  addUser(user: User): Observable<User> {
    let userString = JSON.stringify(user);
    let headers = new Headers({'Content-Type': 'application/json'});
    let options = new RequestOptions({headers: headers});
    return this.http.post(this.apiEndPoint + 'user/add', userString, options)
      .map(this.extractData)
      .catch(this.handleError);
  }
/*
  (id: numgetUserber): Observable<User> {
    return this.getUsers().
    subscribe(
      users => users.find(user => user.id === id)
    )
  }


  update(user: User): Observable<User> {
    const url = `${this.usersUrl}/${user.id}`;
    return this.http
      .put(url, JSON.stringify(user), {headers: this.headers})
      .map(this.extractData)
      .catch(this.handleError);
  }

  addUser(user: User): Observable<User> {
{'fraction_non_alphanumeric': 0.1431641149610529, 'fraction_numerical': 0.0045662100456621, 'mean_word_length': 3.626086956521739, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4905476', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1185, 'n_words': 296}