address: POST an address

This commit is contained in:
nobohan 2021-05-28 10:14:54 +02:00
parent 057db09847
commit 165012b302
4 changed files with 45 additions and 9 deletions

View File

@ -9,11 +9,11 @@ use \JsonSerializable;
*
*/
class Point implements JsonSerializable {
private float $lat;
private float $lon;
private ?float $lat = null;
private ?float $lon = null;
public static string $SRID = '4326';
private function __construct(float $lon, float $lat)
private function __construct(?float $lon, ?float $lat)
{
$this->lat = $lat;
$this->lon = $lon;

View File

@ -33,8 +33,6 @@ export default {
methods: {
addNewAddress({ address, modal }) {
console.log('@@@ CLICK button addNewAdress', address);
const lon = address.selected.address.point.coordinates[0];
const lat = address.selected.address.point.coordinates[1];
const newAddress = {
'isNoAddress': address.isNoAddress,
'street': address.selected.address.street,
@ -47,8 +45,7 @@ export default {
'buildingName': address.buildingName,
'distribution': address.distribution,
'extra': address.extra,
//'point': {'lon': lon, 'lat': lat} WIP
'point': `SRID=4326;POINT(${lon}, ${lat})`
'point': address.selected.address.point.coordinates
};
this.$store.dispatch('addAddress', newAddress);
modal.showModal = false;

View File

@ -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]);
}
}
}
}

View File

@ -1,7 +1,7 @@
---
services:
# note: the autowiring for serializers and normalizers is declared
# note: the autowiring for serializers and normalizers is declared
# into ../services.yaml
Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer:
@ -9,3 +9,8 @@ services:
tags:
- { name: 'serializer.normalizer', priority: 8 }
Chill\MainBundle\Serializer\Normalizer\PointNormalizer:
autowire: true
tags:
- { name: 'serializer.normalizer', priority: 8 }