Merge branch 'Johan'

This commit is contained in:
Parpaillax
2024-04-26 11:29:25 +02:00
10 changed files with 147 additions and 10 deletions

View File

@@ -1,16 +1,23 @@
plugins {
id 'java'
id 'application'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'fr.eni'
version = '0.0.1-SNAPSHOT'
version = '1.0.0'
java {
sourceCompatibility = '17'
}
jar {
manifest {
attributes 'Main-Class': 'fr.eni.enchere.EnchereApplication'
}
}
repositories {
mavenCentral()
}

View File

@@ -9,5 +9,7 @@ import java.util.List;
public interface CategorieService {
List<fr.eni.enchere.bo.Categorie> findAllCategories();
Categorie findCategorieById(int id);
void saveCategorie(Categorie categorie);
void updateCategorie(Categorie categorie);
void deleteCategorie(int id);
}

View File

@@ -28,5 +28,20 @@ public class CategorieServiceImpl implements CategorieService {
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);
}
}

View File

@@ -2,11 +2,19 @@ package fr.eni.enchere.controllers;
import fr.eni.enchere.bll.CategorieService;
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.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping("/admin")
public class AdminController {
private UserService userService;
@@ -17,10 +25,27 @@ public class AdminController {
this.categorieService = categorieService;
}
@GetMapping( "/admin")
@GetMapping
public String viewAdminPanel(Model model) {
model.addAttribute("categories", categorieService.findAllCategories());
//model.addAttribute("userProfil", userService.f);
model.addAttribute("userProfil", userService.listeUtilisateurs());
model.addAttribute("categorie", new Categorie());
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";
}
}

View File

@@ -7,4 +7,7 @@ import java.util.List;
public interface CategorieRepository {
List<Categorie> findAllCategories();
Categorie findCategorieById(int id);
void saveCategorie(Categorie categorie);
void updateCategorie(Categorie categorie);
void deleteCategorie(int id);
}

View File

@@ -5,6 +5,8 @@ import fr.eni.enchere.bo.Categorie;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
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 java.sql.ResultSet;
@@ -16,7 +18,6 @@ public class CategorieRepositoryImpl implements CategorieRepository {
private JdbcTemplate jdbcTemplate;
private NamedParameterJdbcTemplate namedJdbcTemplate;
private class CategorieRowMapper implements RowMapper<Categorie> {
@Override
@@ -35,15 +36,31 @@ public class CategorieRepositoryImpl implements CategorieRepository {
@Override
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());
return categories;
}
@Override
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);
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) {
}
}

View File

@@ -75,7 +75,9 @@ public class UserRepositoryImpl implements UserRepository {
@Override
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

View File

@@ -9,6 +9,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import static javax.management.Query.and;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig{

View File

@@ -2,4 +2,5 @@ spring.datasource.url=jdbc:mariadb://91.121.54.36:3306/eni_enchere
spring.datasource.username=eni
spring.datasource.password=Pa$$w0rd
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.messages.encoding=UTF-8
spring.messages.encoding=UTF-8
server.port=8800

View File

@@ -2,9 +2,72 @@
<html th:replace="~{modele-page :: layout('Panel administrateur',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css"> <!-- Ajoutez le lien vers votre fichier CSS si nécessaire -->
</head>
<body>
<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>
</body>