diff --git a/src/main/java/com/example/demo1/controller/NotificationsController.java b/src/main/java/com/example/demo1/controller/NotificationsController.java new file mode 100644 index 0000000..26266ef --- /dev/null +++ b/src/main/java/com/example/demo1/controller/NotificationsController.java @@ -0,0 +1,73 @@ +package com.example.demo1.controller; + + +import com.example.demo1.model.Notification; +import com.example.demo1.model.notificationsType.SmsNotification; +import com.example.demo1.service.impl.NotificationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +// +@Controller +@RequestMapping("/notifications") +public class NotificationsController { + + + private final NotificationService notificationService; + + @Autowired + public NotificationsController(NotificationService notificationService) { + this.notificationService = notificationService; + } + + @GetMapping() + public String getAllNotifications(Model model){ + model.addAttribute("notifications", notificationService.getAllNotifications()); + return "notificationsView/notifications"; + + } + + @GetMapping("/{id}") + public String getNotificationById(@PathVariable("id") int id,Model model){ + model.addAttribute("notifications", notificationService.getNotificationById(id)); + return "notificationsView/notifications"; + } + + + @PostMapping("/add") + @ResponseBody + public String addNotification(){ + SmsNotification notification = notificationService.addNotification(); + + return notification.toString() + "- notification added"; + } + + @PutMapping("/update/{id}") + @ResponseBody + public String updateById(@PathVariable("id") int id){ + + //notificationService.updateById(); + + return "Notification with id "+ id +" has been updated"; + } + + + @DeleteMapping("/delete") + @ResponseBody + public String deleteAll(){ + //notificationService.deleteAll(); + return "Notifications have been deleted"; + } + + @DeleteMapping("/delete/{id}") + @ResponseBody + public String deleteById(@PathVariable("id") int id){ + //notificationService.deleteById(); + return "Notification with id " + id + " have been deleted"; + } + + + +} diff --git a/src/main/java/com/example/demo1/model/Notification.java b/src/main/java/com/example/demo1/model/Notification.java new file mode 100644 index 0000000..182382f --- /dev/null +++ b/src/main/java/com/example/demo1/model/Notification.java @@ -0,0 +1,16 @@ +package com.example.demo1.model; + +import lombok.Data; +import lombok.experimental.SuperBuilder; + +import java.util.Date; + +@Data +@SuperBuilder +public abstract class Notification { + + protected int id; + protected String message; + protected Date timestamp; + +} diff --git a/src/main/java/com/example/demo1/model/notificationsType/EmailNotification.java b/src/main/java/com/example/demo1/model/notificationsType/EmailNotification.java new file mode 100644 index 0000000..a512b14 --- /dev/null +++ b/src/main/java/com/example/demo1/model/notificationsType/EmailNotification.java @@ -0,0 +1,18 @@ +package com.example.demo1.model.notificationsType; + +import com.example.demo1.model.Notification; +import lombok.Builder; +import lombok.Data; +import lombok.ToString; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@ToString(callSuper = true) +public class EmailNotification extends Notification { + + private String recipientEmail; + private String senderEmail; + private String subject; + +} diff --git a/src/main/java/com/example/demo1/model/notificationsType/SmsNotification.java b/src/main/java/com/example/demo1/model/notificationsType/SmsNotification.java new file mode 100644 index 0000000..cb44a94 --- /dev/null +++ b/src/main/java/com/example/demo1/model/notificationsType/SmsNotification.java @@ -0,0 +1,17 @@ +package com.example.demo1.model.notificationsType; + +import com.example.demo1.model.Notification; +import lombok.Builder; +import lombok.Data; +import lombok.ToString; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@ToString(callSuper = true) +public class SmsNotification extends Notification { + + private String recipientNumber; + private String senderNumber; + +} diff --git a/src/main/java/com/example/demo1/service/impl/NotificationService.java b/src/main/java/com/example/demo1/service/impl/NotificationService.java new file mode 100644 index 0000000..12eb350 --- /dev/null +++ b/src/main/java/com/example/demo1/service/impl/NotificationService.java @@ -0,0 +1,82 @@ +package com.example.demo1.service.impl; + +import com.example.demo1.model.Notification; +import com.example.demo1.model.notificationsType.EmailNotification; +import com.example.demo1.model.notificationsType.SmsNotification; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Service +public class NotificationService { + + + List notificationList = new ArrayList<>(); + + public List getAllNotifications() { + + List notificationsList = new ArrayList<>(); + + EmailNotification emailNotification1 = EmailNotification.builder() + .id(1) + .message("Email marketing message1") + .recipientEmail("testmail1@gmail.com") + .senderEmail("myemail1@gmail.com") + .timestamp(new Date()) + .build(); + + EmailNotification emailNotification2 = EmailNotification.builder() + .id(2) + .message("Email marketing message2") + .recipientEmail("testmail2@gmail.com") + .senderEmail("myemail2@gmail.com") + .timestamp(new Date()) + .build(); + + SmsNotification smsNotification1 = SmsNotification.builder() + .id(3) + .message("SMS marketing message1") + .recipientNumber("07phoneNumber") + .senderNumber("07myPhoneNumber") + .timestamp(new Date()) + .build(); + + notificationsList.add(emailNotification1); + notificationsList.add(emailNotification2); + notificationsList.add(smsNotification1); + return notificationsList; + + } + + public List getNotificationById(int id){ + //TODO: Get the notification from the database by the id + + //functie facuta doar sa afisez ceva + List notificationsList = new ArrayList<>(); + + notificationsList.add( SmsNotification.builder() + .id(id) + .message("SMS marketing message1") + .recipientNumber("07phoneNumber") + .senderNumber("07myPhoneNumber") + .timestamp(new Date()) + .build()); + + return notificationsList; + } + + public SmsNotification addNotification() { + + //TODO: Add notification to the database + + return SmsNotification.builder() + .id(4) + .message("SMS marketing message2") + .recipientNumber("07123phoneNumber") + .senderNumber("07123myPhoneNumber") + .timestamp(new Date()) + .build(); + } +} diff --git a/src/main/resources/templates/notificationsView/notifications.html b/src/main/resources/templates/notificationsView/notifications.html new file mode 100644 index 0000000..34fdffa --- /dev/null +++ b/src/main/resources/templates/notificationsView/notifications.html @@ -0,0 +1,40 @@ + + + + + + + Notifications + + + +
+

Notifications List

+ + + + + + + + + + + + + + + + + + + + + + +
IDTypeMessageRecipientSenderTimestamp
+
+ + + +