Skip to content
Commits on Source (7)
FROM openjdk:17
LABEL maintainer="ellyfiah@gmail.com"
COPY target/starWars-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
......@@ -4,6 +4,10 @@
*/
package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.domains.PiloteSpecifications;
import fr.ldnr.starWars.enumerations.EtatPilote;
import fr.ldnr.starWars.enumerations.GradePilote;
import fr.ldnr.starWars.enumerations.RacePilote;
import fr.ldnr.starWars.enumerations.TypePilote;
import fr.ldnr.starWars.services.PiloteService;
import org.springframework.stereotype.Controller;
......@@ -17,34 +21,45 @@ import org.springframework.web.bind.annotation.RequestParam;
* @author stag
*/
@Controller
public class ListePiloteController {
public class FilterPiloteController {
private final PiloteService piloteService;
public ListePiloteController(PiloteService piloteService) {
public FilterPiloteController(PiloteService piloteService) {
this.piloteService = piloteService;
}
@GetMapping("/listePilote")
public String listePilote(Model model) {
model.addAttribute("pilotes", piloteService.findAll());
model.addAttribute("typePilotes", piloteService.listType());
model.addAttribute("gradePilotes", piloteService.listGrade());
@GetMapping("/filterPilote")
public String filterPilote(Model model) {
model.addAttribute("etatPilotes", piloteService.listEtat());
model.addAttribute("gradePilotes", piloteService.listGrade());
model.addAttribute("typePilotes", piloteService.listType());
model.addAttribute("racePilotes", piloteService.listRace());
return "filterPilote";
}
@PostMapping("/filterPilote")
public String filterPilote(
Model model,
@RequestParam(value = "etatPilotes", required = false) String etatPilote,
@RequestParam(value = "gradePilotes", required = false) String gradePilote,
@RequestParam(value = "typePilotes", required = false) String typePilote,
@RequestParam(value = "racePilotes", required = false) String racePilote) {
// Validate the parameters if needed
EtatPilote etat = (etatPilote.equals("none")) ? null : EtatPilote.valueOf(etatPilote);
GradePilote grade = (gradePilote.equals("none")) ? null : GradePilote.valueOf(gradePilote);
TypePilote type = (typePilote.equals("none")) ? null : TypePilote.valueOf(typePilote);
RacePilote race = (racePilote.equals("none")) ? null : RacePilote.valueOf(racePilote);
System.out.println("etat" + etat);
model.addAttribute("pilotes", piloteService.findAll(PiloteSpecifications.findByParameters(etat, grade, type, race)));
System.out.println("pilotes filtered : " + piloteService.findAll(PiloteSpecifications.findByParameters(etat, grade, type, race)));
model.addAttribute("etatPilotes", piloteService.listEtat());
model.addAttribute("gradePilotes", piloteService.listGrade());
model.addAttribute("typePilotes", piloteService.listType());
model.addAttribute("racePilotes", piloteService.listRace());
return "listePilote";
return "filterPilote";
}
// @PostMapping("/listePilote")
// public String listePilote(Model model,
// @RequestParam(value = "typePilotes") String types,
// @RequestParam(value = "gradePilotes") String grades,
// @RequestParam(value = "etatPilotes") String etats,
// @RequestParam(value = "racePilotes") String races) {
// model.addAttribute("pilotes", piloteService.listType());
// model.addAttribute("typePilotes", piloteService.findByType(TypePilote.valueOf(types)));
// return "listePilote";
// }
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.enumerations.EtatPilote;
import fr.ldnr.starWars.enumerations.GradePilote;
import fr.ldnr.starWars.enumerations.TypePilote;
import fr.ldnr.starWars.services.PiloteService;
import java.util.ArrayList;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
*
* @author stag
*/
@Controller
public class ListePiloteParEtat {
private final PiloteService piloteService;
public ListePiloteParEtat(PiloteService piloteService) {
this.piloteService = piloteService;
}
@GetMapping("/listePiloteParEtat")
public String listePilote(Model model) {
model.addAttribute("etats", piloteService.listEtat());
return "listePiloteParEtat";
}
@PostMapping("/listePiloteParEtat")
public String listePilote(Model model, @RequestParam(value = "etats") String etats) {
model.addAttribute("etats", piloteService.listEtat());
// if (types.equals("all")) {
// model.addAttribute("pilotes", piloteService.findAll());
// }
model.addAttribute("pilotes", piloteService.findByEtat(EtatPilote.valueOf(etats)));
return "listePiloteParEtat";
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.enumerations.GradePilote;
import fr.ldnr.starWars.services.PiloteService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
*
* @author stag
*/
@Controller
public class ListePiloteParGrade {
private final PiloteService piloteService;
public ListePiloteParGrade(PiloteService piloteService) {
this.piloteService = piloteService;
}
@GetMapping("/listePiloteParGrade")
public String listePilote(Model model) {
model.addAttribute("grades", piloteService.listGrade());
return "listePiloteParGrade";
}
@PostMapping("/listePiloteParGrade")
public String listePilote(Model model, @RequestParam(value = "grades") String grades) {
model.addAttribute("grades", piloteService.listGrade());
// if (types.equals("all")) {
// model.addAttribute("pilotes", piloteService.findAll());
// }
model.addAttribute("pilotes", piloteService.findByGrade(GradePilote.valueOf(grades)));
return "listePiloteParGrade";
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package fr.ldnr.starWars.controllers;
import fr.ldnr.starWars.enumerations.TypePilote;
import fr.ldnr.starWars.services.PiloteService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
*
* @author stag
*/
@Controller
public class ListePiloteParType {
private final PiloteService piloteService;
public ListePiloteParType(PiloteService piloteService) {
this.piloteService = piloteService;
}
@GetMapping("/listePiloteParType")
public String listePilote(Model model) {
model.addAttribute("types", piloteService.listType());
return "listePiloteParType";
}
@PostMapping("/listePiloteParType")
public String listePilote(Model model, @RequestParam(value = "types") String types) {
model.addAttribute("types", piloteService.listType());
// if (types.equals("all")) {
// model.addAttribute("pilotes", piloteService.findAll());
// }
model.addAttribute("pilotes", piloteService.findByType(TypePilote.valueOf(types)));
return "listePiloteParType";
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package fr.ldnr.starWars.domains;
import fr.ldnr.starWars.enumerations.EtatPilote;
import fr.ldnr.starWars.enumerations.GradePilote;
import fr.ldnr.starWars.enumerations.RacePilote;
import fr.ldnr.starWars.enumerations.TypePilote;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;
import org.springframework.data.jpa.domain.Specification;
/**
*
* @author stag
*/
public class PiloteSpecifications {
public static Specification<Pilote> findByParameters(EtatPilote etat, GradePilote grade, TypePilote type, RacePilote race) {
return (root, query, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
if (etat != null) {
predicates.add(criteriaBuilder.equal(root.get("etat"), etat));
}
if (grade != null) {
predicates.add(criteriaBuilder.equal(root.get("grade"), grade));
}
if (type != null) {
predicates.add(criteriaBuilder.equal(root.get("type"), type));
}
if (race != null) {
predicates.add(criteriaBuilder.equal(root.get("race"), race));
}
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
};
}
}
......@@ -10,6 +10,7 @@ import fr.ldnr.starWars.enumerations.GradePilote;
import fr.ldnr.starWars.enumerations.RacePilote;
import fr.ldnr.starWars.enumerations.TypePilote;
import java.util.List;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
......@@ -36,4 +37,6 @@ public interface PiloteRepository extends CrudRepository<Pilote, Long> {
//List<Pilote> findByEtatInAndTypeIn(List<EtatPilote> etats, List<TypePilote> types);
List<Pilote> findByEtatAndType(EtatPilote etat, TypePilote type);
List<Pilote> findAll(Specification<Pilote> spec);
}
......@@ -10,6 +10,7 @@ import fr.ldnr.starWars.enumerations.GradePilote;
import fr.ldnr.starWars.enumerations.RacePilote;
import fr.ldnr.starWars.enumerations.TypePilote;
import java.util.List;
import org.springframework.data.jpa.domain.Specification;
/**
*
......@@ -45,4 +46,6 @@ public interface PiloteService {
public Pilote findById(Integer id_pilote);
public List<Pilote> findAll(Specification<Pilote> spec);
}
......@@ -5,6 +5,7 @@
package fr.ldnr.starWars.services;
import fr.ldnr.starWars.domains.Pilote;
import fr.ldnr.starWars.domains.PiloteSpecifications;
import fr.ldnr.starWars.enumerations.EtatPilote;
import fr.ldnr.starWars.enumerations.GradePilote;
import fr.ldnr.starWars.enumerations.RacePilote;
......@@ -14,6 +15,8 @@ import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.util.Arrays;
import java.util.List;
import org.springframework.data.jpa.domain.Specification;
import static org.springframework.data.util.TypeUtils.type;
import org.springframework.stereotype.Service;
/**
......@@ -82,6 +85,7 @@ public class PiloteServiceImpl implements PiloteService {
public List<Pilote> findByNom(String nom) {
return piloteRepository.findByNom(nom);
}
@Override
public List<Pilote> findByNomAndPrenom(String nom, String prenom) {
return piloteRepository.findByNomAndPrenom(nom, prenom);
......@@ -107,4 +111,9 @@ public class PiloteServiceImpl implements PiloteService {
return piloteRepository.findByEtatAndType(etat, type);
}
@Override
public List<Pilote> findAll(Specification<Pilote> spec) {
return piloteRepository.findAll(spec);
}
}
......@@ -5,7 +5,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>liste pilote</title>
<title>Filter Pilote</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/style.css"/>
......@@ -16,14 +16,41 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
</head>
<body>
<header>
<h1>Trier des Pilotes</h1>
<h1><span class='faulty-letter'>{</span> Liste des Pilotes par Tri</h1>
</header>
<main>
<div class="tri">
<a th:href="@{/listePiloteParType}"><p>Trier par rang</p></a>
<a th:href="@{/listePiloteParGrade}"><p>Trier par grade</p></a>
<a th:href="@{/listePiloteParEtat}"><p>Trier par etat</p></a>
<form action="/filterPilote" method="post">
<div>
<label for="etatPilotes">Choisir un etat :</label>
<select id="etatPilotes" name="etatPilotes">
<option value="none">Tous</option>
<option th:each="etatPilote : ${etatPilotes}" th:value="${etatPilote}" th:text="${etatPilote}"></option>
</select>
</div>
<div>
<label for="gradePilotes">Choisir un grade :</label>
<select id="gradePilotes" name="gradePilotes">
<option value="none">Tous</option>
<option th:each="gradePilote : ${gradePilotes}" th:value="${gradePilote}" th:text="${gradePilote}"></option>
</select>
</div>
<div>
<label for="typePilotes">Choisir un type :</label>
<select id="typePilotes" name="typePilotes">
<option value="none">Tous</option>
<option th:each="typePilote : ${typePilotes}" th:value="${typePilote}" th:text="${typePilote}"></option>
</select>
</div>
<div>
<label for="racePilotes">Choisir une race :</label>
<select id="racePilotes" name="racePilotes">
<option value="none">Tous</option>
<option th:each="racePilote : ${racePilotes}" th:value="${racePilote}" th:text="${racePilote}"></option>
</select>
</div>
<input type="submit" value="Trier"/>
<input type="reset" value="Annuler"/>
</form>
<table>
<tr>
......@@ -49,7 +76,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<td th:text="${pilote.type}"></td>
<td th:text="${pilote.etat}"></td>
<td>
<a th:href="'/fichePilote?id_pilote=' + ${pilote.idPilote}" th:text="Fiche_Pilote">
<a th:href="'/fichePilote?id_pilote=' + ${pilote.idPilote}" th:text="Fiche_Chasseur">
</a>
</td>
</tr>
......
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Liste Pilote</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/style.css"/>
<link href="https://fonts.cdnfonts.com/css/star-wars" rel="stylesheet">
<style>
@import url('https://fonts.cdnfonts.com/css/star-wars');
</style>
</head>
<body>
<header>
<h1><span class='faulty-letter'>{</span> Liste des pilotes par etat</h1>
</header>
<main>
<form action="/listePiloteParEtat" method="post">
<div>
<label for="etats">Choisir un etat :</label>
<select id="etats" name="etats">
<option th:each="etat : ${etats}" th:value="${etat}" th:text="${etat}"></option>
</select>
<input type="submit" value="Trier"/>
</div>
</form>
<table>
<tr>
<th>Id pilote</th>
<th>Nom</th>
<th>Prenom</th>
<th>Age</th>
<th>Race</th>
<th>Grade</th>
<th>Type</th>
<th>Etat</th>
</tr>
<tr th:each="pilote : ${pilotes}">
<td>
<a th:href="'/fichePilote?id_pilote=' + ${pilote.idPilote}" th:text="${pilote.idPilote}">
</a>
</td>
<td th:text="${pilote.nom}"></td>
<td th:text="${pilote.prenom}"></td>
<td th:text="${pilote.age}"></td>
<td th:text="${pilote.race}"></td>
<td th:text="${pilote.grade}"></td>
<td th:text="${pilote.type}"></td>
<td th:text="${pilote.etat}"></td>
</tr>
</table>
<p>
<a href="/listePilote">Retour aux pilotes</a>
</p>
</main>
<footer>
<a href="/menu" class="menu">Retour au Menu</a>
</footer>
</body>
</html>
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/style.css"/>
<link href="https://fonts.cdnfonts.com/css/star-wars" rel="stylesheet">
<style>
@import url('https://fonts.cdnfonts.com/css/star-wars');
</style>
</head>
<body>
<header>
<h1><span class='faulty-letter'>{</span> Liste des pilotes par grades</h1>
</header>
<main>
<form action="/listePiloteParGrade" method="post">
<div>
<label for="grades">Choisir un grade :</label>
<select id="grades" name="grades">
<option th:each="grade : ${grades}" th:value="${grade}" th:text="${grade}"></option>
</select>
<input type="submit" value="Trier"/>
</div>
</form>
<table>
<tr>
<th>Id pilote</th>
<th>Nom</th>
<th>Prenom</th>
<th>Age</th>
<th>Race</th>
<th>Grade</th>
<th>Type</th>
<th>Etat</th>
</tr>
<tr th:each="pilote : ${pilotes}">
<td>
<a th:href="'/fichePilote?id_pilote=' + ${pilote.idPilote}" th:text="${pilote.idPilote}">
</a>
</td>
<td th:text="${pilote.nom}"></td>
<td th:text="${pilote.prenom}"></td>
<td th:text="${pilote.age}"></td>
<td th:text="${pilote.race}"></td>
<td th:text="${pilote.grade}"></td>
<td th:text="${pilote.type}"></td>
<td th:text="${pilote.etat}"></td>
</tr>
</table>
<p>
<a href="/listePilote">retour aux pilotes</a>
</p>
</main>
<footer>
<a href="/menu" class="menu">Retour au Menu</a>
</footer>
</body>
</html>
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/style.css"/>
<link href="https://fonts.cdnfonts.com/css/star-wars" rel="stylesheet">
<style>
@import url('https://fonts.cdnfonts.com/css/star-wars');
</style>
</head>
<body>
<header>
<h1><span class='faulty-letter'>{</span> Liste des pilotes par rang</h1>
</header>
<main>
<form action="/listePiloteParType" method="post">
<div>
<label for="types">choisir un rang :</label>
<select id="types" name="types">
<option th:each="type : ${types}" th:value="${type}" th:text="${type}"></option>
</select>
<input type="submit" value="Trier"/>
</div>
</form>
<table>
<tr>
<th>Id pilote</th>
<th>Nom</th>
<th>Prenom</th>
<th>Age</th>
<th>Race</th>
<th>Grade</th>
<th>Type</th>
<th>Etat</th>
</tr>
<tr th:each="pilote : ${pilotes}">
<td>
<a th:href="'/fichePilote?id_pilote=' + ${pilote.idPilote}" th:text="${pilote.idPilote}">
</a>
</td>
<td th:text="${pilote.nom}"></td>
<td th:text="${pilote.prenom}"></td>
<td th:text="${pilote.age}"></td>
<td th:text="${pilote.race}"></td>
<td th:text="${pilote.grade}"></td>
<td th:text="${pilote.type}"></td>
<td th:text="${pilote.etat}"></td>
</tr>
</table>
<p>
<a href="/listePilote">Retour aux pilotes</a>
</p>
</main>
<footer>
<a href="/menu" class="menu">Retour au Menu</a>
</footer>
</body>
</html>
......@@ -21,7 +21,7 @@ Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this temp
<h2>Pilote</h2>
<ul>
<li><a href="/inscriptionPilote" class="menu">Inscription d'un nouveau pilote</a></li>
<li><a href="/listePilote" class="menu">Liste des pilotes</a></li>
<li><a href="/filterPilote" class="menu">Liste des pilotes</a></li>
<li><a href="/cherchePilote" class="menu">Cherche pilote par nom</a></li>
</ul>
......
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Modifier Etat Chasseur</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<h1><span class='faulty-letter'>{</span> Modifier Etat Chasseur</h1>
<form action="/modifierEtatChasseur" method="post">
<div>
<label for="etat">Etat du chasseur</label>
<select id="etat" name="etat">
<option th:each="chasseur : ${chasseur}" th:value="${chasseur.etat}" th:text="${chasseur.etat}"></option>
</select>
</div>
<input type="submit" value="Modifier"/>
</form>
<a th:href="@{/listeChasseur}">Retour à la liste des chasseurs</a>
</body>
</html>