I have a question between the controller and the service, so I leave a question.
Below is an example.
There is an API that creates a company.
The process of creating a company is
- Check if the company you want to register is already registered.
- Create a company.
- Create policies for the company.
- Leave a log that the company has been created.
As above, let’s assume that the process of API is largely divided into four categories.
There are two ways to implement it
Method 1
- The processes are implemented as a function of the service file one by one.
- The functions created in No. 1 are called sequentially from the controller.
Method 2
- The processes are implemented as a function of the service file one by one.
- One function that calls the functions created in No. 1 sequentially is implemented in the service file.
- Call the function created in No. 2 from the controller.
I tried to find something related to this, but I couldn’t find it, so I’m leaving a question.
I understand that the service file is intended to hide and reuse business logic
Which one is better
If anyone has been thinking about this, please reply!