Hexagonal architecture with api-platform - api-platform.com

I'm going to create an api with api-platform and I want to separate my business logic from framework.
For example I want to allow users to register new accounts and POST: /user is good for that. Api-platform is doing all the magic (handler request, validate data, save new user (doctrine), return response). But my business logic wants to send invitation email and make other things during creating new user. How should I do that to be fine with api-platform?
Should I create custom operation POST: /register, inside call my use-case register($user)? Should I create custom repository interface and inside save(User) implementation call POST: /user?
Or should I use event system and split my "big" use-case (register) to small ones depends on what my business logic need to do (validate data, send invitation email, etc.)? And if I want to register new user from CLI my command has to use all of this small use-cases?
Or should I completely forget about all api-platform magic and if my business logic is more then CRUD I have to care of everything by my self (validate data, save to DB, send email, etc.)?

There are a places for custom business logic https://api-platform.com/docs/core/extending/.
Good point to add business logic are Data Persisters. I can use there my own Repository to save user, send email, etc.

Related

Add members to an existing conversation

(New to Bot Framework)(Using botbuilder SDK4) I have a requirement of passing the control to an agent in case the bot does not recognise the intent of the phrase entered by the customer. I want to connect the customer and the agent using the bot. In my current attempt to achieve this, I am using adapter.continueConversation(conversationReference, logic)
But then I realised, there is an entity called members in the conversation (there exists a method getConversationMembers in botframework-connector/lib/connectorApi/operations/conversations.d.ts).
Question 1: Can I use this attribute for the aforementioned use case?
Question 2: How to add multiple members in a conversation?
Creating a custom middleware is the most efficient way to handover a conversation from the bot to an agent. Here is an example of a bot that implements middleware to forward messages between users and agents with proactive messages. The example uses an array based handover provider to save the state of every conversation. You should implement your own provider with a database structure to fit your project requirements.
Hope this helps.

Laravel 5.4 How to reset password with sms and notifications

I have see some articles, didn't find the solution.
I know Laravel 5.4's notifications have sms via Nexmo. And Nexmo is a third party website, one sms cost €0.0442 in my country.
But we have our own sms provider, and I had make it work. Our users have to provide real name, email, mobilephone. And the mobilephone have to be verified. I wrote a simple function to do it, with the provider's api.
I would like to implement the laravel notifications, make passwords reset via sms, like emails. How to do this?
The laravel password reset logic can be found in:
vendor/laravel/framework/src/Illuminate/Foundation/Auth/SendsPasswordResetEmails.php.
You can override the functions in there to accomodate for your sms needs.
But since that file is in the vendor folder you have/need to add the functions to:
app/Http/Controllers/Auth/ForgotPasswordController.php
(functions in the ForgotPasswordController override functions in SendsPasswordResetEmails)
Laravel has built in feature for resetting password via email, you can get lot of tutorials in this regards moreover if you want to create for sms validation then you will need a table which will hold the PIN (Personal Identification Number) for particular user, so suppose you have a table named password_pin you need to have columns with users_id, pin, validated_at, Now once you send a sms you can insert the data into these table and while verifying you can place updated with the validated at, you need to have logic where you want to have PIN to be validated once or can be verified more than once. As the validation happens you can show a form for updating the password and can update the password through those.
Note: You can must have a logic of validation in mind to conclude the architecture.
It will be more easier for us to guide you if you provide us the code. Hope this helps.

Addressing the customer by their first name in CRM 2011 email templates triggered by Service Activity workflows

If a customer schedules a service activity using my web application and I want to send them an automated confirmation email, it seems I have two options:
Have the workflow create and send a new email message. On this view (see below), you can use fields from related entities on the service activity (e.g. the customer's first name).
Have the workflow use an email template. It seems that email templates do not allow you to access fields from a related entity, like first name, so the only option here is to address the customer by their FULL name.
Are there any solutions that I missed, or am I stuck with the first option if I want to address the customer in a personal, natural way on this automated email?
Unfortunatly, the CRM is pretty limited on that aspect. The best workaround is to add the firstname to the Service Activity entity. May suit you or not. Otherwise, it is achievable through a the SDK, but that's much more complicated if you don't already use it.

MVC: Where to trigger user registration emails

I am building an MVC application (using the Zend Framework).
When users first register, the applicaiton sends them an email. My question is, where should I trigger this email from? The model or the controller? My thoughts are as follows:
In some ways, the model makes sense, since sending a registration email is part of my business logic. Users must click the link in the mail to validate their email address.
But by putting it in the model, I am 'encumbering' the model. The model's registerUser action is then only useful within the context of an application that needs emails sent for every registration.
Instead, by triggering the email from within the controller, my controller would be a litter 'fatter', but my model a little more 'fine grained'.
I have written an email service which actually configures and sends the email, and I think this is a good design decision. I am really just asking where I should be calling this service from.
Your thoughts are most appreciated!
According to Zend Framework's definition of MVC, you should put send the email from the controller:
Controllers...decide which view to display based on the user's request.
Models, on the other hand, contain:
...basic functionality behind a set of abstractions.
An email may be considered a "view" in that it displays information to the user. It is the controller's job to activate this "view."
In my opinion, I would want this in the model, as I would consider this an assumed process of the create user method, rather than any specific interaction with the user making the request.
In other words, since I would always want this email sent, regardless of the source of the request, I would identify this as a natural byproduct of the create user action, similar to a record being saved in a database.
You might want to look into using something like NServiceBus to queue messages to be sent to your Email Service.
This way you can have NServiceBus subscribe to an event that occurs and omit any manual firing of the email service etc.
Ultimately you want a failsafe way of ensuring your messages get to the intended people. This kind of framework will greatly help you ensure that this happens.
Alternatively you could store the emails to be sent inside your database and have your email service check the database queue every x minutes for new emails to send and omit the need for triggering the email sending.
Again, doing it this way will ensure at the least that the emails get sent. Should the network go down or some other disruption occur during the sending of each email you can simply leave them in the queue until the network comes back up.

Should the model or controller be responsible for sending emails?

In a MVC web application, I often send emails.
I usually do it in the controller, as I load all my views from the controller (including email views).
Now, however, I have some code where the email sends from the model.
Which tier is email generally sent from? Does it matter? Does it need to be consistent?
A controller should ideally be like an operator that connects a view to a model. This either belongs in the model or service layer.
I would argue that this belongs in the Model layer only if you have a model object that is solely responsible for sending e-mails. You don't want to comingle presentation and logic, that's the whole point of separation of concerns in Model-View-Controller.
This type of logic should reside in a service layer. You could then use dependency injection to inject the service into the controller and call EmailSenderService.sendEmail();

Resources