Merge branch 'refs/heads/marvin'

This commit is contained in:
mepiphana2023
2024-04-23 11:02:00 +02:00
8 changed files with 34 additions and 5 deletions

View File

@@ -11,4 +11,5 @@ public interface ArticleService {
void saveArticle(Article article);
void deleteArticle(int id);
void updateArticle(int id);
List<Article> findArticleByTitle(String title);
}

View File

@@ -38,4 +38,9 @@ public class ArticleServiceImpl implements ArticleService{
public void updateArticle(int id) {
}
@Override
public List<Article> findArticleByTitle(String title) {
return articleRepository.findArticleByTitle(title);
}
}

View File

@@ -1,11 +1,17 @@
package fr.eni.enchere.controllers;
import fr.eni.enchere.bll.ArticleService;
import fr.eni.enchere.bo.Article;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@Controller
@@ -16,6 +22,7 @@ public class AccueilController {
public AccueilController(ArticleService articleService) {
super();
this.articleService = articleService;
}
@@ -25,6 +32,12 @@ public class AccueilController {
return "accueil";
}
@PostMapping("/searchArticle")
public String searchArticle(@ModelAttribute String title, Model model) {
model.addAttribute("Articles", articleService.findArticleByTitle(title));
return "accueil";
}
@GetMapping("/login")
public String login(Model modele) {
return "login";

View File

@@ -7,6 +7,7 @@ import java.util.List;
public interface ArticleRepository {
List<Article> findAllArticle();
Article findArticleById(int id);
List<Article> findArticleByTitle(String title);
void saveArticle(Article article);
void deleteArticle(int id);
void updateArticle(int id);

View File

@@ -56,6 +56,13 @@ public class ArticleRepositoryImpl implements ArticleRepository {
return null;
}
@Override
public List<Article> findArticleByTitle(String title) {
String sql = "SELECT * FROM ARTICLES_VENDUS WHERE nom_article LIKE '?'";
List<Article> articles = jdbcTemplate.query(sql, new ArticleRowMapper(), title);
return articles;
}
@Override
public void saveArticle(Article article) {

View File

@@ -14,7 +14,7 @@ public class WebSecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((requests) -> requests.requestMatchers("/", "/accueil").permitAll()
.requestMatchers("/accueil", "/login", "/inscription").permitAll()
.requestMatchers("/accueil", "/login", "/inscription", "/searchArticle").permitAll()
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll()
.requestMatchers("/admin").hasRole("ADMIN")
.anyRequest().authenticated())

View File

@@ -11,8 +11,8 @@
<div class="container mt-4">
<div class="row mb-4">
<div class="col-12">
<form th:action="@{/search}" method="get" class="input-group">
<input type="text" class="form-control" placeholder="Rechercher un article par nom..." name="searchTerm" th:value="${searchTerm}">
<form th:action="@{/searchArticle}" method="post" class="input-group">
<input type="text" class="form-control" placeholder="Rechercher un article par nom..." name="searchTerm" th:value="${titre}">
<button type="submit" class="btn btn-primary">Recherche</button>
</form>
</div>
@@ -32,7 +32,6 @@
<div>
<h6>Prix de vente: <span th:text="${article.prixVente}"></span></h6>
<h6 class="text-muted">Fin de l'enchere: <span th:text="${#dates.format(article.dateFinEnch, 'dd/MM/yyyy')}"></span></h6>
</div>
</div>
</div>

View File

@@ -16,7 +16,7 @@
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse " id="navbarNav">
<div class="collapse navbar-collapse " id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Encheres <span class="sr-only">(current)</span></a>
@@ -30,6 +30,9 @@
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Déconnection</a>
</li>
<li class="nav-item" th:if="${#authorization.expression('hasRole(''ROLE_ADMIN'')')}">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">S'inscrire - Se connecter</a>
</li>
</ul>
</div>
</nav>