Добавил сервисный ключ
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9d59624372
commit
80294316de
@ -10,6 +10,8 @@ import jakarta.persistence.Table;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Основные настройки приложения.
|
* Основные настройки приложения.
|
||||||
*
|
*
|
||||||
@ -25,6 +27,9 @@ public class AppSetting {
|
|||||||
@Column(name = "id")
|
@Column(name = "id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "service_key")
|
||||||
|
private UUID serviceKey = UUID.randomUUID();
|
||||||
|
|
||||||
@Column(name = "first_start")
|
@Column(name = "first_start")
|
||||||
private boolean firstStart;
|
private boolean firstStart;
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package dev.struchkov.bot.gitlab.context.service;
|
|||||||
|
|
||||||
import dev.struchkov.bot.gitlab.context.domain.notify.level.DiscussionLevel;
|
import dev.struchkov.bot.gitlab.context.domain.notify.level.DiscussionLevel;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сервис отвечает за пользовательские настройки приложения.
|
* Сервис отвечает за пользовательские настройки приложения.
|
||||||
*
|
*
|
||||||
@ -39,4 +41,6 @@ public interface AppSettingService {
|
|||||||
|
|
||||||
void setDiscussionLevel(DiscussionLevel level);
|
void setDiscussionLevel(DiscussionLevel level);
|
||||||
|
|
||||||
|
UUID getServiceKey();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
|
import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
|
||||||
@ -92,6 +93,16 @@ public class AppSettingServiceImpl implements AppSettingService {
|
|||||||
appSetting.setDiscussionNotifyLevel(level);
|
appSetting.setDiscussionNotifyLevel(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public UUID getServiceKey() {
|
||||||
|
final AppSetting appSetting = getAppSetting();
|
||||||
|
if (appSetting.getServiceKey() == null) {
|
||||||
|
appSetting.setServiceKey(UUID.randomUUID());
|
||||||
|
}
|
||||||
|
return appSetting.getServiceKey();
|
||||||
|
}
|
||||||
|
|
||||||
private AppSetting getAppSetting() {
|
private AppSetting getAppSetting() {
|
||||||
return appSettingRepository.findById(KEY)
|
return appSettingRepository.findById(KEY)
|
||||||
.orElseThrow(NOT_FOUND_SETTINGS);
|
.orElseThrow(NOT_FOUND_SETTINGS);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
<column name="id" type="int">
|
<column name="id" type="int">
|
||||||
<constraints primaryKey="true"/>
|
<constraints primaryKey="true"/>
|
||||||
</column>
|
</column>
|
||||||
|
<column name="service_key" type="uuid"/>
|
||||||
<column name="first_start" type="boolean" defaultValue="true">
|
<column name="first_start" type="boolean" defaultValue="true">
|
||||||
<constraints nullable="false"/>
|
<constraints nullable="false"/>
|
||||||
</column>
|
</column>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package dev.struchkov.bot.gitlab.telegram.service;
|
package dev.struchkov.bot.gitlab.telegram.service;
|
||||||
|
|
||||||
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
|
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
|
||||||
|
import dev.struchkov.bot.gitlab.context.service.NotifyService;
|
||||||
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||||
import dev.struchkov.bot.gitlab.core.config.properties.AppProperty;
|
import dev.struchkov.bot.gitlab.core.config.properties.AppProperty;
|
||||||
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
|
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
|
||||||
@ -16,8 +17,8 @@ import okhttp3.Request;
|
|||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
|
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
||||||
@ -38,6 +39,8 @@ public class StartNotify {
|
|||||||
private final TelegramSending sending;
|
private final TelegramSending sending;
|
||||||
private final TelegramService telegramService;
|
private final TelegramService telegramService;
|
||||||
|
|
||||||
|
private final NotifyService notifyService;
|
||||||
|
|
||||||
private final AppProperty appProperty;
|
private final AppProperty appProperty;
|
||||||
private final AppSettingService settingService;
|
private final AppSettingService settingService;
|
||||||
private final PersonProperty personProperty;
|
private final PersonProperty personProperty;
|
||||||
@ -66,6 +69,23 @@ public class StartNotify {
|
|||||||
|
|
||||||
sendNotice();
|
sendNotice();
|
||||||
}
|
}
|
||||||
|
registrationForStatistic();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Отправляет service_key для сбора анонимной статистики использования.
|
||||||
|
*/
|
||||||
|
private void registrationForStatistic() {
|
||||||
|
final UUID serviceKey = settingService.getServiceKey();
|
||||||
|
final boolean firstStart = settingService.isFirstStart();
|
||||||
|
final String requestUrl = "https://metrika.struchkov.dev/gitlab-notify/registration?key=" + serviceKey + "&initFlow=" + firstStart;
|
||||||
|
final Request request = new Request.Builder().get().url(requestUrl).build();
|
||||||
|
try {
|
||||||
|
client.newCall(request).execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,10 +93,7 @@ public class StartNotify {
|
|||||||
*/
|
*/
|
||||||
private void sendNotice() {
|
private void sendNotice() {
|
||||||
final String requestUrl = "https://metrika.struchkov.dev/gitlab-notify/start-notice";
|
final String requestUrl = "https://metrika.struchkov.dev/gitlab-notify/start-notice";
|
||||||
final Request request = new Request.Builder()
|
final Request request = new Request.Builder().get().url(requestUrl).build();
|
||||||
.get()
|
|
||||||
.url(requestUrl)
|
|
||||||
.build();
|
|
||||||
try {
|
try {
|
||||||
final Response response = client.newCall(request).execute();
|
final Response response = client.newCall(request).execute();
|
||||||
if (response.code() == 200) {
|
if (response.code() == 200) {
|
||||||
@ -95,9 +112,22 @@ public class StartNotify {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
log.warn(e.getMessage());
|
log.warn(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @PostConstruct
|
||||||
|
// public void demo() {
|
||||||
|
// notifyService.send(
|
||||||
|
// DiscussionNewNotify.builder()
|
||||||
|
// .authorName("Ivan Ivanov")
|
||||||
|
// .threadId("1")
|
||||||
|
// .discussionMessage("Кажется здесь можно сделать лучше.")
|
||||||
|
// .mergeRequestName("Merge Request Name")
|
||||||
|
// .url("https://ya.ru")
|
||||||
|
// .build()
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user