Refactor: Make the Notification not send themself but rather create their content
This commit is contained in:
@@ -6,11 +6,4 @@ public class MailNotification extends Notification {
|
||||
public MailNotification(String content, User user, SendNotificationStrategy strategy) {
|
||||
super(content, user, strategy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send() {
|
||||
if (isSendable())
|
||||
strategy.send(user.id() + " Mail: " + user.name() + " " + content);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import utils.SendNotificationStrategy;
|
||||
public abstract class Notification {
|
||||
protected String content;
|
||||
protected User user;
|
||||
/**
|
||||
* Pas de change state car chemin multiple. On reste sur des enum !
|
||||
*/
|
||||
protected NotificationState state;
|
||||
protected SendNotificationStrategy strategy;
|
||||
|
||||
@@ -20,15 +23,29 @@ public abstract class Notification {
|
||||
return this.state != NotificationState.SENT && this.state != NotificationState.READ;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
/**
|
||||
* Transition d'état spéciale pour indiquer que l'envoie de notification est en échec
|
||||
*/
|
||||
public void setKoState() {
|
||||
state = NotificationState.KO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pas de change state car route non linéaire. On reste sur des enum !
|
||||
* Fait la transition des états
|
||||
*/
|
||||
public void transitionState() {
|
||||
switch (state) {
|
||||
case PENDING -> state = NotificationState.SENT;
|
||||
case SENT -> state = NotificationState.READ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public abstract void send();
|
||||
public String getContent() {
|
||||
if (isSendable()) {
|
||||
transitionState();
|
||||
return strategy.makeContent(user.id() + " Push: " + user.name() + " " + content);
|
||||
}
|
||||
setKoState();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,4 @@ public class PushNotification extends Notification {
|
||||
public PushNotification(String content, User user, SendNotificationStrategy strategy) {
|
||||
super(content, user, strategy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send() {
|
||||
if (isSendable())
|
||||
strategy.send(user.id() + " Push: " + user.name() + " " + content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,4 @@ public class SmsNotification extends Notification {
|
||||
public SmsNotification(String content, User user, SendNotificationStrategy strategy) {
|
||||
super(content, user, strategy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send() {
|
||||
if (isSendable())
|
||||
strategy.send(user.id() + " Sms: " + user.name() + " " + content);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user