Merge branch 'main' into Olivier
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import org.apache.catalina.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
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.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
@@ -11,6 +14,8 @@ import org.springframework.jdbc.support.KeyHolder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -30,14 +35,25 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserProfil> findAll() {
|
||||
return List.of();
|
||||
}
|
||||
public class UserRowMapper implements RowMapper<UserProfil> {
|
||||
|
||||
@Override
|
||||
public UserProfil findById(int id) {
|
||||
return null;
|
||||
@Override
|
||||
public UserProfil mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
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
|
||||
@@ -45,22 +61,20 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE pseudo = :username OR email = :username AND isDelete = 0";
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("username", username);
|
||||
UserProfil user = namedParameterJdbcTemplate.queryForObject(sql, params, (rs, rowNum) -> {
|
||||
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;
|
||||
});
|
||||
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), params);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserProfil> findAll() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfil findById(int id) {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE no_utilisateur = ?";
|
||||
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), id);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user