post new address - WIP

This commit is contained in:
nobohan 2021-05-25 17:54:21 +02:00
parent e88e9b1a6f
commit 72795be040
4 changed files with 80 additions and 24 deletions

View File

@ -4,6 +4,7 @@ namespace Chill\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Chill\MainBundle\Doctrine\Model\Point; use Chill\MainBundle\Doctrine\Model\Point;
use Chill\ThirdPartyBundle\Entity\ThirdParty; use Chill\ThirdPartyBundle\Entity\ThirdParty;
@ -22,6 +23,7 @@ class Address
* @ORM\Id * @ORM\Id
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
* @groups({"write"})
*/ */
private $id; private $id;
@ -29,6 +31,7 @@ class Address
* @var string * @var string
* *
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
* @groups({"write"})
*/ */
private $street = ''; private $street = '';
@ -36,6 +39,7 @@ class Address
* @var string * @var string
* *
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
* @groups({"write"})
*/ */
private $streetNumber = ''; private $streetNumber = '';
@ -43,6 +47,7 @@ class Address
* @var PostalCode * @var PostalCode
* *
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\PostalCode") * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\PostalCode")
* @groups({"write"})
*/ */
private $postcode; private $postcode;
@ -50,6 +55,7 @@ class Address
* @var string|null * @var string|null
* *
* @ORM\Column(type="string", length=16, nullable=true) * @ORM\Column(type="string", length=16, nullable=true)
* @groups({"write"})
*/ */
private $floor; private $floor;
@ -57,6 +63,7 @@ class Address
* @var string|null * @var string|null
* *
* @ORM\Column(type="string", length=16, nullable=true) * @ORM\Column(type="string", length=16, nullable=true)
* @groups({"write"})
*/ */
private $corridor; private $corridor;
@ -64,6 +71,7 @@ class Address
* @var string|null * @var string|null
* *
* @ORM\Column(type="string", length=16, nullable=true) * @ORM\Column(type="string", length=16, nullable=true)
* @groups({"write"})
*/ */
private $steps; private $steps;
@ -71,6 +79,7 @@ class Address
* @var string|null * @var string|null
* *
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
* @groups({"write"})
*/ */
private $buildingName; private $buildingName;
@ -78,6 +87,7 @@ class Address
* @var string|null * @var string|null
* *
* @ORM\Column(type="string", length=16, nullable=true) * @ORM\Column(type="string", length=16, nullable=true)
* @groups({"write"})
*/ */
private $flat; private $flat;
@ -85,6 +95,7 @@ class Address
* @var string|null * @var string|null
* *
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
* @groups({"write"})
*/ */
private $distribution; private $distribution;
@ -92,6 +103,7 @@ class Address
* @var string|null * @var string|null
* *
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
* @groups({"write"})
*/ */
private $extra; private $extra;
@ -102,6 +114,7 @@ class Address
* @var \DateTime * @var \DateTime
* *
* @ORM\Column(type="date") * @ORM\Column(type="date")
* @groups({"write"})
*/ */
private $validFrom; private $validFrom;
@ -112,11 +125,13 @@ class Address
* @var \DateTime|null * @var \DateTime|null
* *
* @ORM\Column(type="date", nullable=true) * @ORM\Column(type="date", nullable=true)
* @groups({"write"})
*/ */
private $validTo; private $validTo;
/** /**
* True if the address is a "no address", aka homeless person, ... * True if the address is a "no address", aka homeless person, ...
* @groups({"write"})
* *
* @var bool * @var bool
*/ */
@ -128,6 +143,7 @@ class Address
* @var Point|null * @var Point|null
* *
* @ORM\Column(type="point", nullable=true) * @ORM\Column(type="point", nullable=true)
* @groups({"write"})
*/ */
private $point; private $point;
@ -138,6 +154,7 @@ class Address
* *
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty") * @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty")
* @ORM\JoinColumn(nullable=true) * @ORM\JoinColumn(nullable=true)
* @groups({"write"})
*/ */
private $linkedToThirdParty; private $linkedToThirdParty;

View File

