Merge branch 'Johan'
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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