Updated code
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
package net.gepafin.tendermanagement.service.feignClient;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//@FeignClient(name = "mailgunClient", url = "${mailGun_base_url}")
|
||||
public interface MailgunFeignClient {
|
||||
// @PostMapping(value = "/v3/{domain}/messages", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
// ResponseEntity<Void> sendEmail( @RequestPart("from") String from,
|
||||
// @RequestPart("to") List<String> to,
|
||||
// @RequestPart("subject") String subject,
|
||||
// @RequestPart("text") String htmlBody,
|
||||
// @PathVariable("domain") String domain,
|
||||
//// @RequestBody PayloadDTO dto,
|
||||
// //RequestParam
|
||||
//
|
||||
// @RequestHeader HttpHeaders headers);
|
||||
//
|
||||
// public class PayloadDTO {
|
||||
// public String from;
|
||||
// public List<String> to;
|
||||
// public String subject;
|
||||
// public String htmlBody;
|
||||
//
|
||||
// public PayloadDTO(String from, List<String> to, String subject, String htmlBody) {
|
||||
// this.from = from;
|
||||
// this.to = to;
|
||||
// this.subject = subject;
|
||||
// this.htmlBody = htmlBody;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package net.gepafin.tendermanagement.service.feignClient;
|
||||
|
||||
import feign.Headers;
|
||||
import net.gepafin.tendermanagement.model.request.PecEmailRequest;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
//@FeignClient(name = "pecClient", url = "${api.pecUrl}")
|
||||
public interface PecFeignClient {
|
||||
// @PostMapping("/send")
|
||||
// ResponseEntity<Void> sendEmail(@RequestHeader HttpHeaders headers,
|
||||
// @RequestBody PecEmailRequest emailRequest);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,12 @@ package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import com.mashape.unirest.http.HttpResponse;
|
||||
import com.mashape.unirest.http.Unirest;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.dao.EmailLogDao;
|
||||
import net.gepafin.tendermanagement.entities.EmailLogEntity;
|
||||
import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.service.feignClient.MailgunFeignClient;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
@@ -61,14 +59,14 @@ public class MailgunEmailService implements EmailService {
|
||||
.asString();
|
||||
}catch(Exception e) {
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.MAILGUN);
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE);
|
||||
emailLogRequest.setErrorMessage(e.getMessage());
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
throw new RuntimeException("Failed to send email via Mailgun: " + response2.getStatus());
|
||||
}
|
||||
emailLogRequest.setEmailServiceResponse(response2.getBody());
|
||||
}
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.MAILGUN);
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.MAILGUN_SERVICE);
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mashape.unirest.http.HttpResponse;
|
||||
import com.mashape.unirest.http.Unirest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.dao.EmailLogDao;
|
||||
import net.gepafin.tendermanagement.entities.EmailLogEntity;
|
||||
import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
|
||||
@@ -13,14 +10,11 @@ import net.gepafin.tendermanagement.enums.StatusTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.EmailConfig;
|
||||
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
|
||||
import net.gepafin.tendermanagement.model.request.PecEmailRequest;
|
||||
import net.gepafin.tendermanagement.service.feignClient.PecFeignClient;
|
||||
import net.gepafin.tendermanagement.util.Utils;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -47,11 +41,11 @@ public class PecEmailService implements EmailService {
|
||||
|
||||
PecEmailRequest emailRequest = new PecEmailRequest();
|
||||
emailRequest.setSender(emailConfig.getSender());
|
||||
|
||||
emailRequest.setSubject(subject);
|
||||
emailRequest.setBody(body);
|
||||
emailRequest.setUsername(emailConfig.getUsername());
|
||||
emailRequest.setPassword(emailConfig.getPassword());
|
||||
emailRequest.setRecipient(recipientEmails);
|
||||
String url=emailConfig.getUrl();
|
||||
String authToken = emailConfig.getAuthToken();
|
||||
HttpResponse<String> response2=null;
|
||||
@@ -66,14 +60,14 @@ public class PecEmailService implements EmailService {
|
||||
.asString();
|
||||
}catch(Exception e) {
|
||||
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC);
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
||||
emailLogRequest.setErrorMessage(e.getMessage());
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
throw new RuntimeException("Failed to send email via PEC: " + response2.getStatus());
|
||||
}
|
||||
emailLogRequest.setEmailServiceResponse(response2.getBody());
|
||||
}
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC);
|
||||
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
|
||||
EmailLogEntity emailLogEntity= emailLogDao.createEmailLog(emailLogRequest);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user