Рефакторинг EventDistributorService
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-03-18 11:08:02 +03:00
parent 90c54f0d76
commit 0e575cc09f
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
4 changed files with 24 additions and 89 deletions

View File

@ -47,7 +47,7 @@ public class EventDistributorService implements EventDistributor {
final PreCheckoutQuery preCheckoutQuery = update.getPreCheckoutQuery(); final PreCheckoutQuery preCheckoutQuery = update.getPreCheckoutQuery();
if (Checker.checkNotNull(preCheckoutQuery)) { if (Checker.checkNotNull(preCheckoutQuery)) {
getHandler(preCheckoutQuery.getClass().getName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(preCheckoutQuery))); getHandler(preCheckoutQuery.getClass().getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(preCheckoutQuery)));
return; return;
} }
@ -62,11 +62,11 @@ public class EventDistributorService implements EventDistributor {
if (update.getMyChatMember() != null) { if (update.getMyChatMember() != null) {
final ChatMemberUpdated chatMember = update.getMyChatMember(); final ChatMemberUpdated chatMember = update.getMyChatMember();
if ("kicked".equals(chatMember.getNewChatMember().getStatus())) { if ("kicked".equals(chatMember.getNewChatMember().getStatus())) {
getHandler(Unsubscribe.class.getName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(UnsubscribeConvert.apply(chatMember)))); getHandler(Unsubscribe.class.getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(UnsubscribeConvert.apply(chatMember))));
return; return;
} }
if ("member".equals(chatMember.getNewChatMember().getStatus())) { if ("member".equals(chatMember.getNewChatMember().getStatus())) {
getHandler(Subscribe.class.getName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(SubscribeConvert.apply(chatMember)))); getHandler(Subscribe.class.getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(SubscribeConvert.apply(chatMember))));
return; return;
} }
} }
@ -78,7 +78,7 @@ public class EventDistributorService implements EventDistributor {
} else { } else {
final Mail mail = CallbackQueryConvert.apply(callbackQuery); final Mail mail = CallbackQueryConvert.apply(callbackQuery);
getHandler(Mail.class.getName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(mail))); getHandler(Mail.class.getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(mail)));
} }
} }
@ -86,10 +86,10 @@ public class EventDistributorService implements EventDistributor {
final Long fromId = message.getChat().getId(); final Long fromId = message.getChat().getId();
if (fromId < 0) { if (fromId < 0) {
final ChatMail chatMail = MessageChatMailConvert.apply(message); final ChatMail chatMail = MessageChatMailConvert.apply(message);
getHandler(ChatMail.class.getName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(chatMail))); getHandler(ChatMail.class.getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(chatMail)));
} else { } else {
final Mail mail = MessageMailConvert.apply(message); final Mail mail = MessageMailConvert.apply(message);
getHandler(Mail.class.getName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(mail))); getHandler(Mail.class.getSimpleName()).ifPresent(handlers -> handlers.forEach(handler -> handler.handle(mail)));
} }
} }

View File

@ -30,7 +30,7 @@ public class PreCheckoutQueryHandler implements EventHandler<PreCheckoutQuery> {
@Override @Override
public String getEventType() { public String getEventType() {
return PreCheckoutQuery.class.getName(); return PreCheckoutQuery.class.getSimpleName();
} }
} }

View File

@ -1,53 +1,17 @@
package dev.struchkov.godfather.telegram.domain.event; package dev.struchkov.godfather.telegram.domain.event;
import dev.struchkov.godfather.main.domain.event.Event; import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime; import java.time.LocalDateTime;
public class Subscribe implements Event { @Getter
@Setter
public static final String TYPE = "SUBSCRIBE"; public class Subscribe {
private String telegramId; private String telegramId;
private String firstName; private String firstName;
private String lastName; private String lastName;
private LocalDateTime subscriptionDate; private LocalDateTime subscriptionDate;
public String getTelegramId() {
return telegramId;
}
public void setTelegramId(String telegramId) {
this.telegramId = telegramId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public LocalDateTime getSubscriptionDate() {
return subscriptionDate;
}
public void setSubscriptionDate(LocalDateTime subscriptionDate) {
this.subscriptionDate = subscriptionDate;
}
@Override
public String getEventType() {
return TYPE;
}
} }

View File

@ -1,53 +1,24 @@
package dev.struchkov.godfather.telegram.domain.event; package dev.struchkov.godfather.telegram.domain.event;
import dev.struchkov.godfather.main.domain.event.Event; import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.time.LocalDateTime; import java.time.LocalDateTime;
public class Unsubscribe implements Event { @Getter
@Setter
public static final String TYPE = "UNSUBSCRIBE"; @Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Unsubscribe {
private String telegramId; private String telegramId;
private String firstName; private String firstName;
private String lastName; private String lastName;
private LocalDateTime subscriptionDate; private LocalDateTime subscriptionDate;
public String getTelegramId() {
return telegramId;
}
public void setTelegramId(String telegramId) {
this.telegramId = telegramId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public LocalDateTime getSubscriptionDate() {
return subscriptionDate;
}
public void setSubscriptionDate(LocalDateTime subscriptionDate) {
this.subscriptionDate = subscriptionDate;
}
@Override
public String getEventType() {
return TYPE;
}
} }