|
|
|
@ -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 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|