1- import { HttpClient } from '@angular/common/http' ;
1+ import { HttpClient , HttpRequest } from '@angular/common/http' ;
22import { Injectable } from '@angular/core' ;
3+ import { Utilisateur } from 'app/model/utilisateur' ;
34import { Observable } from 'rxjs' ;
45
56@Injectable ( {
@@ -9,24 +10,30 @@ export class UtilisateurService {
910
1011 private BASE_URL = "http://localhost:8080/utilisateurs"
1112
12- constructor ( private httpClient :HttpClient ) { }
13-
14- public findAll ( ) : Observable < any >
15- { return this . httpClient . get ( this . BASE_URL ) ; }
16-
17- public save ( utilisateur :any ) : Observable < any >
18- { return this . httpClient . post ( this . BASE_URL , utilisateur ) ; }
13+ constructor ( private httpClient : HttpClient ) { }
14+
15+ public findAll ( ) : Observable < any > { return this . httpClient . get ( this . BASE_URL ) ; }
16+
17+ public save ( image : File , utilisateur : Utilisateur ) : Observable < any > {
18+ const formData = new FormData ( ) ; //permet d'utiliser le resquestParam de la méthode save de la partie back
19+ formData . append ( 'nomFront' , utilisateur . nomUtilisateur ) ;
20+ formData . append ( 'prenomFront' , utilisateur . prenomUtilisateur ) ;
21+ formData . append ( 'usernameFront' , utilisateur . username ) ;
22+ formData . append ( 'passwordFront' , utilisateur . password ) ;
23+ formData . append ( 'imageFront' , image ) ;
24+ const requestHttp = new HttpRequest ( 'POST' , this . BASE_URL , formData , {
25+ reportProgress : true , responseType : 'text'
26+ } )
27+ return this . httpClient . request ( requestHttp ) ;
28+ }
1929
20- public delete ( id :number ) : Observable < any >
21- { return this . httpClient . delete ( this . BASE_URL + "/" + id ) ; }
30+ public delete ( id : number ) : Observable < any > { return this . httpClient . delete ( this . BASE_URL + "/" + id ) ; }
2231
23- public findOne ( id :number ) : Observable < any >
24- { return this . httpClient . get ( this . BASE_URL + "/" + id ) ; }
32+ public findOne ( id : number ) : Observable < any > { return this . httpClient . get ( this . BASE_URL + "/" + id ) ; }
2533
26- public findOneUsername ( username :string ) : Observable < any >
27- { return this . httpClient . get ( this . BASE_URL + "/" + username ) ; }
34+ public findOneUsername ( username : string ) : Observable < any > { return this . httpClient . get ( this . BASE_URL + "/" + username ) ; }
2835
29- public update ( utilisateur :any ) :Observable < any > {
36+ public update ( utilisateur : any ) : Observable < any > {
3037 var utilisateurJSON = JSON . parse ( utilisateur ) ;
3138 return this . httpClient . put ( this . BASE_URL + "/" + utilisateurJSON . idUtilisateur , utilisateurJSON ) ;
3239 }
0 commit comments