Skip to content

Commit

Permalink
Query Reply
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammadhussain257 committed Jul 19, 2020
1 parent c8d0ecd commit 0ffde8e
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public class HelpDesk extends BaseEntity<Long> implements Serializable {
private String email;
@NotEmpty(message = "Query is required")
private String query;
private String reply;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum Template {
REGISTRATION_CREDENTIALS("Registration Credentials!!!"),
PATIENT_REGISTRATION("Patient Registration Credentials!!!"),
RESET_PASSWORD("Reset your password!!!"),
APPOINTMENT_CONFIRMATION("Appointment Confirmation!!!");
APPOINTMENT_CONFIRMATION("Appointment Confirmation!!!"),
HELP_DESK_QUERY_REPLY("Help Desk Query Reply!!!");

private final String subject;

Expand All @@ -31,6 +32,7 @@ public String get() {
.put(Template.PATIENT_REGISTRATION, "/mail/patient-registration")
.put(Template.RESET_PASSWORD, "/mail/reset-password.html")
.put(Template.APPOINTMENT_CONFIRMATION, "/mail/appointment-confirmation.html")
.put(Template.HELP_DESK_QUERY_REPLY, "/mail/help-desk-reply.html")
.build();

private EmailConstant() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class EmailDto {
private String patientId;
private String resetToken;
private String message;
private String query;

private Template template;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

import com.pemits.webcare.api.helpdesk.entity.HelpDesk;
import com.pemits.webcare.api.helpdesk.service.HelpDeskService;
import com.pemits.webcare.core.constant.EmailConstant;
import com.pemits.webcare.core.controller.BaseController;
import com.pemits.webcare.core.service.BaseService;
import com.pemits.webcare.core.dto.EmailDto;
import com.pemits.webcare.core.dto.RestResponseDto;
import com.pemits.webcare.core.service.EmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

import static com.pemits.webcare.web.helpdesk.HelpDeskController.URL;

/**
Expand All @@ -20,7 +29,37 @@
public class HelpDeskController extends BaseController<HelpDesk, Long> {
static final String URL = "/v1/helpdesk";

protected HelpDeskController(HelpDeskService helpDeskService) {
private final EmailService emailService;
private final HelpDeskService service;

protected HelpDeskController(
HelpDeskService helpDeskService,
EmailService emailService) {
super(helpDeskService, log.getClass());
this.emailService = emailService;
this.service = helpDeskService;
}

@GetMapping("/reply")
public ResponseEntity<?> replyQuery(@RequestParam Long helpDeskQueryId) {
Optional<HelpDesk> helpDesk = service.findOne(helpDeskQueryId);

if (!helpDesk.isPresent()) {
return new RestResponseDto().fail(HttpStatus.NOT_FOUND, Optional.of("Help Desk Query Not Found"));
}

HelpDesk saved = service.save(helpDesk.get());

// send email
EmailDto emailDto = EmailDto.builder()
.template(EmailConstant.Template.HELP_DESK_QUERY_REPLY)
.to(saved.getEmail())
.toName(saved.getName())
.query(saved.getQuery())
.message(saved.getReply())
.build();
emailService.send(emailDto);

return new RestResponseDto().success(saved);
}
}
12 changes: 12 additions & 0 deletions pemits-web/src/main/resources/db/changelog/changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,16 @@
</createTable>
</changeSet>

<changeSet id="14-alter-help-desk-add-reply" author="Mohammad Hussain">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="help_desk" columnName="reply"/>
</not>
</preConditions>

<addColumn tableName="help_desk">
<column name="reply" type="LONGTEXT"/>
</addColumn>
</changeSet>

</databaseChangeLog>
129 changes: 129 additions & 0 deletions pemits-web/src/main/resources/templates/mail/help-desk-reply.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<!DOCTYPE html>
<html xmlns:th="http:https://www.thymeleaf.org">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
</head>
<style>
.custom-para {
margin: 0;
color: #4c4c4c;
font-weight: 400;
font-size: 16px;
line-height: 1.25
}
</style>
<body>

<div
style="padding:0;margin:0 auto;width:100%!important;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">

<table align="center" bgcolor="#EDF0F3" border="0" cellpadding="0" cellspacing="0"
style="background-color:#edf0f3;table-layout:fixed" width="100%">
<tbody>
<tr>
<td align="center">
<table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0"
style="background-color:#ffffff;margin:0 auto;max-width:512px;width:inherit"
width="512">
<tbody>
<tr>
<td bgcolor="#F6F8FA"
style="background-color:#f6f8fa;padding:12px;border-bottom:1px solid #ececec">
<table border="0" cellpadding="0" cellspacing="0"
style="width:100%!important;min-width:100%!important"
width="100%">
<tbody>
<tr>
<td align="left" valign="middle"><a
style="color:#008cc9;display:inline-block;text-decoration:none">
</a></td>
<td align="right" style="padding:0 0 0 10px" width="100%"><a
style="margin:0;color:#008cc9;display:inline-block;text-decoration:none">
<span
style="word-wrap:break-word;color:#4c4c4c;word-break:break-word;font-weight:400;font-size:14px;line-height:1.429"><span
th:text="${data.getTo()}"></span></span>
</a></td>
<td width="1">&nbsp;</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td style="padding:20px 24px 32px 24px">
<table border="0" cellpadding="0" cellspacing="0"
width="100%">
<tbody>
<tr>
<td style="padding-bottom:20px"><h2
style="margin:0;color:#262626;font-weight:700;font-size:20px;line-height:1.2">
Hello <span
th:text="${data.getToName()}"></span>,</h2></td>
</tr>
<tr>
<td style="padding-bottom:20px">
<p class="custom-para">
Your Query: <span th:text="${data.getQuery()}"></span><br />
Your Answer: <span th:text="${data.getMessage()}"></span>
</p>
<hr>
<hr>
<p class="custom-para">
Regards, <br/>
<em>The PEMITS Team</em>
</p>
<hr/>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table align="center" bgcolor="#EDF0F3" border="0" cellpadding="0"
cellspacing="0"
style="background-color:#edf0f3;padding:0 24px;color:#6a6c6d;text-align:center"
width="100%">
<tbody>
<tr>
<td align="center"
style="padding:16px 0 0 0;text-align:center"></td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0"
width="100%">
<tbody>
<tr>
<td align="center"
style="padding:0 0 12px 0;text-align:center"><p
style="margin:0;color:#6a6c6d;font-weight:400;font-size:12px;line-height:1.333"></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>

</body>
</html>

0 comments on commit 0ffde8e

Please sign in to comment.