Merge branch 'Johan' of https://gitlab.com/marvin.epip/enchere into Johan
This commit is contained in:
@@ -1,16 +1,23 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
|
id 'application'
|
||||||
id 'org.springframework.boot' version '3.2.3'
|
id 'org.springframework.boot' version '3.2.3'
|
||||||
id 'io.spring.dependency-management' version '1.1.4'
|
id 'io.spring.dependency-management' version '1.1.4'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'fr.eni'
|
group = 'fr.eni'
|
||||||
version = '0.0.1-SNAPSHOT'
|
version = '1.0.0'
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = '17'
|
sourceCompatibility = '17'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes 'Main-Class': 'fr.eni.enchere.EnchereApplication'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,7 @@ import java.util.List;
|
|||||||
public interface CategorieService {
|
public interface CategorieService {
|
||||||
List<fr.eni.enchere.bo.Categorie> findAllCategories();
|
List<fr.eni.enchere.bo.Categorie> findAllCategories();
|
||||||
Categorie findCategorieById(int id);
|
Categorie findCategorieById(int id);
|
||||||
|
void saveCategorie(Categorie categorie);
|
||||||
|
void updateCategorie(Categorie categorie);
|
||||||
|
void deleteCategorie(int id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,5 +28,20 @@ public class CategorieServiceImpl implements CategorieService {
|
|||||||
return categorieRepository.findCategorieById(id);
|
return categorieRepository.findCategorieById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveCategorie(Categorie categorie) {
|
||||||
|
categorieRepository.saveCategorie(categorie);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateCategorie(Categorie categorie) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteCategorie(int id) {
|
||||||
|
categorieRepository.deleteCategorie(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,19 @@ package fr.eni.enchere.controllers;
|
|||||||
|
|
||||||
import fr.eni.enchere.bll.CategorieService;
|
import fr.eni.enchere.bll.CategorieService;
|
||||||
import fr.eni.enchere.bll.UserService;
|
import fr.eni.enchere.bll.UserService;
|
||||||
|
import fr.eni.enchere.bo.Article;
|
||||||
|
import fr.eni.enchere.bo.Categorie;
|
||||||
|
import fr.eni.enchere.bo.Retrait;
|
||||||
|
import fr.eni.enchere.bo.UserProfil;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@RequestMapping("/admin")
|
||||||
public class AdminController {
|
public class AdminController {
|
||||||
|
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@@ -17,10 +25,27 @@ public class AdminController {
|
|||||||
this.categorieService = categorieService;
|
this.categorieService = categorieService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping( "/admin")
|
@GetMapping
|
||||||
public String viewAdminPanel(Model model) {
|
public String viewAdminPanel(Model model) {
|
||||||
model.addAttribute("categories", categorieService.findAllCategories());
|
model.addAttribute("categories", categorieService.findAllCategories());
|
||||||
//model.addAttribute("userProfil", userService.f);
|
model.addAttribute("userProfil", userService.listeUtilisateurs());
|
||||||
|
model.addAttribute("categorie", new Categorie());
|
||||||
return "admin";
|
return "admin";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/new")
|
||||||
|
public String ajouterCategorie(@ModelAttribute("categorie") Categorie categorie) {
|
||||||
|
categorieService.saveCategorie(categorie);
|
||||||
|
return "redirect:/admin";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update")
|
||||||
|
public String updateCategorie(@RequestParam("newCategorie") String libelle, @RequestParam("IdCategorie") int idCategorie) {
|
||||||
|
Categorie categorie = new Categorie();
|
||||||
|
categorie.setLibelle(libelle);
|
||||||
|
categorie.setId(idCategorie);
|
||||||
|
|
||||||
|
return "redirect:/admin";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,7 @@ import java.util.List;
|
|||||||
public interface CategorieRepository {
|
public interface CategorieRepository {
|
||||||
List<Categorie> findAllCategories();
|
List<Categorie> findAllCategories();
|
||||||
Categorie findCategorieById(int id);
|
Categorie findCategorieById(int id);
|
||||||
|
void saveCategorie(Categorie categorie);
|
||||||
|
void updateCategorie(Categorie categorie);
|
||||||
|
void deleteCategorie(int id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import fr.eni.enchere.bo.Categorie;
|
|||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
|
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||||
|
import org.springframework.jdbc.support.KeyHolder;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -16,7 +18,6 @@ public class CategorieRepositoryImpl implements CategorieRepository {
|
|||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
||||||
|
|
||||||
|
|
||||||
private class CategorieRowMapper implements RowMapper<Categorie> {
|
private class CategorieRowMapper implements RowMapper<Categorie> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,15 +36,31 @@ public class CategorieRepositoryImpl implements CategorieRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Categorie> findAllCategories() {
|
public List<Categorie> findAllCategories() {
|
||||||
String sql = "SELECT * FROM CATEGORIES";
|
String sql = "SELECT * FROM CATEGORIES WHERE isDelete = 0";
|
||||||
List<Categorie> categories = jdbcTemplate.query(sql, new CategorieRowMapper());
|
List<Categorie> categories = jdbcTemplate.query(sql, new CategorieRowMapper());
|
||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Categorie findCategorieById(int id) {
|
public Categorie findCategorieById(int id) {
|
||||||
String sql = "SELECT * FROM CATEGORIES WHERE no_categorie = ?";
|
String sql = "SELECT * FROM CATEGORIES WHERE no_categorie = ? AND isDelete = 0";
|
||||||
Categorie categorie = jdbcTemplate.queryForObject(sql, new CategorieRowMapper(), id);
|
Categorie categorie = jdbcTemplate.queryForObject(sql, new CategorieRowMapper(), id);
|
||||||
return categorie;
|
return categorie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveCategorie(Categorie categorie) {
|
||||||
|
String sql = "INSERT INTO CATEGORIES (\t=libelle) VALUES (?)";
|
||||||
|
jdbcTemplate.update(sql, categorie.getLibelle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateCategorie(Categorie categorie) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteCategorie(int id) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,9 @@ public class UserRepositoryImpl implements UserRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserProfil> findAll() {
|
public List<UserProfil> findAll() {
|
||||||
return List.of();
|
String sql = "SELECT * FROM UTILISATEURS WHERE isDelete = 0";
|
||||||
|
List<UserProfil> users = jdbcTemplate.query(sql, new UserRowMapper());
|
||||||
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||||
|
|
||||||
|
import static javax.management.Query.and;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class WebSecurityConfig{
|
public class WebSecurityConfig{
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ spring.datasource.url=jdbc:mariadb://91.121.54.36:3306/eni_enchere
|
|||||||
spring.datasource.username=eni
|
spring.datasource.username=eni
|
||||||
spring.datasource.password=Pa$$w0rd
|
spring.datasource.password=Pa$$w0rd
|
||||||
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
||||||
spring.messages.encoding=UTF-8
|
spring.messages.encoding=UTF-8
|
||||||
|
server.port=8800
|
||||||
@@ -2,9 +2,72 @@
|
|||||||
<html th:replace="~{modele-page :: layout('Panel administrateur',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
|
<html th:replace="~{modele-page :: layout('Panel administrateur',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css"> <!-- Ajoutez le lien vers votre fichier CSS si nécessaire -->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="container-main">
|
<div id="container-main">
|
||||||
|
<h2>Liste des catégories modifiées</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Nom</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr th:each="categorie : ${categories}">
|
||||||
|
<td>
|
||||||
|
<form th:action="@{/admin/update}" method="post">
|
||||||
|
<input type="text" name="newCategorie" id="newCategorie" th:value="${categorie.libelle}">
|
||||||
|
<input type="hidden" name="IdCategorie" id="IdCategorie" th:value="${categorie.id}">
|
||||||
|
<button>Sauvegarder</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<form th:action="@{/admin/catDelete}" method="post">
|
||||||
|
<input type="hidden" name="deleteIdCategorie" id="deleteIdCategorie" th:value="${categorie.id}">
|
||||||
|
<button>Supprimer</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<form th:action="@{/admin/new}" th:object="${categorie}" method="post">
|
||||||
|
<input type="text" th:field="*{libelle}" id="nom">
|
||||||
|
<button>Ajouter</button>
|
||||||
|
</form>
|
||||||
|
<h2>Liste des utilisateurs</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Pseudo</th>
|
||||||
|
<th>Nom</th>
|
||||||
|
<th>Prénom</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr th:each="user : ${userProfil}">
|
||||||
|
<td th:text="${user.id}"></td>
|
||||||
|
<td th:text="${user.pseudo}"></td>
|
||||||
|
<td th:text="${user.nom}"></td>
|
||||||
|
<td th:text="${user.prenom}"></td>
|
||||||
|
<td th:text="${user.email}"></td>
|
||||||
|
<td>
|
||||||
|
<form th:action="@{/admin/disabled}" method="post">
|
||||||
|
<input type="hidden" name="userDisabled" id="userDisabled" th:value="${user.id}">
|
||||||
|
<button >Désactiver</button>
|
||||||
|
</form>
|
||||||
|
<form th:action="@{/admin/delete}" method="post">
|
||||||
|
<input type="hidden" name="userDelete" id="userDelete" th:value="${user.id}">
|
||||||
|
<button>Supprimer</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user