Page admin V1

This commit is contained in:
jleroy
2024-04-26 11:28:16 +02:00
parent 658f1c3e9c
commit 0c28a4ce14
9 changed files with 56 additions and 23 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

@@ -10,5 +10,6 @@ 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

@@ -33,6 +33,11 @@ public class CategorieServiceImpl implements CategorieService {
categorieRepository.saveCategorie(categorie);
}
@Override
public void updateCategorie(Categorie categorie) {
}
@Override
public void deleteCategorie(int id) {
categorieRepository.deleteCategorie(id);

View File

@@ -3,6 +3,7 @@ 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;
@@ -10,9 +11,10 @@ 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;
@@ -23,24 +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.listeUtilisateurs());
model.addAttribute("categorie", new Categorie());
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";
// }
@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

@@ -8,5 +8,6 @@ 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
@@ -42,13 +43,19 @@ public class CategorieRepositoryImpl implements CategorieRepository {
@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) {
}

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

@@ -17,21 +17,25 @@
<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}">
<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="idCategorie" id="idCategorie" th:value="${categorie.id}">
<input type="hidden" name="deleteIdCategorie" id="deleteIdCategorie" th:value="${categorie.id}">
<button>Supprimer</button>
</form>
</td>
<td th:text="${categorie.libelle}"></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>