Page admin V1
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user