Skip to content
Extraits de code Groupes Projets
Valider 114b9aa2 rédigé par nono's avatar nono :computer:
Parcourir les fichiers

Merge branch 'patch-mail-address-update' into 'preprod'

Patch mail address update

See merge request lqdn-interne/don!137
parents 85ee12e0 c96d429d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion!144Fusion de la branch préprod et master,!137Patch mail address update
......@@ -287,6 +287,22 @@ class Perso extends Controller
}
$f3->push('SESSION.message', _("Adresse ajoutée à votre profil"));
break;
case 'UPDATE':
$f3->get('container')['command_handler']->handle(
new AddressUpdateCommand(
\Utils::asl($f3->get('id')),
\Utils::asl($f3->get('SESSION.id')),
\Utils::asl($f3->get('nom')),
\Utils::asl($f3->get('adresse')),
\Utils::asl($f3->get('adresse2')),
\Utils::asl($f3->get('codepostal')),
\Utils::asl($f3->get('ville')),
\Utils::asl($f3->get('pays')),
\Utils::asl($f3->get('state'))
)
);
$f3->push('SESSION.message', _("Adresse du profil modifiée."));
break;
case 'DELETE':
try {
$f3->get('container')['command_handler']->handle(
......
......@@ -79,8 +79,15 @@
<h3>{{ _("Renseigner votre adresse.")}}</h3>
<form method="POST" action="{{ 'adresses' | alias }}" id="create-adress-form">
<input type="hidden" name="csrf" value="{{ @CSRF }}" />
<input type="hidden" name="action" value="ADD" />
<check if="{{ @adresse }}">
<true>
<input type="hidden" name="action" value="UPDATE" />
<input type="hidden" name="id" value="{{ @@adresse.id }}" />
</true>
<false>
<input type="hidden" name="action" value="ADD" />
</false>
</check>
<div class="form-group">
<label for="nom">{{ _("Destinataire") }}</label>
<input type="text" class="form-control" name="nom" value="{{ @@adresse.nom }}">
......
<?php
namespace LQDN\Command;
class AddressUpdateCommand
{
private $addressId;
private $userId;
private $name;
private $address;
private $address2;
private $postalCode;
private $city;
private $country;
private $state;
public function __construct($addressId, $userId, $name, $address, $address2, $postalCode, $city, $country, $state)
{
$this->addressId = $addressId;
$this->userId = $userId;
$this->name = $name;
$this->address = $address;
$this->address2 = $address2;
$this->postalCode = $postalCode;
$this->city = $city;
$this->country = $country;
$this->state = $state;
}
public function getAddressId()
{
return $this->addressId;
}
public function getUserId()
{
return $this->userId;
}
public function getName()
{
return $this->name;
}
public function getAddress()
{
return $this->address;
}
public function getAddress2()
{
return $this->address2;
}
public function getPostalCode()
{
return $this->postalCode;
}
public function getCity()
{
return $this->city;
}
public function getCountry()
{
return $this->country;
}
public function getState()
{
return $this->state;
}
}
......@@ -63,24 +63,6 @@ EOF;
$stmt->execute();
}
/**
* Check if an address already exists.
*
* @param int $userId
*
* @return bool
*/
private function addressExists($userId)
{
return (bool) $this->connection->fetchColumn(
"SELECT 1 FROM adresses WHERE user_id = :user_id",
[
'user_id' => $userId,
],
0
);
}
/**
* Check if an adress is used.
*
......@@ -99,4 +81,33 @@ EOF;
);
return ($count > 0);
}
/**
* Update an address.
*
* @param AddressUpdateCommand $command
*/
public function handleAddressUpdateCommand(AddressUpdateCommand $command)
{
$addressId = $command->getAddressId();
$userId = $command->getUserId();
$query =<<<EOF
UPDATE adresses
SET nom = :name, adresse = :address, adresse2 = :address2, codepostal = :postal_code, ville = :city, etat = :state, pays = :country
WHERE id = :id and user_id = :user_id
EOF;
$stmt = $this->connection->prepare($query);
$stmt->bindValue('id', $command->getAddressId());
$stmt->bindValue('user_id', $command->getUserId());
$stmt->bindValue('name', $command->getName());
$stmt->bindValue('address', $command->getAddress());
$stmt->bindValue('address2', $command->getAddress2());
$stmt->bindValue('postal_code', $command->getPostalCode());
$stmt->bindValue('city', $command->getCity());
$stmt->bindValue('state', $command->getState());
$stmt->bindValue('country', $command->getCountry());
$stmt->execute();
}
}
......@@ -61,6 +61,30 @@ class AddressHandlerTest extends FunctionalTest
$this->assertSame($expectedAddress, $latestAddress);
}
public function testAddressUpdate()
{
$this->assertTrue($this->addressExists(1));
$latestAddress = $this->getLatestAddress();
$this->container['command_handler']->handle(new AddressUpdateCommand(1, 1, 'LQDN', '115 rue de Ménilmontant', '', 75020, 'Paris', 'France', 'IDF'));
$expectedAddress = [
'id' => '1',
'user_id' => '1',
'nom' => 'LQDN',
'adresse' => '115 rue de Ménilmontant',
'adresse2' => '',
'codepostal' => '75020',
'ville' => 'Paris',
'pays' => 'France',
'etat' => 'IDF',
];
$updatedAddress = $this->getAddressById(1);
$this->assertSame($expectedAddress, $updatedAddress);
}
/**
* Check if an address exists in DB.
*
......@@ -82,4 +106,16 @@ class AddressHandlerTest extends FunctionalTest
{
return $this->container['db']->fetchAssoc("SELECT * FROM adresses ORDER BY id DESC LIMIT 1");
}
/**
* Retrieve address by its ID.
*
* @param int $id
*
* @return []
*/
private function getAddressById($id)
{
return $this->container['db']->fetchAssoc("SELECT id,user_id,nom,adresse,adresse2,codepostal,ville,pays,etat FROM adresses WHERE id = $id LIMIT 1");
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter