I am refactoring the code including the controller.js class to handle the business logic. This is that from Map.js it will use the Controller methods to manage the data access insertions.
Map.js will has a new constant: const [controlMng, setControlMng] = useState(new Controller(session)); and will use the following methods:
controlMng.saveLocationsToPOD(); This is used to save the current session locations object to the user's pod
controlMng.canAdd() This is used to check if an insertion is need due to a weird behaviour of the code
controlMng.updateUserLocations(originalMarkers); This is used to update the current locations (previously loaded from the POD.
An example of workflow would be:
The user logs in LoMap app
The locations are read from the user's POD
The locations are loaded in our domain model with controlMng.updateUserLocations(originalMarkers);
When the user adds a new location it check if it that change has been done with controlMng.canAdd()
If true, the locations are uploaded to the user's POD with controlMng.saveLocationsToPOD();
Otherwise, nothing changes.
I also re-write the classes: ./models/user.js, ./models/location.js, ./util/Convertor.js
I currently working on ./handlers/podAccess.js to remove all the used methods. And also refactoring the read method to the controller class (now still in Map.js)
Important things
Now the LocationLM class has new fields; date (when was the location created) and owner (who has create that location). About this last, we need to think in a way to include in the front view to show it to the user.
We still missing the description field in the front view.
I have changed the resource URL scheme, so now the locations that are stored in the pod will not be readed since they use a different schema.
We should think in a new place to call the method controlMng.saveLocationsToPOD(); inside Map.js. Right now it works but I saves only the previously added maker. For example, if the user add a new location (loc1) it will not be stored in the POD but if in the same session the user adds a new one (loc2), the first one (loc1) will be stored in the POD but not the second (loc2).
This is becase I am calling controlMng.saveLocationsToPOD(); inside const updateLastMarker = async () => { that has the marker without the new one. I tried to do it inside // Set canAddMarker to true when isInteractive changes to true React.useEffect( () => { line 244 that is when the markers are updated but when running an error raise and the map is not shown.
Changes suggested
Add a new button "save" so when pressed all the locations will be saved into the POD. (Or even all the changes during the session). We can also look for a better place in the code to call the function.
Changes in the front view to include "owner" in locations and a way to allow the user to enter a location's description when creating one.
The method updateUserLocations(list) from controller return an array with the locations in frontView model with some fields updated; domainID and owner (theses can helps with the logic and also passing the owner to the front. What I don't know if the array of markers can be modified without problems)
Other things
Due to the weird behaviour of the app, I was forced to include an error control to avoid inserting empty locations to the POD. When converting a location from view object to domain model object, if an StringInvalidFormat error is thrown, it is skipped (This means the location had an empty privacy (needed to know where to store it), empty category or empty name. The description is not consider yet because there's no way to added). This can be removed if we call controlMng.saveLocationsToPOD(); somewhere else.
I am refactoring the code including the controller.js class to handle the business logic. This is that from Map.js it will use the Controller methods to manage the data access insertions. Map.js will has a new constant:
const [controlMng, setControlMng] = useState(new Controller(session));
and will use the following methods:An example of workflow would be:
I also re-write the classes: ./models/user.js, ./models/location.js, ./util/Convertor.js
I currently working on ./handlers/podAccess.js to remove all the used methods. And also refactoring the read method to the controller class (now still in Map.js)
Important things
Changes suggested
Other things
Due to the weird behaviour of the app, I was forced to include an error control to avoid inserting empty locations to the POD. When converting a location from view object to domain model object, if an StringInvalidFormat error is thrown, it is skipped (This means the location had an empty privacy (needed to know where to store it), empty category or empty name. The description is not consider yet because there's no way to added). This can be removed if we call
controlMng.saveLocationsToPOD();
somewhere else.