mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Link between address and reference, and api endpoint to find household
by address reference * add a one-to-many link between address and address reference; * update AddAddress.vue to add information on picked address reference; * add an HouseholdACLAwareRepository, with a method to find household by current address reference * add an endpoint to retrieve household by address reference * + tests
This commit is contained in:
@@ -23,7 +23,7 @@ class Address
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $id;
|
||||
|
||||
@@ -31,7 +31,7 @@ class Address
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $street = '';
|
||||
|
||||
@@ -39,7 +39,7 @@ class Address
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $streetNumber = '';
|
||||
|
||||
@@ -47,7 +47,7 @@ class Address
|
||||
* @var PostalCode
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\PostalCode")
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $postcode;
|
||||
|
||||
@@ -55,7 +55,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=16, nullable=true)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $floor;
|
||||
|
||||
@@ -63,7 +63,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=16, nullable=true)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $corridor;
|
||||
|
||||
@@ -71,7 +71,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=16, nullable=true)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $steps;
|
||||
|
||||
@@ -79,7 +79,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $buildingName;
|
||||
|
||||
@@ -87,7 +87,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=16, nullable=true)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $flat;
|
||||
|
||||
@@ -95,7 +95,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $distribution;
|
||||
|
||||
@@ -103,7 +103,7 @@ class Address
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $extra;
|
||||
|
||||
@@ -114,7 +114,7 @@ class Address
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(type="date")
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private \DateTime $validFrom;
|
||||
|
||||
@@ -125,13 +125,13 @@ class Address
|
||||
* @var \DateTime|null
|
||||
*
|
||||
* @ORM\Column(type="date", nullable=true)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private ?\DateTime $validTo = null;
|
||||
|
||||
/**
|
||||
* True if the address is a "no address", aka homeless person, ...
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
* @ORM\Column(type="boolean")
|
||||
*
|
||||
* @var bool
|
||||
@@ -144,7 +144,7 @@ class Address
|
||||
* @var Point|null
|
||||
*
|
||||
* @ORM\Column(type="point", nullable=true)
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private $point;
|
||||
|
||||
@@ -154,7 +154,7 @@ class Address
|
||||
* @var ThirdParty|null
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty")
|
||||
* @groups({"write"})
|
||||
* @Groups({"write"})
|
||||
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
|
||||
*/
|
||||
private $linkedToThirdParty;
|
||||
@@ -166,6 +166,12 @@ class Address
|
||||
*/
|
||||
private $customs = [];
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=AddressReference::class)
|
||||
* @Groups({"write"})
|
||||
*/
|
||||
private ?AddressReference $addressReference = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->validFrom = new \DateTime();
|
||||
@@ -376,6 +382,7 @@ class Address
|
||||
public static function createFromAddress(Address $original) : Address
|
||||
{
|
||||
return (new Address())
|
||||
->setAddressReference($original->getAddressReference())
|
||||
->setBuildingName($original->getBuildingName())
|
||||
->setCorridor($original->getCorridor())
|
||||
->setCustoms($original->getCustoms())
|
||||
@@ -402,6 +409,7 @@ class Address
|
||||
->setPostcode($original->getPostcode())
|
||||
->setStreet($original->getStreet())
|
||||
->setStreetNumber($original->getStreetNumber())
|
||||
->setAddressReference($original)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -549,5 +557,22 @@ class Address
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AddressReference|null
|
||||
*/
|
||||
public function getAddressReference(): ?AddressReference
|
||||
{
|
||||
return $this->addressReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AddressReference|null $addressReference
|
||||
* @return Address
|
||||
*/
|
||||
public function setAddressReference(?AddressReference $addressReference = null): Address
|
||||
{
|
||||
$this->addressReference = $addressReference;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -589,6 +589,14 @@ export default {
|
||||
'point': this.entity.selected.address.point.coordinates
|
||||
});
|
||||
}
|
||||
|
||||
// add the address reference, if any
|
||||
if (this.entity.selected.address.addressReference !== undefined) {
|
||||
newAddress = Object.assign(newAddress, {
|
||||
'addressReference': this.entity.selected.address.addressReference
|
||||
});
|
||||
}
|
||||
|
||||
if (this.validFrom) {
|
||||
console.log('add validFrom in fetch body', this.entity.selected.valid.from);
|
||||
newAddress = Object.assign(newAddress, {
|
||||
@@ -733,6 +741,9 @@ export default {
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* Called when the event pick-address is emitted, which is, by the way,
|
||||
* called when an address suggestion is picked.
|
||||
*
|
||||
* @param address the address selected
|
||||
*/
|
||||
|
@@ -95,6 +95,9 @@ export default {
|
||||
},
|
||||
selectAddress(value) {
|
||||
this.entity.selected.address = value;
|
||||
this.entity.selected.address.addressReference = {
|
||||
id: value.id
|
||||
};
|
||||
this.entity.selected.address.street = value.street;
|
||||
this.entity.selected.address.streetNumber = value.streetNumber;
|
||||
this.entity.selected.writeNew.address = false;
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
@@ -33,6 +34,9 @@ class AddressNormalizer implements NormalizerAwareInterface, NormalizerInterface
|
||||
$data['extra'] = $address->getExtra();
|
||||
$data['validFrom'] = $address->getValidFrom();
|
||||
$data['validTo'] = $address->getValidTo();
|
||||
$data['addressReference'] = $this->normalizer->normalize($address->getAddressReference(), $format, [
|
||||
AbstractNormalizer::GROUPS => ['read']
|
||||
]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Add a link between address and address reference
|
||||
*/
|
||||
final class Version20210929192242 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add a link between address and address reference';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_address ADD addressReference_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE chill_main_address ADD CONSTRAINT FK_165051F647069464 FOREIGN KEY (addressReference_id) REFERENCES chill_main_address_reference (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('CREATE INDEX IDX_165051F647069464 ON chill_main_address (addressReference_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_address DROP addressReference_id');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user