implémentation des premières fonctions des controleurs

master
lchandellier 4 years ago
parent 0e6965c3dc
commit c12eb0c654
  1. 6
      Controllers/CollaborateurController/CollaborateurControlleur.cs
  2. 24
      Controllers/EpController/EPController.cs
  3. 69
      Controllers/FormationController/FormationController.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<Collaborateur> Get()
public IEnumerable<Collaborateur> Get(string token)
{
List<Collaborateur> liste = APIAccess.requestAPI<Collaborateur>("/personne");
KeycloakAuthentificator.IsvalidToken(token);
List<Collaborateur> liste = APIAccess.requestGetAPI<Collaborateur>("/personne");
return liste;
}
}

@ -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<evaluation> Get(string token)
{
KeycloakAuthentificator.IsvalidToken(token);
List<evaluation> retour = new List<evaluation>();
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;
}
}
}

@ -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<Formation> Get(string token)
{
if (!KeycloakAuthentificator.IsvalidToken(token))
{
return null;
}
List<Formation> retour = new List<Formation>();
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
}
}
}

Loading…
Cancel
Save