This is a MVC question. Here is the situation:
- I am writing an application where I have βgroupsβ.
- You can invite others to your groups by typing their email and clicking "Invite."
- There are two possibilities that can be called this functionality: a) a web interface and b) an API
- Upon completion of sending the mail, I want to inform the user which letters were sent successfully (that is, if the SMTP transmission was successful. At present, I am not interested in reporting mail errors).
So, Iβm thinking how can I design so that there is no duplication of code. That is, the API and the web interface must share the bulk of the code.
To do this, I can create an invite method inside the group model. Thus, the API and web interface can simply call: groups-> invite ($ email addresses); This method can send emails. But the problem is that I have to access the mail templates, create submissions for letters, and then send letters. In fact, it should be in the "View" part, or at least in the "Controller" part.
What is the most elegant design in this situation?
Note. I really think to write this in Model. My only doubt is that I used to think that sending emails was also a "presentation". Since this can be considered as another form of output generation.
Added after editing.
I understand that View does not have to be displayed in the browser. And I doubt it. Now the problem is that I have a "task list" in my application. We can assign a task to some people. Now the "assignTo" method can be called in two situations: 1) When creating a task 2) reassign the task to someone else.
In both cases, the new assignee must receive an email notification. Therefore, if the "assignTo" method does not send mail, we must duplicate the mail part in two places: "task create controller" and "task reassign controller".
I wanted to avoid this duplication.
Sabya source share