parent
2efb321f6a
commit
e86b3f7b00
@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database;
|
||||||
|
|
||||||
|
class UserGateway
|
||||||
|
{
|
||||||
|
private Connexion $connection;
|
||||||
|
|
||||||
|
public function __construct(Connexion $connection) {
|
||||||
|
$this->connection = $connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUsers(): array
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Athlete";
|
||||||
|
$res = $this->connection->executeWithErrorHandling($query);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserById(int $userId): array
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Athlete WHERE idAthlete = :id";
|
||||||
|
$params = [':id' => $userId];
|
||||||
|
$res = $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserByName(string $name): array
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Athlete WHERE nom = :name";
|
||||||
|
$params = [':name' => $name];
|
||||||
|
return $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserByFirstName(string $firstName): array
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Athlete WHERE prenom = :firstName";
|
||||||
|
$params = [':firstName' => $firstName];
|
||||||
|
return $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserByEmail(string $email): array
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Athlete WHERE email = :email";
|
||||||
|
$params = [':email' => $email];
|
||||||
|
return $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserByGender(string $gender): array
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Athlete WHERE sexe = :gender";
|
||||||
|
$params = [':gender' => $gender];
|
||||||
|
return $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserByHeight(int $height): array
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Athlete WHERE taille = :height";
|
||||||
|
$params = [':height' => [$height, PDO::PARAM_INT]];
|
||||||
|
return $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserByWeight(int $weight): array
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Athlete WHERE poids = :weight";
|
||||||
|
$params = [':weight' => [$weight, PDO::PARAM_INT]];
|
||||||
|
return $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserByBirthDate(string $birthdate): array
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Athlete WHERE dateNaissance = :birthdate";
|
||||||
|
$params = [':birthdate' => [$birthdate, PDO::PARAM_STR]];
|
||||||
|
return $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteUserById(int $idAthlete): array
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM Athlete WHERE idAthlete = :idAthlete";
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
':idAthlete' => $idAthlete,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
}
|
||||||
|
public function deleteUserByEmail(string $email): array
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM Athlete WHERE email = :email";
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
':email' => $email,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->connection->executeWithErrorHandling($query, $params);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
INSERT INTO Athlete (username, nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) VALUES
|
INSERT INTO Athlete (username, nom, prenom, email, sexe, taille, poids, motDePasse, dateNaissance, isCoach) VALUES
|
||||||
('johnD63', 'Doe', 'John', 'john.doe@example.com', 'M', 1.80, 70, 'password123', '1990-01-01', FALSE),
|
('johnD63', 'Doe', 'John', 'john.doe@example.com', 'M', 1.80, 75, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1985-05-15', TRUE),
|
||||||
('janeS03', 'Smith', 'Jane', 'jane.smith@example.com', 'F', 1.65, 60, 'password456', '1992-02-02', TRUE),
|
('janeS03', 'Smith', 'Jane', 'jane.smith@example.com', 'F', 1.65, 60, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1990-03-10', FALSE),
|
||||||
('bryanO', 'OConner', 'Bryan', 'bryan.oconner@example.com', 'M', 1.88, 86, 'password789', '1973-09-12', FALSE),
|
('bryanO', 'Martin', 'Paul', 'paul.martin@example.com', 'M', 1.75, 68, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1988-08-20', TRUE),
|
||||||
('dominicT', 'Toretto', 'Dominic', 'dominic.toretto@example.com', 'M', 1.83, 94, 'password987', '1967-07-18', TRUE),
|
('dominicT', 'Brown', 'Anna', 'anna.brown@example.com', 'F', 1.70, 58, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1992-11-25', FALSE),
|
||||||
('miaT', 'Toretto', 'Mia', 'mia.toretto@example.com', 'F', 1.70, 56, 'password654', '1980-04-26', FALSE);
|
('miaT', 'Lee', 'Bruce', 'bruce.lee@example.com', 'M', 1.72, 70, '$2y$10$U59ioMTGZBM2FGQv.3lcbuL0IkO4Fx1jQU7f5hF7o/hvCX2t46mby', '1970-02-05', FALSE);
|
Loading…
Reference in new issue