diff --git a/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java b/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java index 7372a62..71708fc 100644 --- a/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java +++ b/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java @@ -3,7 +3,10 @@ package dev.struchkov.bot.gitlab.config; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.prop.AppProperty; import dev.struchkov.bot.gitlab.context.prop.PersonProperty; +import dev.struchkov.godfather.simple.domain.BoxAnswer; +import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import dev.struchkov.sdk.gitlab.core.GitlabSdkManager; +import dev.struchkov.sdk.gitlab.schema.common.PersonJson; import jakarta.persistence.EntityManagerFactory; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -21,6 +24,8 @@ import java.util.Arrays; import java.util.Optional; import java.util.concurrent.ForkJoinPool; +import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN; + /** * Общий файл настройки всего приложения. * @@ -83,17 +88,28 @@ public class AppConfig { @Bean public PersonInformation personInformation( GitlabSdkManager gitlabSdkManager, - PersonProperty personProperty + PersonProperty personProperty, + TelegramSending telegramSender ) { - return Optional.of(gitlabSdkManager.getAuthPerson()) - .map( - authUser -> PersonInformation.builder() - .id(authUser.getId()) - .username(authUser.getUsername()) - .name(authUser.getName()) - .telegramId(personProperty.getTelegramId()) - .build() - ).orElseThrow(); + final Optional optAuthPerson = gitlabSdkManager.getAuthPerson(); + if (optAuthPerson.isPresent()) { + final PersonJson authUser = optAuthPerson.get(); + return PersonInformation.builder() + .id(authUser.getId()) + .username(authUser.getUsername()) + .name(authUser.getName()) + .telegramId(personProperty.getTelegramId()) + .build(); + } else { + telegramSender.send( + BoxAnswer.builder() + .recipientPersonId(personProperty.getTelegramId()) + .message("\uD83D\uDED1 *Ошибка доступа к GitLab APi* \uD83D\uDED1\n-- -- -- -- -- --\nВозможные причины:\n1. Невалидный токен доступа.\n2. Для доступа к GitLab нужно включить VPN.") + .payload(ENABLE_MARKDOWN) + .build() + ); + throw new RuntimeException("Ошибка доступа к GitLab APi."); + } } }