From c12eb0c654a6b702680b3b398fccbe93e651dee3 Mon Sep 17 00:00:00 2001 From: lchandellier Date: Fri, 26 Jun 2020 12:15:52 +0200 Subject: [PATCH] =?UTF-8?q?impl=C3=A9mentation=20des=20premi=C3=A8res=20fo?= =?UTF-8?q?nctions=20des=20controleurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollaborateurControlleur.cs | 6 +- Controllers/EpController/EPController.cs | 24 ++++++- .../FormationController.cs | 69 ++++++++++++++++++- 3 files changed, 95 insertions(+), 4 deletions(-) diff --git a/Controllers/CollaborateurController/CollaborateurControlleur.cs b/Controllers/CollaborateurController/CollaborateurControlleur.cs index 2a9e03b..dbfabdb 100644 --- a/Controllers/CollaborateurController/CollaborateurControlleur.cs +++ b/Controllers/CollaborateurController/CollaborateurControlleur.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using EPAServeur.BDAccess; using EPAServeur.CollaborateurModele.Collaborateur; +using EPAServeur.Commun; using Microsoft.AspNetCore.Mvc; using MySql.Data.MySqlClient; @@ -11,9 +12,10 @@ namespace EPAServeur.Controllers.CollaborateurController public class CollaborateurControlleur : ControllerBase { [HttpGet("collaborateurs")] - public IEnumerable Get() + public IEnumerable Get(string token) { - List liste = APIAccess.requestAPI("/personne"); + KeycloakAuthentificator.IsvalidToken(token); + List liste = APIAccess.requestGetAPI("/personne"); return liste; } } diff --git a/Controllers/EpController/EPController.cs b/Controllers/EpController/EPController.cs index cbc31b4..26ade24 100644 --- a/Controllers/EpController/EPController.cs +++ b/Controllers/EpController/EPController.cs @@ -2,14 +2,36 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using EPAServeur.Commun; +using EPAServeur.Modele.EpModele; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using MySql.Data.MySqlClient; +using Org.BouncyCastle.Bcpg; namespace EPAServeur.Controllers.EpController { - [Route("api/[controller]")] + [Route("api/ep/")] [ApiController] public class EPController : ControllerBase { + [HttpGet("evaluation")] + public IEnumerable Get(string token) + { + KeycloakAuthentificator.IsvalidToken(token); + List retour = new List(); + string query = "select ce.Libelle, ev.note, ev.Commentaire" + + " from participation_formation pf " + + " inner join Evaluation ev on pf.IdParticipation = ev.IdParticipation " + + " inner join critere_evaluation ce on ce.IdCritère = ev.IdCritère " + + " inner join ep on ep.IdEP = pf.IdEP " + + " left join participant p on(p.IdEP = ep.IdEP and p.idRole = 'collaborateur');"; + MySqlDataReader liste = BDAccess.BDAccess.executeQuery(query); + while (liste.Read()) + { + retour.Add(new evaluation((string) liste.GetValue(0), int.Parse((string)liste.GetValue(1)), (string) liste.GetValue(2))); + } + return retour; + } } } diff --git a/Controllers/FormationController/FormationController.cs b/Controllers/FormationController/FormationController.cs index 9861d74..5c09f1e 100644 --- a/Controllers/FormationController/FormationController.cs +++ b/Controllers/FormationController/FormationController.cs @@ -1,15 +1,82 @@ using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Threading.Tasks; +using EPAServeur.Commun; +using EPAServeur.Modele.FormationModele; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using MySql.Data.MySqlClient; namespace EPAServeur.Controllers.FormationController { - [Route("api/[controller]")] + [Route("api/")] [ApiController] public class FormationController : ControllerBase { + [HttpGet("formations")] + public IEnumerable Get(string token) + { + if (!KeycloakAuthentificator.IsvalidToken(token)) + { + return null; + } + + List retour = new List(); + string query = "SELECT IdFormation,Intitulé,DateDebut,DateFin,Statut,Lieu,Duree,Organisme,NomFormateur " + + " FROM formation ;"; + MySqlDataReader queryResult = BDAccess.BDAccess.executeQuery(query); + while (queryResult.Read()) + { + retour.Add(new Formation( + queryResult.GetInt32(0), //id + queryResult.GetString(1), // intitulé + queryResult.GetDateTime(2), //DateDebut + queryResult.GetDateTime(3), // dateFin + queryResult.GetString(4), //status + queryResult.GetString(5), //lieu + queryResult.GetString(6), //durée + queryResult.GetString(7), //organisme + queryResult.GetString(8) //nomformateur + )); + } + return retour; + } + + [HttpGet("formation")] + public Formation Get(int id, string token) + { + KeycloakAuthentificator.IsvalidToken(token); + + Formation retour; + string query = "SELECT IdFormation,Intitulé,DateDebut,DateFin,Statut,Lieu,Duree,Organisme,NomFormateur " + + " FROM formation " + + $" where IdFormation={id};"; + MySqlDataReader queryResult = BDAccess.BDAccess.executeQuery(query); + queryResult.Read(); + retour = new Formation( + queryResult.GetInt32(0), //id + queryResult.GetString(1), //intitulé + queryResult.GetDateTime(2), //dateDebut + queryResult.GetDateTime(3), //dateFin + queryResult.GetString(4), //status + queryResult.GetString(5), //lieu + queryResult.GetString(6), //durée + queryResult.GetString(7), //organisme + queryResult.GetString(8) //nomformateur + ); + return retour; + } + + [HttpPost("formation/new")] + public Formation Post(string token) + { + KeycloakAuthentificator.IsvalidToken(token); + + Formation formation = new Formation(-1, Request.Form["intitule"], DateTime.Parse(Request.Form["dateDebut"]), DateTime.Parse(Request.Form["dateFin"]), Request.Form["statut"], Request.Form["lieu"], Request.Form["duree"], Request.Form["organisme"], Request.Form["nomFormateur"]); + BDAccess.BDAccess.executeQuery(formation.generateInsertStatement()); + return this.Get(1, token); // TODO : retourner la formation que l'on vient de créer + } } }