From 84a543f6aece117ab3f1e5d6ea8c6f8129ef2999 Mon Sep 17 00:00:00 2001 From: Okhin <okhin@okhin.fr> Date: Thu, 15 Nov 2018 16:00:16 +0100 Subject: [PATCH] Adding user handling command for total and cumul --- src/LQDN/Command/CounterpartCreateCommand.php | 8 ++++- src/LQDN/Command/UserUpdateCumulCommand.php | 25 ++++++++++++++ src/LQDN/Command/UserUpdateTotalCommand.php | 25 ++++++++++++++ src/LQDN/Handler/CounterpartHandler.php | 5 +-- src/LQDN/Handler/UserHandler.php | 34 +++++++++++++++++++ 5 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/LQDN/Command/UserUpdateCumulCommand.php create mode 100644 src/LQDN/Command/UserUpdateTotalCommand.php diff --git a/src/LQDN/Command/CounterpartCreateCommand.php b/src/LQDN/Command/CounterpartCreateCommand.php index 2cfa701..1a0a7e3 100644 --- a/src/LQDN/Command/CounterpartCreateCommand.php +++ b/src/LQDN/Command/CounterpartCreateCommand.php @@ -12,7 +12,7 @@ class CounterpartCreateCommand private $status; private $date; - public function __construct($addressId, $userId, $quoi, $taille, $status, $date) + public function __construct($addressId, $userId, $quoi, $taille, $status, $date, $commentaire) { $this->userId = $userId; $this->addressId = $addressId; @@ -20,6 +20,7 @@ class CounterpartCreateCommand $this->taille = $taille; $this->status = $status; $this->date = $date; + $this->commentaire = $commentaire; } public function getUserId() @@ -51,4 +52,9 @@ class CounterpartCreateCommand { return $this->date; } + + public function getCommentaire() + { + return $this->commentaire; + } } diff --git a/src/LQDN/Command/UserUpdateCumulCommand.php b/src/LQDN/Command/UserUpdateCumulCommand.php new file mode 100644 index 0000000..ced725f --- /dev/null +++ b/src/LQDN/Command/UserUpdateCumulCommand.php @@ -0,0 +1,25 @@ +<?php + +namespace LQDN\Command; + +class UserUpdateCumulCommand +{ + private $id; + private $cumul; + + public function __construct($id, $cumul) + { + $this->id = $id; + $this->cumul = $cumul; + } + + public function getId() + { + return $this->id; + } + + public function getCumul() + { + return $this->cumul; + } +} diff --git a/src/LQDN/Command/UserUpdateTotalCommand.php b/src/LQDN/Command/UserUpdateTotalCommand.php new file mode 100644 index 0000000..dc09807 --- /dev/null +++ b/src/LQDN/Command/UserUpdateTotalCommand.php @@ -0,0 +1,25 @@ +<?php + +namespace LQDN\Command; + +class UserUpdateTotalCommand +{ + private $id; + private $total; + + public function __construct($id, $total) + { + $this->id = $id; + $this->total = $total; + } + + public function getId() + { + return $this->id; + } + + public function getTotal() + { + return $this->total; + } +} diff --git a/src/LQDN/Handler/CounterpartHandler.php b/src/LQDN/Handler/CounterpartHandler.php index 6fdbce7..ef4b4af 100644 --- a/src/LQDN/Handler/CounterpartHandler.php +++ b/src/LQDN/Handler/CounterpartHandler.php @@ -43,8 +43,8 @@ class CounterpartHandler $adresseId = $command->getAddressId(); $query =<<<EOF -INSERT INTO contreparties(datec, user_id, adresse_id, quoi, taille, status) -VALUES (:datec, :user_id, :adresse_id, :quoi, :taille, :status) +INSERT INTO contreparties(datec, user_id, adresse_id, quoi, taille, status, commentaire) +VALUES (:datec, :user_id, :adresse_id, :quoi, :taille, :status, :commentaire) EOF; $stmt = $this->connection->prepare($query); $stmt->bindValue('datec', $command->getDateCreation()); @@ -53,6 +53,7 @@ EOF; $stmt->bindValue('quoi', $command->getQuoi()); $stmt->bindValue('taille', $command->getTaille()); $stmt->bindValue('status', $command->getStatus()); + $stmt->bindValue('commentaire', $command->getCommentaire()); $stmt->execute(); } diff --git a/src/LQDN/Handler/UserHandler.php b/src/LQDN/Handler/UserHandler.php index 5f13a68..4e886ef 100644 --- a/src/LQDN/Handler/UserHandler.php +++ b/src/LQDN/Handler/UserHandler.php @@ -4,6 +4,8 @@ namespace LQDN\Handler; use Doctrine\DBAL\Connection; use LQDN\Command\UserUpdateByAdminCommand; +use LQDN\Command\UserUpdateTotalCommand; +use LQDN\Command\UserUpdateCumulCommand; class UserHandler { @@ -28,4 +30,36 @@ class UserHandler 'id' => $command->getId(), ]); } + + /** + * Update the user total + * + * @param UserUpdateTotalCommand $command + */ + public function handleUserUpdateTotalCommand(UserUpdateTotalCommand $command) + { + $this->connection->executeUpdate( + 'UPDATE users SET total = :total WHERE id = :id', + [ + 'total' => $command->getTotal(), + 'id'=> $command->getId() + ] + ); + } + + /** + * Update the user cumul + * + * @param UserUpdateCumulCommand $command + */ + public function handleUserUpdateCumulCommand(UserUpdateCumulCommand $command) + { + $this->connection->executeUpdate( + 'UPDATE users SET cumul = :cumul WHERE id = :id', + [ + 'cumul' => $command->getCumul(), + 'id' => $command->getId(), + ] + ); + } } -- GitLab