Merge branch 'refs/heads/marvin'

This commit is contained in:
mepiphana2023
2024-04-23 15:48:51 +02:00
5 changed files with 62 additions and 34 deletions

View File

@@ -11,13 +11,13 @@ public class Article {
Date dateFinEnch; Date dateFinEnch;
float prixInitial; float prixInitial;
float prixVente; float prixVente;
int numUtilisateur; UserProfil Utilisateur;
int numCategorie; int numCategorie;
public Article() { public Article() {
} }
public Article(int id, String nom, String desc, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, int numUtilisateur, int numCategorie) { public Article(int id, String nom, String desc, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, UserProfil Utilisateur, int numCategorie) {
this.id = id; this.id = id;
this.nom = nom; this.nom = nom;
this.desc = desc; this.desc = desc;
@@ -25,7 +25,7 @@ public class Article {
this.dateFinEnch = dateFinEnch; this.dateFinEnch = dateFinEnch;
this.prixInitial = prixInitial; this.prixInitial = prixInitial;
this.prixVente = prixVente; this.prixVente = prixVente;
this.numUtilisateur = numUtilisateur; this.Utilisateur = Utilisateur;
this.numCategorie = numCategorie; this.numCategorie = numCategorie;
} }
@@ -85,12 +85,12 @@ public class Article {
this.prixVente = prixVente; this.prixVente = prixVente;
} }
public int getNumUtilisateur() { public UserProfil getUtilisateur() {
return numUtilisateur; return Utilisateur;
} }
public void setNumUtilisateur(int numUtilisateur) { public void setUtilisateur(UserProfil Utilisateur) {
this.numUtilisateur = numUtilisateur; this.Utilisateur = Utilisateur;
} }
public int getNumCategorie() { public int getNumCategorie() {

View File

@@ -1,7 +1,9 @@
package fr.eni.enchere.dal; package fr.eni.enchere.dal;
import fr.eni.enchere.bll.UserService;
import fr.eni.enchere.bo.Article; import fr.eni.enchere.bo.Article;
import fr.eni.enchere.bo.SearchArticleCritere; import fr.eni.enchere.bo.SearchArticleCritere;
import fr.eni.enchere.bo.UserProfil;
import fr.eni.enchere.controllers.AccueilController; import fr.eni.enchere.controllers.AccueilController;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -23,6 +25,7 @@ public class ArticleRepositoryImpl implements ArticleRepository {
private static final Logger logger = LoggerFactory.getLogger(ArticleRepositoryImpl.class); private static final Logger logger = LoggerFactory.getLogger(ArticleRepositoryImpl.class);
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
private NamedParameterJdbcTemplate namedJdbcTemplate; private NamedParameterJdbcTemplate namedJdbcTemplate;
private UserService userService;
private class ArticleRowMapper implements RowMapper<Article> { private class ArticleRowMapper implements RowMapper<Article> {
@Override @Override
@@ -35,15 +38,23 @@ public class ArticleRepositoryImpl implements ArticleRepository {
article.setDateFinEnch(rs.getDate("date_fin_encheres")); article.setDateFinEnch(rs.getDate("date_fin_encheres"));
article.setPrixInitial(rs.getFloat("prix_initial")); article.setPrixInitial(rs.getFloat("prix_initial"));
article.setPrixVente(rs.getFloat("prix_vente")); article.setPrixVente(rs.getFloat("prix_vente"));
article.setNumUtilisateur(rs.getInt("no_utilisateur"));
UserProfil user = userService.utilisateur(rs.getInt("no_utilisateur"));
if (user != null) {
article.setUtilisateur(user);
} else {
logger.error("erreur de l'utilisateur");
}
article.setNumCategorie(rs.getInt("no_categorie")); article.setNumCategorie(rs.getInt("no_categorie"));
return article; return article;
} }
} }
public ArticleRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate) { public ArticleRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate, UserService userService) {
this.jdbcTemplate = jdbcTemplate; this.jdbcTemplate = jdbcTemplate;
this.namedJdbcTemplate = namedJdbcTemplate; this.namedJdbcTemplate = namedJdbcTemplate;
this.userService = userService;
} }
@Override @Override

View File

@@ -1,9 +1,12 @@
package fr.eni.enchere.dal; package fr.eni.enchere.dal;
import fr.eni.enchere.bo.Article;
import fr.eni.enchere.bo.UserProfil; import fr.eni.enchere.bo.UserProfil;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.GeneratedKeyHolder;
@@ -12,6 +15,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -31,14 +36,25 @@ public class UserRepositoryImpl implements UserRepository {
this.passwordEncoder = passwordEncoder; this.passwordEncoder = passwordEncoder;
} }
@Override public class UserRowMapper implements RowMapper<UserProfil> {
public List<UserProfil> findAll() {
return List.of();
}
@Override @Override
public UserProfil findById(int id) { public UserProfil mapRow(ResultSet rs, int rowNum) throws SQLException {
return null; UserProfil userProfile = new UserProfil();
userProfile.setId(rs.getInt("no_utilisateur"));
userProfile.setPrenom(rs.getString("prenom"));
userProfile.setNom(rs.getString("nom"));
userProfile.setPseudo(rs.getString("pseudo"));
userProfile.setEmail(rs.getString("email"));
userProfile.setTelephone(rs.getString("telephone"));
userProfile.setRue(rs.getString("rue"));
userProfile.setCode_postal(rs.getString("code_postal"));
userProfile.setVille(rs.getString("ville"));
userProfile.setPassword(rs.getString("mot_de_passe"));
userProfile.setCredit(rs.getFloat("credit"));
userProfile.setAdmin(rs.getBoolean("administrateur"));
return userProfile;
}
} }
@Override @Override
@@ -46,22 +62,20 @@ public class UserRepositoryImpl implements UserRepository {
String sql = "SELECT * FROM UTILISATEURS WHERE pseudo = :username OR email = :username AND isDelete = 0"; String sql = "SELECT * FROM UTILISATEURS WHERE pseudo = :username OR email = :username AND isDelete = 0";
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("username", username); params.put("username", username);
UserProfil user = namedParameterJdbcTemplate.queryForObject(sql, params, (rs, rowNum) -> { UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), params);
UserProfil userProfile = new UserProfil(); return user;
userProfile.setId(rs.getInt("no_utilisateur")); }
userProfile.setPrenom(rs.getString("prenom"));
userProfile.setNom(rs.getString("nom"));
userProfile.setPseudo(rs.getString("pseudo")); @Override
userProfile.setEmail(rs.getString("email")); public List<UserProfil> findAll() {
userProfile.setTelephone(rs.getString("telephone")); return List.of();
userProfile.setRue(rs.getString("rue")); }
userProfile.setCode_postal(rs.getString("code_postal"));
userProfile.setVille(rs.getString("ville")); @Override
userProfile.setPassword(rs.getString("mot_de_passe")); public UserProfil findById(int id) {
userProfile.setCredit(rs.getFloat("credit")); String sql = "SELECT * FROM UTILISATEURS WHERE no_utilisateur = ?";
userProfile.setAdmin(rs.getBoolean("administrateur")); UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), id);
return userProfile;
});
return user; return user;
} }

View File

@@ -43,9 +43,12 @@
<div class="d-flex justify-content-between align-items-center"> <div class="d-flex justify-content-between align-items-center">
<div> <div>
<h6>Prix de vente: <span th:text="${article.prixVente}"></span></h6> <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>
<h6>Vendeur: <span th:text="${article.utilisateur.getPseudo()}"></span> </h6>
</div> </div>
</div> </div>
</br>
<h6 class="text-muted">Fin de l'enchere: <span th:text="${#dates.format(article.dateFinEnch, 'dd/MM/yyyy')}"></span></h6>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -10,7 +10,7 @@
<body> <body>
<header> <header>
<nav class="navbar navbar-expand-lg navbar navbar-dark bg-dark navbar-"> <nav class="navbar navbar-expand-lg navbar navbar-dark bg-dark navbar-">
<a class="navbar-brand" href="#"> <a class="navbar-brand" href="/accueil">
<img src="img/logo.png" width="70" height="70" alt="Logo"> <img src="img/logo.png" width="70" height="70" alt="Logo">
</a> </a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">