Skip to content

Commit 8506e98

Browse files
author
Adnane Miliari
committed
🔧implement conditional email service configuration based on profiles
1 parent 946ed8e commit 8506e98

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

notification/src/main/java/dev/nano/notification/NotificationService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public interface NotificationService {
88

9-
public NotificationDTO getNotification(Long notificationId);
10-
public List<NotificationDTO> getAllNotification();
11-
public void sendNotification(NotificationRequest notificationRequest);
9+
NotificationDTO getNotification(Long notificationId);
10+
List<NotificationDTO> getAllNotification();
11+
void sendNotification(NotificationRequest notificationRequest);
1212
}

notification/src/main/java/dev/nano/notification/NotificationServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.nano.notification;
22

33
import dev.nano.clients.notification.NotificationRequest;
4-
import dev.nano.notification.aws.AWSEmailService;
4+
import dev.nano.notification.email.EmailService;
55
import lombok.AllArgsConstructor;
66
import org.springframework.stereotype.Service;
77

@@ -14,7 +14,7 @@ public class NotificationServiceImpl implements NotificationService {
1414

1515
private final NotificationRepository notificationRepository;
1616
private final NotificationMapper notificationMapper;
17-
private final AWSEmailService emailService;
17+
private final EmailService emailService;
1818

1919
@Override
2020
public NotificationDTO getNotification(Long notificationId) {

notification/src/main/java/dev/nano/notification/aws/AWSConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
99
import org.springframework.context.annotation.Bean;
1010
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.context.annotation.Profile;
1112
import org.springframework.core.env.Environment;
1213

1314
@Configuration
15+
@Profile("eks")
1416
public class AWSConfig {
15-
private Environment environment;
17+
private final Environment environment;
1618

1719
public AWSConfig(Environment environment) {
1820
this.environment = environment;

notification/src/main/java/dev/nano/notification/aws/AWSEmailService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
44
import com.amazonaws.services.simpleemail.model.*;
5+
import dev.nano.notification.email.EmailService;
56
import lombok.AllArgsConstructor;
7+
import org.springframework.context.annotation.Profile;
68
import org.springframework.stereotype.Service;
79

810
@Service
911
@AllArgsConstructor
10-
public class AWSEmailService {
12+
@Profile("eks")
13+
public class AWSEmailService implements EmailService {
1114

1215
private final AmazonSimpleEmailService emailService;
1316

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package dev.nano.notification.email;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.context.annotation.Profile;
5+
import org.springframework.stereotype.Service;
6+
7+
@Service
8+
@Profile("!eks")
9+
@Slf4j
10+
public class DefaultEmailService implements EmailService {
11+
@Override
12+
public void send(String to, String content, String subject) {
13+
log.info("Simulated email sent to: {}, subject: {}, content: {}", to, subject, content);
14+
}
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dev.nano.notification.email;
2+
3+
public interface EmailService {
4+
void send(String to, String content, String subject);
5+
}

0 commit comments

Comments
 (0)