@ -33,7 +33,21 @@ export default {
methods: { methods: {
addNewAddress({ address, modal }) { addNewAddress({ address, modal }) {
console.log('@@@ CLICK button addNewAdress', address); console.log('@@@ CLICK button addNewAdress', address);
this.$store.dispatch('addAddress', address.selected); const newAddress = {
'isNoAddress': address.isNoAddress,
'street': address.selected.address.street,
'streetNumber': address.selected.address.streetNumber,
'postcode': address.selected.address.postcode.id,
'floor': address.floor,
'corridor': address.corridor,
'steps': address.steps,
'flat': address.flat,
'buildingName': address.buildingName,
'distribution': address.distribution,
'extra': address.extra,
'point': address.selected.address.point.coordinates
};
this.$store.dispatch('addAddress', newAddress);
modal.showModal = false; modal.showModal = false;
} }
} }

View File

@ -1,8 +1,7 @@
import 'es6-promise/auto'; import 'es6-promise/auto';
import { createStore } from 'vuex'; import { createStore } from 'vuex';
// le fetch POST serait rangé dans la logique du composant qui appelle AddAddress import { postAddress } from '../../_api/AddAddress'
//import { postAddress } from '... api'
const debug = process.env.NODE_ENV !== 'production'; const debug = process.env.NODE_ENV !== 'production';
@ -10,11 +9,14 @@ const store = createStore({
strict: debug, strict: debug,
state: { state: {
address: {}, address: {},
errorMsg: {} errorMsg: []
}, },
getters: { getters: {
}, },
mutations: { mutations: {
catchError(state, error) {
state.errorMsg.push(error);
},
addAddress(state, address) { addAddress(state, address) {
console.log('@M addAddress address', address); console.log('@M addAddress address', address);
state.address = address; state.address = address;
@ -23,19 +25,19 @@ const store = createStore({
actions: { actions: {
addAddress({ commit }, payload) { addAddress({ commit }, payload) {
console.log('@A addAddress payload', payload); console.log('@A addAddress payload', payload);
commit('addAddress', payload); // à remplacer par //commit('addAddress', payload); // à remplacer par la suite
//fetch POST qui envoie l'adresse, et récupère la confirmation que c'est ok. //fetch POST qui envoie l'adresse, et récupère la confirmation que c'est ok.
//La confirmation est l'adresse elle-même. //La confirmation est l'adresse elle-même.
//
// postAddress(payload) postAddress(payload)
// .fetch(address => new Promise((resolve, reject) => { .then(address => new Promise((resolve, reject) => {
// commit('addAddress', address); commit('addAddress', address);
// resolve(); resolve();
// })) }))
// .catch((error) => { .catch((error) => {
// state.errorMsg.push(error.message); commit('catchError', error);
// }); });
} }
} }
}); });

View File

@ -1,5 +1,5 @@
/* /*
* Endpoint chill_api_single_country_index * Endpoint chill_api_single_country__index
* method GET, get Country Object * method GET, get Country Object
* @returns {Promise} a promise containing all Country object * @returns {Promise} a promise containing all Country object
*/ */
@ -15,7 +15,7 @@ const fetchCountries = () => {
}; };
/* /*
* Endpoint chill_api_single_postal_code_index * Endpoint chill_api_single_postal_code__index
* method GET, get Country Object * method GET, get Country Object
* @returns {Promise} a promise containing all Postal Code objects filtered with country * @returns {Promise} a promise containing all Postal Code objects filtered with country
*/ */
@ -30,9 +30,9 @@ const fetchCities = (country) => {
}; };
/* /*
* Endpoint chill_api_single_address_reference_index * Endpoint chill_api_single_address_reference__index
* method GET, get AddressReference Object * method GET, get AddressReference Object
* @returns {Promise} a promise containing all AddressReference objects filtered with country * @returns {Promise} a promise containing all AddressReference objects filtered with postal code
*/ */
const fetchReferenceAddresses = (postalCode) => { const fetchReferenceAddresses = (postalCode) => {
console.log('<<< fetching references addresses for', postalCode); console.log('<<< fetching references addresses for', postalCode);
@ -45,8 +45,31 @@ const fetchReferenceAddresses = (postalCode) => {
}); });
}; };
/*
* Endpoint chill_api_single_address__entity__create
* method POST, post Address Object
* @returns {Promise}
*/
const postAddress = (address) => {
console.log(address);
const url = `/api/1.0/main/address.json?`;
const body = address;
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(body)
}).then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
};
export { export {
fetchCountries, fetchCountries,
fetchCities, fetchCities,
fetchReferenceAddresses fetchReferenceAddresses,
postAddress
}; };