Добавил новые модули domain

This commit is contained in:
Struchkov Mark 2023-02-17 17:58:28 +03:00
parent a103f20dd0
commit a05eb8a403
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
36 changed files with 302 additions and 45 deletions

25
pom.xml
View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.struchkov.godfather.telegram</groupId>
@ -54,7 +55,17 @@
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
<artifactId>telegram-domain-main</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain-simple</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain-quarkus</artifactId>
<version>${project.version}</version>
</dependency>
@ -155,6 +166,16 @@
<artifactId>bot-domain-main</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-domain-quarkus</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-domain-simple</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>

View File

@ -13,7 +13,7 @@
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
<artifactId>telegram-domain-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
@ -18,8 +19,13 @@
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
<artifactId>telegram-domain-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context-simple</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>

View File

@ -1,8 +1,8 @@
package dev.struchkov.godfather.telegram.quarkus.context.service;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.SentBox;
import dev.struchkov.godfather.quarkus.context.service.SendingService;
import dev.struchkov.godfather.quarkus.domain.BoxAnswer;
import dev.struchkov.godfather.quarkus.domain.SentBox;
import io.smallrye.mutiny.Uni;
import org.jetbrains.annotations.NotNull;

View File

@ -20,10 +20,9 @@
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context-simple</artifactId>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain-simple</artifactId>
</dependency>
<dependency>

View File

@ -1,8 +1,8 @@
package dev.struchkov.godfather.telegram.simple.context.service;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.SentBox;
import dev.struchkov.godfather.simple.context.service.SendingService;
import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.simple.domain.SentBox;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
@ -8,22 +9,11 @@
</parent>
<artifactId>telegram-domain</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context-main</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
</dependency>
</dependencies>
<packaging>pom</packaging>
<modules>
<module>telegram-domain-main</module>
<module>telegram-domain-quarkus</module>
<module>telegram-domain-simple</module>
</modules>
</project>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
<version>0.0.49-SNAPSHOT</version>
</parent>
<artifactId>telegram-domain-main</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-domain-main</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
<version>0.0.49-SNAPSHOT</version>
</parent>
<artifactId>telegram-domain-quarkus</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-domain-quarkus</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,147 @@
package dev.struchkov.godfather.telegram.quarkus.domain;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardLine;
import dev.struchkov.godfather.quarkus.domain.BoxAnswer;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.haiti.utils.Inspector;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
import static dev.struchkov.godfather.telegram.domain.UnitPaginationUtil.navigableLine;
public class UnitPage<T> {
/**
* Дополнительные линии клавиатуры. Выводятся после кнопок навигации.
*/
private final List<KeyBoardLine> additionalLines = new ArrayList<>();
/**
* Элементы, которые будут выводиться.
*/
private List<T> elements;
/**
* Номер текущей страницы.
*/
private Integer currentOffset;
/**
* Общее количество элементов на всех страницах.
*/
private Integer countAllElements;
/**
* Функция преобразования элементов с линии.
*/
private Function<T, KeyBoardLine> function;
/**
* Сообщение, которое выводится над результатами
*/
private String message;
/**
* Флаг, определяющий нужно ли заменить старое сообщение или вывести новое (по умолчанию заменять)
*/
private boolean replace;
/**
* Флаг, исключающий добавление строки с навигацией
*/
private boolean removeDefaultNavigableLine;
/**
* Сообщение, которое будет отправлено, если коллекция элементов пустая.
*/
private BoxAnswer emptyElements;
public static <T> UnitPage<T> builder() {
return new UnitPage<>();
}
public UnitPage<T> elements(List<T> elements) {
this.elements = elements;
return this;
}
public UnitPage<T> countAllElements(Integer countAllElements) {
this.countAllElements = countAllElements;
return this;
}
public UnitPage<T> currentOffset(Integer currentOffset) {
this.currentOffset = currentOffset;
return this;
}
public UnitPage<T> additionLine(KeyBoardLine line) {
additionalLines.add(line);
return this;
}
public UnitPage<T> additionLine(KeyBoardButton button) {
additionalLines.add(simpleLine(button));
return this;
}
public UnitPage<T> mapper(Function<T, KeyBoardLine> function) {
this.function = function;
return this;
}
public UnitPage<T> message(String message) {
this.message = message;
return this;
}
public UnitPage<T> replace(boolean replace) {
this.replace = replace;
return this;
}
public UnitPage<T> emptyElements(BoxAnswer boxAnswer) {
this.emptyElements = boxAnswer;
return this;
}
public UnitPage<T> removeDefaultNavigableLine() {
this.removeDefaultNavigableLine = true;
return this;
}
public BoxAnswer build() {
Inspector.isNotNull(currentOffset, countAllElements, function);
if (elements.isEmpty()) {
return emptyElements != null ? emptyElements : BoxAnswer.boxAnswer("Данные не найдены.");
} else {
final List<KeyBoardLine> lines = elements.stream()
.map(function)
.toList();
final InlineKeyBoard.Builder builder = InlineKeyBoard.builder();
lines.forEach(builder::line);
if (!removeDefaultNavigableLine) {
navigableLine(currentOffset, countAllElements).ifPresent(builder::line);
}
additionalLines.forEach(builder::line);
final InlineKeyBoard keyBoard = builder.build();
final BoxAnswer.Builder boxAnswer = BoxAnswer.builder()
.keyBoard(keyBoard)
.replace(true);
if (message != null) {
boxAnswer.message(message);
}
boxAnswer.replace(replace);
return boxAnswer.build();
}
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
<version>0.0.49-SNAPSHOT</version>
</parent>
<artifactId>telegram-domain-simple</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-domain-simple</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,8 +1,8 @@
package dev.struchkov.godfather.telegram.domain;
package dev.struchkov.godfather.telegram.simple.domain;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardLine;
import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.haiti.utils.Inspector;

View File

@ -22,7 +22,7 @@
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
<artifactId>telegram-domain-main</artifactId>
</dependency>
</dependencies>

View File

@ -1,9 +1,9 @@
package dev.struchkov.godfather.telegram.quarkus.sender;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.SendType;
import dev.struchkov.godfather.main.domain.SentBox;
import dev.struchkov.godfather.quarkus.context.service.PreSendProcessing;
import dev.struchkov.godfather.quarkus.domain.BoxAnswer;
import dev.struchkov.godfather.quarkus.domain.SentBox;
import dev.struchkov.godfather.quarkus.domain.action.PreSendProcessing;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert;

View File

@ -1,12 +1,11 @@
package dev.struchkov.godfather.telegram.simple.sender;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.SendType;
import dev.struchkov.godfather.main.domain.SentBox;
import dev.struchkov.godfather.simple.context.service.PreSendProcessing;
import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.simple.domain.SentBox;
import dev.struchkov.godfather.simple.domain.action.PreSendProcessing;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert;
import dev.struchkov.godfather.telegram.simple.context.repository.SenderRepository;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import org.jetbrains.annotations.NotNull;
@ -26,9 +25,12 @@ import java.util.Optional;
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_NOTIFICATION;
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW;
import static dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert.convertInlineKeyBoard;
import static dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert.convertKeyBoard;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
import static java.lang.Boolean.TRUE;
import static java.lang.Integer.parseInt;
public class TelegramSender implements TelegramSending {
@ -63,7 +65,7 @@ public class TelegramSender implements TelegramSending {
public void deleteMessage(@NotNull String personId, @NotNull String messageId) {
final DeleteMessage deleteMessage = new DeleteMessage();
deleteMessage.setChatId(personId);
deleteMessage.setMessageId(Integer.parseInt(messageId));
deleteMessage.setMessageId(parseInt(messageId));
try {
absSender.execute(deleteMessage);
} catch (TelegramApiException e) {
@ -115,10 +117,10 @@ public class TelegramSender implements TelegramSending {
private Optional<SentBox> replace(@NotNull String telegramId, @NotNull String replaceMessageId, @NotNull BoxAnswer boxAnswer, BoxAnswer preparedAnswer, boolean saveMessageId) {
final EditMessageText editMessageText = new EditMessageText();
editMessageText.setChatId(telegramId);
editMessageText.setMessageId(Integer.parseInt(replaceMessageId));
editMessageText.setMessageId(parseInt(replaceMessageId));
editMessageText.enableMarkdown(true);
editMessageText.setText(boxAnswer.getMessage());
editMessageText.setReplyMarkup(KeyBoardConvert.convertInlineKeyBoard((InlineKeyBoard) boxAnswer.getKeyBoard()));
editMessageText.setReplyMarkup(convertInlineKeyBoard((InlineKeyBoard) boxAnswer.getKeyBoard()));
try {
absSender.execute(editMessageText);
return SentBox.optional(telegramId, replaceMessageId, preparedAnswer, boxAnswer);
@ -138,7 +140,7 @@ public class TelegramSender implements TelegramSending {
sendMessage.enableMarkdown(true);
sendMessage.setChatId(telegramId);
sendMessage.setText(boxAnswer.getMessage());
sendMessage.setReplyMarkup(KeyBoardConvert.convertKeyBoard(boxAnswer.getKeyBoard()));
sendMessage.setReplyMarkup(convertKeyBoard(boxAnswer.getKeyBoard()));
boxAnswer.getPayLoad(DISABLE_WEB_PAGE_PREVIEW).ifPresent(isDisable -> {
if (TRUE.equals(isDisable)) sendMessage.disableWebPagePreview();