I give up
This commit is contained in:
@@ -29,11 +29,8 @@ public class EmailController {
|
|||||||
@PostMapping("/mail/send")
|
@PostMapping("/mail/send")
|
||||||
public ResponseEntity<String> send(@RequestBody String payload) {
|
public ResponseEntity<String> send(@RequestBody String payload) {
|
||||||
try {
|
try {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
|
|
||||||
Map<String, Object> map = mapper.readValue(payload, new TypeReference<Map<String, Object>>() {});
|
service.send("laurent0206.cr@gmail.com", "Hello from Board Mate!", payload);
|
||||||
|
|
||||||
//service.send("laurent0206.cr@gmail.com", "Hello from Board Mate!", map);
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ public class SendgridService {
|
|||||||
this.senderEmail = email;
|
this.senderEmail = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(String dst, String subject, Map<String, Object> payload) throws ServiceException {
|
public void send(String dst, String subject, String payload) throws ServiceException {
|
||||||
try {
|
try {
|
||||||
Content content = new Content("text/plain", formatContent(payload));
|
Content content = new Content("text/plain",payload);
|
||||||
Mail mail = new Mail(this.senderEmail, subject, new Email(dst), content);
|
Mail mail = new Mail(this.senderEmail, subject, new Email(dst), content);
|
||||||
|
|
||||||
Request request = new Request();
|
Request request = new Request();
|
||||||
@@ -47,29 +47,4 @@ public class SendgridService {
|
|||||||
throw new ServiceException("Failed to send email : " + e.getMessage());
|
throw new ServiceException("Failed to send email : " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatContent(Map<String, Object> payload) throws JsonProcessingException {
|
|
||||||
|
|
||||||
StringBuilder mailBody = new StringBuilder();
|
|
||||||
|
|
||||||
mailBody.append("White: ")
|
|
||||||
.append(payload.get("white_name"))
|
|
||||||
.append("\n");
|
|
||||||
|
|
||||||
mailBody.append("Black: ")
|
|
||||||
.append(payload.get("black_name"))
|
|
||||||
.append("\n");
|
|
||||||
|
|
||||||
mailBody.append("Time Control: ")
|
|
||||||
.append(payload.get("time_control"))
|
|
||||||
.append(" + ")
|
|
||||||
.append(payload.get("increment"))
|
|
||||||
.append("\n");
|
|
||||||
|
|
||||||
mailBody.append("Timestamp: ")
|
|
||||||
.append(payload.get("timestamp"))
|
|
||||||
.append("\n\n");
|
|
||||||
|
|
||||||
return mailBody.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ public class TwilioService {
|
|||||||
|
|
||||||
public void send(String msg) throws ServiceException {
|
public void send(String msg) throws ServiceException {
|
||||||
try {
|
try {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
Message.creator(new PhoneNumber("+32496533833"), this.serviceId, msg).create();
|
||||||
JsonNode jsonNode = mapper.readTree(msg);
|
|
||||||
String content = jsonNode.get("content").asText();
|
|
||||||
Message.creator(new PhoneNumber("+32496533833"), this.serviceId, content).create();
|
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
throw new ServiceException("Failed to send message :" + e.getMessage());
|
throw new ServiceException("Failed to send message :" + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user