Skip to content

Commit

Permalink
🔧implement conditional email service configuration based on profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Adnane Miliari committed Nov 28, 2024
1 parent 946ed8e commit 8506e98
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public interface NotificationService {

public NotificationDTO getNotification(Long notificationId);
public List<NotificationDTO> getAllNotification();
public void sendNotification(NotificationRequest notificationRequest);
NotificationDTO getNotification(Long notificationId);
List<NotificationDTO> getAllNotification();
void sendNotification(NotificationRequest notificationRequest);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.nano.notification;

import dev.nano.clients.notification.NotificationRequest;
import dev.nano.notification.aws.AWSEmailService;
import dev.nano.notification.email.EmailService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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

private final NotificationRepository notificationRepository;
private final NotificationMapper notificationMapper;
private final AWSEmailService emailService;
private final EmailService emailService;

@Override
public NotificationDTO getNotification(Long notificationId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;

@Configuration
@Profile("eks")
public class AWSConfig {
private Environment environment;
private final Environment environment;

public AWSConfig(Environment environment) {
this.environment = environment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.model.*;
import dev.nano.notification.email.EmailService;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class AWSEmailService {
@Profile("eks")
public class AWSEmailService implements EmailService {

private final AmazonSimpleEmailService emailService;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.nano.notification.email;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

@Service
@Profile("!eks")
@Slf4j
public class DefaultEmailService implements EmailService {
@Override
public void send(String to, String content, String subject) {
log.info("Simulated email sent to: {}, subject: {}, content: {}", to, subject, content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.nano.notification.email;

public interface EmailService {
void send(String to, String content, String subject);
}

0 comments on commit 8506e98

Please sign in to comment.