mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
address: POST an address
This commit is contained in:
parent
057db09847
commit
165012b302
@ -9,11 +9,11 @@ use \JsonSerializable;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Point implements JsonSerializable {
|
class Point implements JsonSerializable {
|
||||||
private float $lat;
|
private ?float $lat = null;
|
||||||
private float $lon;
|
private ?float $lon = null;
|
||||||
public static string $SRID = '4326';
|
public static string $SRID = '4326';
|
||||||
|
|
||||||
private function __construct(float $lon, float $lat)
|
private function __construct(?float $lon, ?float $lat)
|
||||||
{
|
{
|
||||||
$this->lat = $lat;
|
$this->lat = $lat;
|
||||||
$this->lon = $lon;
|
$this->lon = $lon;
|
||||||
|
@ -33,8 +33,6 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
addNewAddress({ address, modal }) {
|
addNewAddress({ address, modal }) {
|
||||||
console.log('@@@ CLICK button addNewAdress', address);
|
console.log('@@@ CLICK button addNewAdress', address);
|
||||||
const lon = address.selected.address.point.coordinates[0];
|
|
||||||
const lat = address.selected.address.point.coordinates[1];
|
|
||||||
const newAddress = {
|
const newAddress = {
|
||||||
'isNoAddress': address.isNoAddress,
|
'isNoAddress': address.isNoAddress,
|
||||||
'street': address.selected.address.street,
|
'street': address.selected.address.street,
|
||||||
@ -47,8 +45,7 @@ export default {
|
|||||||
'buildingName': address.buildingName,
|
'buildingName': address.buildingName,
|
||||||
'distribution': address.distribution,
|
'distribution': address.distribution,
|
||||||
'extra': address.extra,
|
'extra': address.extra,
|
||||||
//'point': {'lon': lon, 'lat': lat} WIP
|
'point': address.selected.address.point.coordinates
|
||||||
'point': `SRID=4326;POINT(${lon}, ${lat})`
|
|
||||||
};
|
};
|
||||||
this.$store.dispatch('addAddress', newAddress);
|
this.$store.dispatch('addAddress', newAddress);
|
||||||
modal.showModal = false;
|
modal.showModal = false;
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||||
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Doctrine\Model\Point;
|
||||||
|
|
||||||
|
|
||||||
|
class PointNormalizer implements DenormalizerInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function supportsDenormalization($data, string $type, string $format = null) : bool
|
||||||
|
{
|
||||||
|
return $type === Point::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!is_array($data)) {
|
||||||
|
throw new InvalidArgumentException('point data is not an array. It should be an array of 2 coordinates.');
|
||||||
|
} else {
|
||||||
|
if (count($data) !== 2) {
|
||||||
|
throw new InvalidArgumentException('point data is not an array of 2 elements. It should be an array of 2 coordinates.');
|
||||||
|
} else {
|
||||||
|
return Point::fromLonLat($data[0], $data[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
services:
|
services:
|
||||||
|
|
||||||
# note: the autowiring for serializers and normalizers is declared
|
# note: the autowiring for serializers and normalizers is declared
|
||||||
# into ../services.yaml
|
# into ../services.yaml
|
||||||
|
|
||||||
Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer:
|
Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer:
|
||||||
@ -9,3 +9,8 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: 'serializer.normalizer', priority: 8 }
|
- { name: 'serializer.normalizer', priority: 8 }
|
||||||
|
|
||||||
|
Chill\MainBundle\Serializer\Normalizer\PointNormalizer:
|
||||||
|
autowire: true
|
||||||
|
tags:
|
||||||
|
- { name: 'serializer.normalizer', priority: 8 }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user