Skip to content

Commit 461ccdf

Browse files
committed
notification system added
1 parent 2975347 commit 461ccdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+716
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.lld.notificationsystem;
2+
3+
import com.lld.notificationsystem.constant.MessageType;
4+
import com.lld.notificationsystem.constant.NotificationChannel;
5+
import com.lld.notificationsystem.model.EndUser;
6+
import com.lld.notificationsystem.model.Message;
7+
import com.lld.notificationsystem.model.Template;
8+
import com.lld.notificationsystem.service.MessageTemplateService;
9+
import com.lld.notificationsystem.service.NotificationService;
10+
import com.lld.notificationsystem.service.impl.MessageTemplateServiceImpl;
11+
import com.lld.notificationsystem.service.impl.NotificationServiceImpl;
12+
13+
import java.util.Arrays;
14+
15+
public class MainApplication {
16+
17+
private static void test1() {
18+
MessageTemplateService messageTemplateService = new MessageTemplateServiceImpl();
19+
20+
// Template creation is one time activity
21+
String strTemplate = "Get straight %s rupee discount on ABC today. Special offer.";
22+
Template template = messageTemplateService.createTemplate(MessageType.INFORMATIONAL, strTemplate);
23+
24+
String formattedMessage = String.format(template.getTemplate(), "100");
25+
EndUser endUser = new EndUser("test1", "test1@test.com");
26+
27+
NotificationService notificationService = new NotificationServiceImpl();
28+
notificationService.subscribeToChannels(endUser,
29+
Arrays.asList(NotificationChannel.WHATSAPP, NotificationChannel.FACEBOOK, NotificationChannel.INSTAGRAM));
30+
notificationService.sendMessageTo(endUser, new Message(formattedMessage, template.getMessageType()));
31+
}
32+
33+
private static void test2() {
34+
MessageTemplateService messageTemplateService = new MessageTemplateServiceImpl();
35+
36+
// Template creation is one time activity
37+
String strTemplate = "Your OTP for transaction amount of INR %s is %s";
38+
Template template = messageTemplateService.createTemplate(MessageType.OTP, strTemplate);
39+
40+
String formattedMessage = String.format(template.getTemplate(), "100000", "6839");
41+
EndUser endUser = new EndUser("test2", "test2@test.com");
42+
43+
NotificationService notificationService = new NotificationServiceImpl();
44+
notificationService.subscribeToChannels(endUser,
45+
Arrays.asList(NotificationChannel.SMS, NotificationChannel.EMAIL));
46+
notificationService.sendMessageTo(endUser, new Message(formattedMessage, template.getMessageType()));
47+
}
48+
49+
public static void main(String[] args) {
50+
test1();
51+
test2();
52+
}
53+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Design a notification system.
2+
3+
<b> Requirements </b>
4+
5+
1. Applications should be able to send notification through different channels like
6+
SMS, Email, Slack, Facebook, Instagram, WhatsApp etc.
7+
2. Depending on what the end user subscribes to, different end user may get notifications
8+
through multiple channels. Ex: user A might get notification through SMS and WhatsApp,
9+
whereas user B might get notifications through Facebook, Instagram, Slack etc.
10+
3. The system should be able to send high priority notifications like OTP as well as
11+
low priority messages like promotional messages.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.lld.notificationsystem.client;
2+
3+
public interface EmailClient {
4+
void sendEmail(String address, String cc, String bcc, String content);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.lld.notificationsystem.client;
2+
3+
public interface FacebookClient {
4+
void sendNotification(String userDetailsEncrypted, String message);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.lld.notificationsystem.client;
2+
3+
public interface InstagramClient {
4+
void sendNotification(String userDetailsEncrypted, String message);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.lld.notificationsystem.client;
2+
3+
public interface MobilePushNotifierClient {
4+
void sendPush(String deviceToken, String message);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.lld.notificationsystem.client;
2+
3+
public interface SMSClient {
4+
void sendSMS(String phoneNo, String message);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.lld.notificationsystem.client;
2+
3+
public interface SlackNotificationClient {
4+
void sendSlack(String userDetailsEncrypted, String message);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.lld.notificationsystem.client;
2+
3+
public interface WebPushClient {
4+
void sendNotification(String userDetailsEncrypted, String message);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.lld.notificationsystem.client;
2+
3+
public interface WhatsappClient {
4+
void sendNotification(String phoneNo, String message);
5+
}

0 commit comments

Comments
 (0)