From 0e575cc09f758c0312107bbe451144956f7049f7 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sat, 18 Mar 2023 11:08:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20EventDistributorService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumer/EventDistributorService.java | 12 ++--- .../core/handler/PreCheckoutQueryHandler.java | 2 +- .../telegram/domain/event/Subscribe.java | 46 ++-------------- .../telegram/domain/event/Unsubscribe.java | 53 +++++-------------- 4 files changed, 24 insertions(+), 89 deletions(-) diff --git a/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java b/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java index 8c35273..701de9a 100644 --- a/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java +++ b/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java @@ -47,7 +47,7 @@ public class EventDistributorService implements EventDistributor { final PreCheckoutQuery preCheckoutQuery = update.getPreCheckoutQuery(); 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; } @@ -62,11 +62,11 @@ public class EventDistributorService implements EventDistributor { if (update.getMyChatMember() != null) { final ChatMemberUpdated chatMember = update.getMyChatMember(); 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; } 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; } } @@ -78,7 +78,7 @@ public class EventDistributorService implements EventDistributor { } else { 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(); if (fromId < 0) { 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 { 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))); } } diff --git a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/handler/PreCheckoutQueryHandler.java b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/handler/PreCheckoutQueryHandler.java index ba26d13..f607183 100644 --- a/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/handler/PreCheckoutQueryHandler.java +++ b/telegram-core/telegram-core-simple/src/main/java/dev/struchkov/godfather/telegram/simple/core/handler/PreCheckoutQueryHandler.java @@ -30,7 +30,7 @@ public class PreCheckoutQueryHandler implements EventHandler { @Override public String getEventType() { - return PreCheckoutQuery.class.getName(); + return PreCheckoutQuery.class.getSimpleName(); } } diff --git a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Subscribe.java b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Subscribe.java index 9f67f60..c11a3e1 100644 --- a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Subscribe.java +++ b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Subscribe.java @@ -1,53 +1,17 @@ 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; -public class Subscribe implements Event { - - public static final String TYPE = "SUBSCRIBE"; +@Getter +@Setter +public class Subscribe { private String telegramId; private String firstName; private String lastName; 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; - } - } diff --git a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Unsubscribe.java b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Unsubscribe.java index 4137d7e..64d9e43 100644 --- a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Unsubscribe.java +++ b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/event/Unsubscribe.java @@ -1,53 +1,24 @@ 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; -public class Unsubscribe implements Event { - - public static final String TYPE = "UNSUBSCRIBE"; +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class Unsubscribe { private String telegramId; private String firstName; private String lastName; 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; - } - }