While creating a route, a waypoint or any other resource there are added many pictures or media files contained in the request.
Currently, first the resource is added to the database and then the file is saved to disk.
I would suggest a change in the order of this routine. I think first the file should be saved to disk and then the database data.
In my opinion, this has the advantage, if the process of saving the file to disk fails, no database resource is created.
The best solution to this issue would be to check if saving to the database or saving of the file failed, and then delete already created resources and files.
In addition, I would suggest refactoring the process of creating a filename and saving the file to disk into its own method, maybe into its own service.
While creating a route, a waypoint or any other resource there are added many pictures or media files contained in the request.
Currently, first the resource is added to the database and then the file is saved to disk.
I would suggest a change in the order of this routine. I think first the file should be saved to disk and then the database data.
In my opinion, this has the advantage, if the process of saving the file to disk fails, no database resource is created.
The best solution to this issue would be to check if saving to the database or saving of the file failed, and then delete already created resources and files.
In addition, I would suggest refactoring the process of creating a filename and saving the file to disk into its own method, maybe into its own service.