Adds backend email validation for contact email. (Issue #128)
This commit is contained in:
parent
934702a734
commit
1f97eaf349
|
@ -27,10 +27,12 @@ public class ContactEmail {
|
|||
public @ResponseBody
|
||||
ResponseEntity sendContactEmail(@RequestBody ContactEmailModel contactEmailModel, Principal principal) {
|
||||
try {
|
||||
this.contactEmailManager.emailValidation(contactEmailModel);
|
||||
this.contactEmailManager.sendContactEmail(contactEmailModel, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
} catch (Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,4 +34,13 @@ public class ContactEmailManager {
|
|||
|
||||
apiContext.getUtilitiesService().getMailService().sendSimpleMail(mail);
|
||||
}
|
||||
|
||||
public void emailValidation(ContactEmailModel contactEmailModel) throws Exception {
|
||||
if (contactEmailModel.getSubject() == null || contactEmailModel.getSubject().trim().isEmpty()) {
|
||||
throw new Exception("Subject is empty");
|
||||
}
|
||||
if (contactEmailModel.getDescription() == null || contactEmailModel.getDescription().trim().isEmpty()) {
|
||||
throw new Exception("Description is empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue