Исправил SenderStorageService на SenderRepository

This commit is contained in:
Struchkov Mark 2022-12-09 22:06:59 +03:00
parent 375ee3255b
commit 78cc771852
7 changed files with 28 additions and 40 deletions

View File

@ -1,8 +1,8 @@
package dev.struchkov.godfather.telegram.quarkus.sender;
package dev.struchkov.godfather.telegram.quarkus.context.repository;
import io.smallrye.mutiny.Uni;
public interface SenderStorageService {
public interface SenderRepository {
Uni<Integer> getLastSendMessage(String telegramId);

View File

@ -1,13 +0,0 @@
package dev.struchkov.godfather.telegram.quarkus.context.service;
import io.smallrye.mutiny.Uni;
public interface SenderStorageService {
Uni<Integer> getLastSendMessage(Long telegramId);
Uni<Void> saveLastSendMessage(Long telegramId, Integer messageId);
Uni<Void> removeLastSendMessage(Long telegramId);
}

View File

@ -1,8 +1,8 @@
package dev.struchkov.godfather.telegram.simple.context.service;
package dev.struchkov.godfather.telegram.simple.context.repository;
import java.util.Optional;
public interface SenderStorageService {
public interface SenderRepository {
Optional<Integer> getLastSendMessage(String telegramId);

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.quarkus.core.service;
import dev.struchkov.godfather.telegram.quarkus.context.service.SenderStorageService;
import dev.struchkov.godfather.telegram.quarkus.context.repository.SenderRepository;
import io.smallrye.mutiny.Uni;
import org.jetbrains.annotations.NotNull;
@ -9,7 +9,7 @@ import java.util.Map;
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
public class SenderMapStorageService implements SenderStorageService {
public class SenderMapRepository implements SenderRepository {
private final Map<Long, Integer> lastMessageId = new HashMap<>();

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.simple.core.service;
import dev.struchkov.godfather.telegram.simple.context.service.SenderStorageService;
import dev.struchkov.godfather.telegram.simple.context.repository.SenderRepository;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
@ -9,7 +9,7 @@ import java.util.Optional;
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
public class SenderMapStorageService implements SenderStorageService {
public class SenderMapRepository implements SenderRepository {
private final Map<String, Integer> lastMessageId = new HashMap<>();

View File

@ -5,6 +5,7 @@ import dev.struchkov.godfather.main.domain.SendType;
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.quarkus.context.repository.SenderRepository;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramSending;
import io.smallrye.mutiny.Uni;
import org.jetbrains.annotations.NotNull;
@ -30,23 +31,23 @@ public class TelegramSender implements TelegramSending {
private final AbsSender absSender;
private SendPreProcessing sendPreProcessing;
private SenderStorageService senderStorageService;
private SenderRepository senderRepository;
public TelegramSender(TelegramConnect telegramConnect) {
this.absSender = telegramConnect.getAbsSender();
}
public TelegramSender(TelegramConnect telegramConnect, SenderStorageService senderStorageService) {
public TelegramSender(TelegramConnect telegramConnect, SenderRepository senderRepository) {
this.absSender = telegramConnect.getAbsSender();
this.senderStorageService = senderStorageService;
this.senderRepository = senderRepository;
}
public void setSendPreProcessing(SendPreProcessing sendPreProcessing) {
this.sendPreProcessing = sendPreProcessing;
}
public void setSenderRepository(SenderStorageService senderStorageService) {
this.senderStorageService = senderStorageService;
public void setSenderRepository(SenderRepository senderStorageService) {
this.senderRepository = senderRepository;
}
@Override
@ -65,8 +66,8 @@ public class TelegramSender implements TelegramSending {
v -> {
isNotNull(telegramId, boxAnswer);
if (boxAnswer.isReplace() && checkNotNull(senderStorageService)) {
return senderStorageService.getLastSendMessage(telegramId)
if (boxAnswer.isReplace() && checkNotNull(senderRepository)) {
return senderRepository.getLastSendMessage(telegramId)
.onItem().transformToUni(
lastId -> {
if (checkNotNull(lastId)) {
@ -119,8 +120,8 @@ public class TelegramSender implements TelegramSending {
try {
final Message execute = absSender.execute(sendMessage);
if (checkNotNull(senderStorageService) && saveMessageId) {
return senderStorageService.saveLastSendMessage(telegramId, execute.getMessageId());
if (checkNotNull(senderRepository) && saveMessageId) {
return senderRepository.saveLastSendMessage(telegramId, execute.getMessageId());
}
} catch (TelegramApiRequestException e) {
log.error(e.getApiResponse());

View File

@ -5,7 +5,7 @@ import dev.struchkov.godfather.main.domain.SendType;
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.service.SenderStorageService;
import dev.struchkov.godfather.telegram.simple.context.repository.SenderRepository;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@ -31,23 +31,23 @@ public class TelegramSender implements TelegramSending {
private final AbsSender absSender;
private SendPreProcessing sendPreProcessing;
private SenderStorageService senderStorageService;
private SenderRepository senderRepository;
public TelegramSender(TelegramConnect telegramConnect) {
this.absSender = telegramConnect.getAbsSender();
}
public TelegramSender(TelegramConnect telegramConnect, SenderStorageService senderStorageService) {
public TelegramSender(TelegramConnect telegramConnect, SenderRepository senderRepository) {
this.absSender = telegramConnect.getAbsSender();
this.senderStorageService = senderStorageService;
this.senderRepository = senderRepository;
}
public void setSendPreProcessing(SendPreProcessing sendPreProcessing) {
this.sendPreProcessing = sendPreProcessing;
}
public void setSenderRepository(SenderStorageService senderStorageService) {
this.senderStorageService = senderStorageService;
public void setSenderRepository(SenderRepository senderRepository) {
this.senderRepository = senderRepository;
}
@Override
@ -63,8 +63,8 @@ public class TelegramSender implements TelegramSending {
private void sendBoxAnswer(@NotNull String telegramId, @NotNull BoxAnswer boxAnswer, boolean saveMessageId) {
isNotNull(telegramId, boxAnswer);
try {
if (boxAnswer.isReplace() && checkNotNull(senderStorageService)) {
final Optional<Integer> optLastId = senderStorageService.getLastSendMessage(telegramId);
if (boxAnswer.isReplace() && checkNotNull(senderRepository)) {
final Optional<Integer> optLastId = senderRepository.getLastSendMessage(telegramId);
if (optLastId.isPresent()) {
replaceMessage(telegramId, optLastId.get(), boxAnswer);
} else {
@ -105,8 +105,8 @@ public class TelegramSender implements TelegramSending {
sendMessage.setReplyMarkup(KeyBoardConvert.convertKeyBoard(boxAnswer.getKeyBoard()));
try {
final Message execute = absSender.execute(sendMessage);
if (checkNotNull(senderStorageService) && saveMessageId) {
senderStorageService.saveLastSendMessage(telegramId, execute.getMessageId());
if (checkNotNull(senderRepository) && saveMessageId) {
senderRepository.saveLastSendMessage(telegramId, execute.getMessageId());
}
} catch (TelegramApiRequestException e) {
log.error(e.getApiResponse());