Отправка файлов и UniPredicate
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-03-30 19:33:06 +03:00
parent 54a6d3cbd7
commit dc567ad410
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
8 changed files with 112 additions and 101 deletions

View File

@ -1,5 +1,9 @@
package dev.struchkov.godfather.quarkus.domain;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import dev.struchkov.godfather.main.domain.jackson.TelegramPayloadDeserializer;
import dev.struchkov.godfather.main.domain.jackson.TelegramPayloadSerializer;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoard;
import dev.struchkov.haiti.utils.container.ContextKey;
import lombok.Getter;
@ -51,7 +55,9 @@ public class BoxAnswer {
/**
* Полезная нагрузка для реализаций.
*/
protected Map<String, Object> payload;
@JsonSerialize(using = TelegramPayloadSerializer.class)
@JsonDeserialize(using = TelegramPayloadDeserializer.class)
protected Map<ContextKey, Object> payload = new HashMap<>();
private BoxAnswer(Builder builder) {
message = builder.message;
@ -112,13 +118,13 @@ public class BoxAnswer {
}
}
public Map<String, Object> getPayload() {
public Map<ContextKey, Object> getPayload() {
return payload;
}
public <T> void setPayload(ContextKey<T> key, T value) {
if (checkNotNull(value)) {
payload.put(key.getValue(), value);
payload.put(key, value);
}
}
@ -137,7 +143,7 @@ public class BoxAnswer {
private boolean replace;
private String replaceMessageId;
private String recipientPersonId;
private Map<String, Object> payload = new HashMap<>();
private Map<ContextKey, Object> payload = new HashMap<>();
private Builder() {
}
@ -169,14 +175,14 @@ public class BoxAnswer {
public <T> Builder payload(ContextKey<T> key, T value) {
if (checkNotNull(value)) {
payload.put(key.getValue(), value);
payload.put(key, value);
}
return this;
}
public Builder payload(ContextKey<Boolean> key) {
if (checkNotNull(key)) {
payload.put(key.getValue(), true);
payload.put(key, true);
}
return this;
}

View File

@ -1,39 +1,30 @@
package dev.struchkov.godfather.quarkus.domain;
import dev.struchkov.godfather.main.domain.content.Mail;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.Optional;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class SentBox {
private String personId;
private String messageId;
private Mail sentMail;
private BoxAnswer sentAnswer;
private BoxAnswer originalAnswer;
public SentBox(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) {
this.personId = personId;
this.messageId = messageId;
this.sentAnswer = sentAnswer;
this.originalAnswer = originalAnswer;
}
public static Optional<SentBox> optional(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) {
return Optional.of(new SentBox(personId, messageId, sentAnswer, originalAnswer));
}
public String getPersonId() {
return personId;
}
public String getMessageId() {
return messageId;
}
public BoxAnswer getSentAnswer() {
return sentAnswer;
}
public BoxAnswer getOriginalAnswer() {
return originalAnswer;
public Optional<Mail> getMail() {
return Optional.ofNullable(sentMail);
}
}

View File

@ -2,8 +2,14 @@ package dev.struchkov.godfather.quarkus.domain.unit.func;
import io.smallrye.mutiny.Uni;
import java.util.function.Predicate;
public interface UniPredicate<T> {
Uni<Boolean> test(T t);
static <D> UniPredicate<D> predicate(Predicate<D> predicate) {
return t -> Uni.createFrom().item(predicate.test(t));
}
}

View File

@ -1,7 +1,15 @@
package dev.struchkov.godfather.simple.domain;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import dev.struchkov.godfather.main.domain.jackson.TelegramPayloadDeserializer;
import dev.struchkov.godfather.main.domain.jackson.TelegramPayloadSerializer;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoard;
import dev.struchkov.godfather.simple.domain.content.send.SendAttachment;
import dev.struchkov.haiti.utils.container.ContextKey;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.HashMap;
import java.util.Map;
@ -15,6 +23,9 @@ import static dev.struchkov.haiti.utils.Checker.checkNull;
*
* @author upagge [08/07/2019]
*/
@Getter
@Setter
@NoArgsConstructor
public class BoxAnswer {
/**
@ -25,17 +36,17 @@ public class BoxAnswer {
/**
* Идентификатор сообщения, которое нужно заменить.
*/
private final String replaceMessageId;
private String replaceMessageId;
/**
* Клавиатура - меню.
*/
private final KeyBoard keyBoard;
private KeyBoard keyBoard;
/**
* Флаг означающий, что надо перезаписать наше последнее отправленное сообщение, вместо отправки нового.
*/
private final boolean replace;
private boolean replace;
/**
* Обычное текстовое сообщение.
@ -45,7 +56,11 @@ public class BoxAnswer {
/**
* Полезная нагрузка для реализаций.
*/
protected Map<ContextKey, Object> payload;
@JsonSerialize(using = TelegramPayloadSerializer.class)
@JsonDeserialize(using = TelegramPayloadDeserializer.class)
private Map<ContextKey, Object> payload = new HashMap<>();
private SendAttachment attachment;
private BoxAnswer(Builder builder) {
message = builder.message;
@ -54,6 +69,7 @@ public class BoxAnswer {
replaceMessageId = builder.replaceMessageId;
recipientPersonId = builder.recipientPersonId;
payload = builder.payload;
attachment = builder.attachment;
}
public static BoxAnswer boxAnswer(boolean replace, String message) {
@ -96,30 +112,6 @@ public class BoxAnswer {
return new Builder().replace(true);
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public KeyBoard getKeyBoard() {
return keyBoard;
}
public boolean isReplace() {
return replace;
}
public String getReplaceMessageId() {
return replaceMessageId;
}
public String getRecipientPersonId() {
return recipientPersonId;
}
public void setRecipientPersonId(String recipientPersonId) {
this.recipientPersonId = recipientPersonId;
}
@ -130,28 +122,14 @@ public class BoxAnswer {
}
}
public Map<ContextKey, Object> getPayload() {
return payload;
}
public <T> void setPayload(ContextKey<T> key, T value) {
public <T> void addPayload(ContextKey<T> key, T value) {
if (checkNotNull(value)) {
payload.put(key, value);
}
}
public <T> Optional<T> getPayLoad(ContextKey<T> contextKey) {
return Optional.ofNullable(payload.get(contextKey))
.map(value -> (T) value);
}
@Override
public String toString() {
return "BoxAnswer{" +
"message='" + message + '\'' +
", keyBoard=" + keyBoard +
", replace=" + replace +
'}';
return Optional.ofNullable(payload.get(contextKey)).map(value -> (T) value);
}
public static final class Builder {
@ -162,6 +140,7 @@ public class BoxAnswer {
private String replaceMessageId;
private String recipientPersonId;
private Map<ContextKey, Object> payload = new HashMap<>();
private SendAttachment attachment;
private Builder() {
}
@ -205,6 +184,13 @@ public class BoxAnswer {
return this;
}
public Builder attachment(SendAttachment attachment) {
if (checkNotNull(attachment)) {
this.attachment = attachment;
}
return this;
}
public BoxAnswer build() {
return new BoxAnswer(this);
}

View File

@ -1,39 +1,28 @@
package dev.struchkov.godfather.simple.domain;
import dev.struchkov.godfather.main.domain.content.Mail;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.Optional;
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class SentBox {
private String personId;
private String messageId;
private Mail sentMail;
private BoxAnswer sentAnswer;
private BoxAnswer originalAnswer;
public SentBox(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) {
this.personId = personId;
this.messageId = messageId;
this.sentAnswer = sentAnswer;
this.originalAnswer = originalAnswer;
}
public static Optional<SentBox> optional(String personId, String messageId, BoxAnswer sentAnswer, BoxAnswer originalAnswer) {
return Optional.of(new SentBox(personId, messageId, sentAnswer, originalAnswer));
}
public String getPersonId() {
return personId;
}
public String getMessageId() {
return messageId;
}
public BoxAnswer getSentAnswer() {
return sentAnswer;
}
public BoxAnswer getOriginalAnswer() {
return originalAnswer;
public Optional<Mail> getMail() {
return Optional.ofNullable(sentMail);
}
}

View File

@ -0,0 +1,9 @@
package dev.struchkov.godfather.simple.domain.content.send;
public interface SendAttachment {
String getType();
SendFile getSendFile();
}

View File

@ -0,0 +1,23 @@
package dev.struchkov.godfather.simple.domain.content.send;
import lombok.Getter;
import lombok.Setter;
import java.io.File;
import java.io.InputStream;
@Getter
@Setter
public class SendFile {
private String fileId;
private String url;
private String fileName;
private File data;
private InputStream fileStream;
}

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</groupId>