Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHEE-296A] Email api #79

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

[PHEE-296A] Email api #79

wants to merge 7 commits into from

Conversation

ankita10r
Copy link
Contributor

@ankita10r ankita10r commented Jun 10, 2024

Description

New email api based on spec

Method: POST
Endpoint: /emails
Description: Sends an email to the specified recipient(s).
Request Header:
Platform tenant id: PH tenant
X-CallbackUrl : Url on which the mail delivered response to be sent
Correlation id
Request Body:
to: List of email addresses of the recipients (array of strings)
subject: Subject of the email (string)
body: Body content of the email (string)

   Responses:
202: Email Accepted to be sent
400: Invalid request
404: Missing fields


The tc design is added in linked pr openMF/ph-ee-integration-test#293

  • PR title should have jira ticket enclosed in [].

    Format: [jira_ticket] description

    ex: [phee-123] PR title.
  • Add a link to the Jira ticket.
  • Describe the changes made and why they were made.

Attached with this is the screenshot of TC passing locally

Screenshot 2024-06-18 at 11 22 00 AM

and
Screenshot 2024-06-18 at 11 21 01 AM

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Followed the PR title naming convention mentioned above.

  • Design related bullet points or design document link related to this PR added in the description above.

  • Updated corresponding Postman Collection or Api documentation for the changes in this PR.

  • Created/updated unit or integration tests for verifying the changes made.

  • Added required Swagger annotation and update API documentation with details of any API changes if applicable

  • Followed the naming conventions as given in https://docs.google.com/document/d/1Q4vaMSzrTxxh9TS0RILuNkSkYCxotuYk1Xe0CMIkkCU/edit?usp=sharing

@Valid @RequestBody EmailRequestDTO emailRequest
) {
if (platformTenantId == null || platformTenantId.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Platform-Tenant-Id header is missing");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supported param validations(etc: email regex) and basic field validations are missing.
Supported header validations are missing.
Error message not in the right format.

@NotEmpty
private String subject;

@NotEmpty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These annotation validations to be handled and sent in phee/fineract specific format.


// Getters and setters

public List<String> getTo() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Lombok for getters and setters

@Autowired
private JavaMailSender mailSender;

@Value("${spring.mail.host}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have to specify 'spring' here? looks like an overhead. we are not using this anywhere else.

boolean flag = false;
String error = null;
try{
((JavaMailSenderImpl) mailSender).setHost(smtpHost);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severe issue:
The values and the mail sender are global( available at startup). Setting those everytime when the API is called is a bad design. This should be created once and reused. My suggestion is to use mailSender bean with these properties use here.



}
private ClientHttpRequestFactory createTimeoutRequestFactory() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could not find a usage for this method.
Again, the rest template should be create as a bean with these settings so that we don't need t create it on the fly every time.

As rest template is going to be deprecated, better stick with webclient / retroft. There is already one implementation added to connector common

EmailService emailService;

@PostMapping
public ResponseEntity<String> sendEmail(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API documentation missing

@@ -22,6 +22,18 @@ spring:
password: ${MYSQL_PASSWORD:password}
driver-class-name: org.drizzle.jdbc.DrizzleDriver

mail:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you attach a demo video with Gmail settings to show that the email is sending successfully with Gmail?

@@ -54,6 +54,9 @@ ext {
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:2.5.5")
implementation("org.springframework.boot:spring-boot-starter-actuator:$springBootVersion")
implementation ("org.springframework.boot:spring-boot-starter-validation:$springBootVersion")
implementation 'org.springframework.boot:spring-boot-starter-mail'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this dependency, I could not find any tests below

@@ -54,6 +54,9 @@ ext {
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:2.5.5")
implementation("org.springframework.boot:spring-boot-starter-actuator:$springBootVersion")
implementation ("org.springframework.boot:spring-boot-starter-validation:$springBootVersion")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these validations may not produce error messages in our custom format. Please be careful with that

emailService.sendEmail(emailRequest,callbackUrl);

return ResponseEntity.status(HttpStatus.ACCEPTED).body("Email accepted to be sent");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send response in JSON format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants