From 9c85714fd6c1255b71cbbe9771abf35c113d0e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yana=C3=ABl=20GRETTE?= Date: Wed, 24 Jun 2020 13:11:14 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20headers=20dans=20les=20services?= =?UTF-8?q?=20avec=20quelques=20tests=20(il=20est=20pr=C3=A9f=C3=A9rable?= =?UTF-8?q?=20d'avoir=20acc=C3=A8s=20=C3=A0=20la=20base=20de=20donn=C3=A9e?= =?UTF-8?q?s=20pour=20le=20reste=20des=20tests)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home-assistante.component.ts | 33 +----- src/app/home/home.component.ts | 111 +++++++++++++++++- src/app/modeles/modele-collaborateur.ts | 4 +- src/app/modeles/modele-ep.ts | 4 +- src/app/modeles/modele-formation.ts | 8 +- src/app/service/service-collaborateur.ts | 14 ++- src/app/service/service-ep.ts | 50 ++++++-- src/app/service/service-formation.ts | 56 ++++++--- src/environments/environment.ts | 3 +- 9 files changed, 212 insertions(+), 71 deletions(-) diff --git a/src/app/home/home-assistante/home-assistante.component.ts b/src/app/home/home-assistante/home-assistante.component.ts index 0971b87..1f80c4a 100644 --- a/src/app/home/home-assistante/home-assistante.component.ts +++ b/src/app/home/home-assistante/home-assistante.component.ts @@ -1,8 +1,5 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; -import { Observable, Subscription } from 'rxjs'; -import { ServiceCollaborateur } from "../../service"; -import { CollaborateurModel } from "../../modeles/modele-collaborateur"; @Component({ selector : 'home-assistante', @@ -10,39 +7,17 @@ import { CollaborateurModel } from "../../modeles/modele-collaborateur"; }) export class HomeAssistanteComponent implements OnInit { - private collabListSubscription : Subscription; - private collab1Subscription : Subscription; - private collab2Subscription : Subscription; - private listeCollaborateurs : CollaborateurModel[]; - constructor(private serviceCollaborateur : ServiceCollaborateur) { - this.collabListSubscription = this.serviceCollaborateur.listeCollaborateurs(). - subscribe(collaborateurs => this.test(collaborateurs)); - let params = { mail : "angelique@apside.com"}; - this.collab1Subscription = this.serviceCollaborateur.getCollaborateurByParam(params). - subscribe(collaborateurs => this.test2(collaborateurs)); - let params2 = { id : 1 }; - this.collab2Subscription = this.serviceCollaborateur.getCollaborateurByParam(params2). - subscribe(collaborateurs => this.test2(collaborateurs)); + + constructor() { + } - test(collaborateurs) { - for(let collaborateur of collaborateurs) { - console.log(collaborateur); - } - } - test2(collaborateur) { - console.log(collaborateur); - } ngOnInit() { } - ngOnDestroy() { - if(this.collabListSubscription != null) { - this.collabListSubscription.unsubscribe(); - } - } + } diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 7e12d92..8bf9b05 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,6 +1,13 @@ import { Component, OnInit } from '@angular/core'; import { KeycloakService } from 'keycloak-angular'; +import { Observable, Subscription } from 'rxjs'; + +import { ServiceCollaborateur, ServiceFormation, ServiceEP } from "../service"; +import { CollaborateurModel } from "../modeles/modele-collaborateur"; +import { FormationModel } from "../modeles/modele-formation"; +import { EpModel } from "../modeles/modele-ep"; + /* import { HomeAssistanteComponent } from './home-assistante/home-assistante.component'; @@ -18,12 +25,112 @@ import { Role } from '../utils/roles'; export class HomeComponent implements OnInit { role = Role; - constructor(public keycloakService : KeycloakService) { + /*private collabListSubscription : Subscription; + private collab1Subscription : Subscription; + private collab2Subscription : Subscription; + private listeCollaborateurs : CollaborateurModel[]; + private formationSubscription : Subscription; + private addFormationSubscription : Subscription; + */ + private epEnvoieSubscription : Subscription; + private epCollaborateurSubscription : Subscription; + private epDisponiblesSubscription : Subscription; + private epCollaborateurProchain : Subscription; + constructor(public keycloakService : KeycloakService, private serviceCollaborateur : ServiceCollaborateur, + private serviceFormation : ServiceFormation, private serviceEP : ServiceEP) { + + //********TEST********// + let ep = new EpModel(); + ep.id = 10; + ep.type ="EPA"; + //ep.dateDisponibilite = new Date(2020,0,5,25,30); + ep.dateDisponibilite = new Date(2020,0,0,25,30); + ep.etat = "créer"; + let collaborateur = new CollaborateurModel(); + collaborateur.id = 1; + collaborateur.nom = "GRETTE"; + collaborateur.prenom = "Yanaël"; + collaborateur.mail = "yanael.grette@apside-groupe.com"; + collaborateur.agence = "Orléans"; + collaborateur.fonction = "Stagiaire"; + + ep.collaborateur = collaborateur; + this.epEnvoieSubscription = this.serviceEP.envoieEP(ep, "saisie"). + subscribe(eps => this.display(eps)); + //this.epCollaborateurProchain = this.serviceEP.prochainEPCollaborateur(3). + //subscribe(eps => this.display(eps)); + //this.epCollaborateurSubscription = this.serviceEP.listeEPCollaborateur(1). + //subscribe(eps => this.display(eps)); + //this.epDisponiblesSubscription = this.serviceEP.listeEPDisponibles(). + // subscribe(eps => this.display(eps)); + /* + let formation = new FormationModel(); + formation.intitule = "TestJAVA"; + formation.dateDebut = new Date("10-12-2020"); + formation.dateFin = new Date("10-12-2020"); + formation.statut = "Prévue"; + formation.lieu = "Orléans"; + formation.duree = 5; + formation.organisme = "Apside"; + formation.nomFormateur = "Patrick"; + console.log(formation.dateDebut); + this.addFormationSubscription = this.serviceFormation.nouvelleFormation(formation) + .subscribe(); + this.formationSubscription = this.serviceFormation.listeFormations() + .subscribe(formations=> this.display(formations)); + /* + this.collabListSubscription = this.serviceCollaborateur.listeCollaborateurs(token). + subscribe(collaborateurs => this.test(collaborateurs)); + let params = { mail : "angelique@apside.com"}; + this.collab1Subscription = this.serviceCollaborateur.getCollaborateurByParam(token,params). + subscribe(collaborateurs => this.test2(collaborateurs)); + let params2 = { id : 1 }; + this.collab2Subscription = this.serviceCollaborateur.getCollaborateurByParam(token,params2). + subscribe(collaborateurs => this.test2(collaborateurs)); + + console.log(token);* + //*/ } + display(listes) { + for(let l of listes) { + console.log(l); + } + } +/* + test2(collaborateur) { + console.log(collaborateur); + } + +*/ ngOnInit() { } - + ngOnDestroy() { + /*if(this.collabListSubscription != null) { + this.collabListSubscription.unsubscribe(); + }*/ + /* + if(this.formationSubscription != null) { + this.formationSubscription.unsubscribe(); + } + if(this.addFormationSubscription != null) { + this.addFormationSubscription.unsubscribe(); + } + */ + if(this.epEnvoieSubscription != null) { + this.epEnvoieSubscription.unsubscribe(); + } + if(this.epCollaborateurSubscription != null) { + this.epCollaborateurSubscription.unsubscribe(); + } + if(this.epDisponiblesSubscription != null) { + this.epDisponiblesSubscription.unsubscribe(); + } + if(this.epCollaborateurProchain != null) { + this.epCollaborateurProchain.unsubscribe(); + } + + } } diff --git a/src/app/modeles/modele-collaborateur.ts b/src/app/modeles/modele-collaborateur.ts index f063bdd..75ac52b 100644 --- a/src/app/modeles/modele-collaborateur.ts +++ b/src/app/modeles/modele-collaborateur.ts @@ -2,8 +2,8 @@ export class CollaborateurModel { id? : number; nom? : string; prenom? : string; - adresse? : string; - agence? : string; mail? : string; + agence? : string; + dateEmbauche? : Date; fonction? : string; }; diff --git a/src/app/modeles/modele-ep.ts b/src/app/modeles/modele-ep.ts index 5ea69ff..02c78aa 100644 --- a/src/app/modeles/modele-ep.ts +++ b/src/app/modeles/modele-ep.ts @@ -1,7 +1,7 @@ import { CollaborateurModel } from "./modele-collaborateur"; -export interface EpModel { - idEp? : number; +export class EpModel { + id? : number; type? : string; dateDisponibilite? : Date; dateSaisie? : Date; diff --git a/src/app/modeles/modele-formation.ts b/src/app/modeles/modele-formation.ts index 3a26d33..a716a6c 100644 --- a/src/app/modeles/modele-formation.ts +++ b/src/app/modeles/modele-formation.ts @@ -1,5 +1,5 @@ -export interface FormationModel { - idFormation? : number; +export class FormationModel { + id? : number; intitule? : string; dateDebut? : Date; dateFin? : Date; @@ -11,7 +11,7 @@ export interface FormationModel { }; -export interface DemandeFormationModel { +export class DemandeFormationModel { idDemandeFormation? : number; idEp? : number; statut? : string; @@ -26,6 +26,6 @@ export interface ThemeModel { nom : string; }; -export interface EvaluationFormationModel { +export class EvaluationFormationModel { //TODO } diff --git a/src/app/service/service-collaborateur.ts b/src/app/service/service-collaborateur.ts index e8a6b4e..0e97c49 100644 --- a/src/app/service/service-collaborateur.ts +++ b/src/app/service/service-collaborateur.ts @@ -2,6 +2,10 @@ import { Injectable } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; + + +import { KeycloakService } from 'keycloak-angular'; + import { urlCollaborateur } from "../utils/path-values-collaborateurs"; import { CollaborateurModel } from "../modeles/modele-collaborateur"; @@ -9,15 +13,19 @@ import { CollaborateurModel } from "../modeles/modele-collaborateur"; providedIn : 'root' }) export class ServiceCollaborateur { - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private keycloakService : KeycloakService) { } listeCollaborateurs() : Observable { - return this.http.get(urlCollaborateur); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlCollaborateur, { headers }); } getCollaborateurByParam(params) : Observable { - return this.http.get(urlCollaborateur, { params }); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlCollaborateur, { params, headers }); } } diff --git a/src/app/service/service-ep.ts b/src/app/service/service-ep.ts index c729a7d..5db0f56 100644 --- a/src/app/service/service-ep.ts +++ b/src/app/service/service-ep.ts @@ -2,6 +2,8 @@ import { Injectable } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { Observable } from 'rxjs'; +import { KeycloakService } from 'keycloak-angular'; + import { urlsEP } from "../utils/path-values-ep"; import { EpModel, RDVEntretienModel } from "../modeles/modele-ep"; @@ -9,51 +11,73 @@ import { EpModel, RDVEntretienModel } from "../modeles/modele-ep"; providedIn : 'root' }) export class ServiceEP { - constructor(private http: HttpClient) { - - } + constructor(private http: HttpClient, private keycloakService : KeycloakService) {} listeProchainsEPReferent(id) : Observable { + let token = this.keycloakService.getKeycloakInstance().token; let params = { idReferent : id }; - return this.http.get(urlsEP.prochainsEPReferent, { params }); + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlsEP.prochainsEPReferent, { params, headers }); } listeEPDisponibles() : Observable { - return this.http.get(urlsEP.epDisponibles); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlsEP.epDisponibles, {headers}); } listeEPCollaborateur(id) : Observable { + let token = this.keycloakService.getKeycloakInstance().token; let params = { idCollab : id }; - return this.http.get(urlsEP.epCollaborateur, {params}); + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlsEP.epCollaborateur, {params, headers}); } listeEPReferent(id) : Observable { + let token = this.keycloakService.getKeycloakInstance().token; let params = { idReferent : id }; - return this.http.get(urlsEP.epReferent); + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlsEP.epReferent, { params, headers}); } prochainEPCollaborateur(id) : Observable { + let token = this.keycloakService.getKeycloakInstance().token; let params = { idCollab : id }; - return this.http.get(urlsEP.prochainEpCollaborateur); + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlsEP.prochainEpCollaborateur, { params, headers}); } envoieEP(ep : EpModel, action) { - let params = { action : action }; - return this.http.post(urlsEP.envoieEP, ep, {params}); + let token = this.keycloakService.getKeycloakInstance().token; + let params = { action }; + const headers = { + Authorization: "Bearer "+token, + ContentType: "application/json" + }; + return this.http.put(urlsEP.envoieEP, ep, {params, headers}); } propositionDate(dates) { - return this.http.post(urlsEP.propositionDate, dates); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { + Authorization: "Bearer "+token, + ContentType: "application/json" + }; + return this.http.post(urlsEP.propositionDate, dates, {headers}); } rappelerSignature(id) { + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; let params = { idEp : id }; - return this.http.get(urlsEP.rappelSignature, {params}); + return this.http.post(urlsEP.rappelSignature, null, {params, headers}); } demandeEPI(id) { + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; let params = { IdCollab : id }; - return this.http.post(urlsEP.epi, params); + return this.http.post(urlsEP.epi, null, { params, headers}); } diff --git a/src/app/service/service-formation.ts b/src/app/service/service-formation.ts index e364464..96ac4ab 100644 --- a/src/app/service/service-formation.ts +++ b/src/app/service/service-formation.ts @@ -2,6 +2,8 @@ import { Injectable } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs"; +import { KeycloakService } from 'keycloak-angular'; + import {FormationModel, DemandeFormationModel, EvaluationFormationModel, ThemeModel } from "../modeles/modele-formation"; import { urlsFormation } from "../utils/path-values-formations"; @@ -9,53 +11,79 @@ import { urlsFormation } from "../utils/path-values-formations"; providedIn : 'root' }) export class ServiceFormation { - constructor(private http: HttpClient) { - - } + constructor(private http: HttpClient, private keycloakService : KeycloakService) {} listeFormations() : Observable { - return this.http.get(urlsFormation.urlFormation); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlsFormation.urlFormation, {headers}); } listeFormationsCollaborateur(id) : Observable { + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; let params = { idCollab : id }; - return this.http.get(urlsFormation.urlFormation, { params }); + return this.http.get(urlsFormation.urlFormation, { params, headers }); } nouvelleFormation(formation) : Observable { - return this.http.post(urlsFormation.newFormation, formation); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { + Authorization: "Bearer "+token, + ContentType: "application/json" + }; + return this.http.post(urlsFormation.newFormation, formation, {headers}); } updateFormation(formation) : Observable { - return this.http.post(urlsFormation.newFormation, formation); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { + Authorization: "Bearer "+token, + ContentType: "application/json" + }; + return this.http.put(urlsFormation.newFormation, formation, {headers}); } deleteFormation(id) { + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; let params = { idFormation : id }; - return this.http.delete(urlsFormation.urlFormation); + return this.http.delete(urlsFormation.urlFormation, {headers, params}); } evaluationsFormation(id) : Observable { + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; let params = { idFormation : id }; - return this.http.get(urlsFormation.evaluationsFormation); + return this.http.get(urlsFormation.evaluationsFormation, {headers, params}); } evaluerFormation(evaluation) { - return this.http.post(urlsFormation.evaluerFormation, evaluation); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { + Authorization: "Bearer "+token, + ContentType: "application/json" + }; + return this.http.post(urlsFormation.evaluerFormation, evaluation, {headers}); } listeDemandesFormation() : Observable { - return this.http.get(urlsFormation.urlDemandesFormation); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlsFormation.urlDemandesFormation, {headers}); } reponseDemandeFormation(demandeFormation) { - return this.http.post(urlsFormation.urlDemandesFormation, demandeFormation); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; + return this.http.post(urlsFormation.urlDemandesFormation, demandeFormation, {headers}); } listeTheme() : Observable { - return this.http.get(urlsFormation.urlTheme); + let token = this.keycloakService.getKeycloakInstance().token; + const headers = { Authorization: "Bearer "+token }; + return this.http.get(urlsFormation.urlTheme, {headers}); } - } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index aa3d9d6..883a48e 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -12,8 +12,7 @@ const keycloakConfig: KeycloakConfig = { }; const serveurConfig = { - url : "http://localhost:3000" - //url : "http:localhost:3000/api" + url : "http://localhost:3000/api" } export const environment = {