Début de la page admin

This commit is contained in:
jleroy
2024-04-25 16:58:47 +02:00
parent 85f4f52960
commit 658f1c3e9c
7 changed files with 108 additions and 4 deletions

View File

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

View File

@@ -28,5 +28,15 @@ public class CategorieServiceImpl implements CategorieService {
return categorieRepository.findCategorieById(id);
}
@Override
public void saveCategorie(Categorie categorie) {
categorieRepository.saveCategorie(categorie);
}
@Override
public void deleteCategorie(int id) {
categorieRepository.deleteCategorie(id);
}
}

View File

@@ -2,6 +2,12 @@ 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.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;
@@ -20,7 +26,21 @@ public class AdminController {
@GetMapping( "/admin")
public String viewAdminPanel(Model model) {
model.addAttribute("categories", categorieService.findAllCategories());
//model.addAttribute("userProfil", userService.f);
model.addAttribute("userProfil", userService.listeUtilisateurs());
return "admin";
}
// @GetMapping("/admin")
// public String newArticleForm(HttpServletRequest request, Model model) {
// model.addAttribute("categories", categorieService.findAllCategories());
// model.addAttribute("article", new Article());
// model.addAttribute("retrait", new Retrait());
// model.addAttribute("requestURI", request.getRequestURI());
// //Récupérer l'utilisateur pour set le retrait à son adresse par defaut
// Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
// String username = authentication.getName();
// UserProfil userProfile = userService.utilisateurByName(username);
// model.addAttribute("user", userProfile);
// return "admin";
// }
}

View File

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

View File

@@ -35,7 +35,7 @@ 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;
}
@@ -46,4 +46,14 @@ public class CategorieRepositoryImpl implements CategorieRepository {
Categorie categorie = jdbcTemplate.queryForObject(sql, new CategorieRowMapper(), id);
return categorie;
}
@Override
public void saveCategorie(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

@@ -2,9 +2,68 @@
<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/new}" th:object="${categorie}" method="post">
<input type="text" th:field="*{libelle}" id="categorie" th:value="${categorie.libelle}">
<button>Sauvegarder</button>
</form>
</td>
<td>
<form th:action="@{/admin/catDelete}" method="post">
<input type="hidden" name="idCategorie" id="idCategorie" th:value="${categorie.id}">
<button>Supprimer</button>
</form>
</td>
<td th:text="${categorie.libelle}"></td>
</tr>
</tbody>
</table>
<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>