aled
This commit is contained in:
@@ -43,9 +43,16 @@ public class ArticleController {
|
||||
//Affichage d'un article
|
||||
|
||||
@GetMapping("/show")
|
||||
public String showArticle(@RequestParam(name = "slug")int id, Model model) {
|
||||
Article article = articleService.findArticleById(id);
|
||||
return "article";
|
||||
public String showArticle(@RequestParam()int id, Model model) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (!authentication.getName().equals("anonymousUser")) {
|
||||
Article article = articleService.findArticleById(id);
|
||||
System.out.println(article);
|
||||
model.addAttribute("article", article);
|
||||
return "article";
|
||||
} else {
|
||||
return "redirect:/accueil";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{slug}")
|
||||
|
||||
@@ -80,7 +80,9 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
|
||||
@Override
|
||||
public Article findArticleById(int id) {
|
||||
return null;
|
||||
String sql = "SELECT * FROM ARTICLES_VENDUS a WHERE no_article = ?";
|
||||
Article article = jdbcTemplate.queryForObject(sql, new ArticleRowMapper(), id);
|
||||
return article;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,9 @@ public class UserInterceptor implements HandlerInterceptor {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null && authentication.isAuthenticated() && !authentication.getName().equals("anonymousUser")) {
|
||||
UserProfil user = this.userService.utilisateurByName(authentication.getName());
|
||||
modelAndView.getModelMap().addAttribute("user", user.getCredit());
|
||||
if (modelAndView != null && modelAndView.getViewName() != null && !modelAndView.getViewName().startsWith("redirect:")) {
|
||||
modelAndView.addObject("user", user.getCredit());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
//package fr.eni.enchere.interceptor;
|
||||
//
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
//
|
||||
//public class UserServiceInterceptorAppConfig implements WebMvcConfigurer {
|
||||
//
|
||||
// @Override
|
||||
// public void addInterceptors(InterceptorRegistry registry) {
|
||||
// registry.addInterceptor(new UserInterceptor());
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user