I have started a Symfony 6 project using the classic RegitrationController (that inherits from AbstractController), RegistrationFormType and User entity obtained from:
symfony console make:registration-form
I can now create a user through the form that adds a new entity in my database.
I also wanted to create an API using API Plateform. I have then added a couple modifications to my User schema and the API is working, I can create a user through the API too.
I now wonder how to properly couple the form/controller and the API. Indeed, in order not to have redondant code and use the same User schema, I would like to find a way that my RegistrationFormType works with the API. Also note that on the one hand I have code in my RegitrationController that, e.g., hashes the user password before saving it to the database. On the other hand this is achieved by a UserDataPersister on the API side.
What is the good practice to factorize that code and structure my architecture in order to be able to create users from both the form and the API? (I would like to keep the cool things that the Symfony AbstractController provides like createForm, handleRequest, renderForm, etc.)
I cannot find examples using both Form/Controller and API Plateform.
Is it a bad idea to have the Form/Controller and API in the same project?