forked from Sanders/TelegaBot
Addad flyway + fixes
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<option name="executionName" />
|
<option name="executionName" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="externalSystemIdString" value="GRADLE" />
|
<option name="externalSystemIdString" value="GRADLE" />
|
||||||
<option name="scriptParameters" value="" />
|
<option name="scriptParameters" value="--refresh-dependencies" />
|
||||||
<option name="taskDescriptions">
|
<option name="taskDescriptions">
|
||||||
<list />
|
<list />
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
+5
-22
@@ -2,7 +2,7 @@ plugins {
|
|||||||
id 'java'
|
id 'java'
|
||||||
id 'org.springframework.boot' version '3.4.2'
|
id 'org.springframework.boot' version '3.4.2'
|
||||||
id 'io.spring.dependency-management' version '1.1.7'
|
id 'io.spring.dependency-management' version '1.1.7'
|
||||||
id 'org.flywaydb.flyway' version '10.11.0'
|
id 'org.flywaydb.flyway' version '11.3.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'ru.cathub'
|
group = 'ru.cathub'
|
||||||
@@ -28,7 +28,8 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-cache'
|
implementation 'org.springframework.boot:spring-boot-starter-cache'
|
||||||
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
|
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
|
||||||
implementation 'org.hibernate:hibernate-tools:6.4.4.Final'
|
// https://mvnrepository.com/artifact/org.hibernate/hibernate-tools
|
||||||
|
|
||||||
annotationProcessor 'org.hibernate.orm:hibernate-jpamodelgen:6.4.4.Final'
|
annotationProcessor 'org.hibernate.orm:hibernate-jpamodelgen:6.4.4.Final'
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
@@ -52,6 +53,8 @@ dependencies {
|
|||||||
|
|
||||||
// https://mvnrepository.com/artifact/io.hypersistence/hypersistence-utils-hibernate-63
|
// https://mvnrepository.com/artifact/io.hypersistence/hypersistence-utils-hibernate-63
|
||||||
implementation group: 'io.hypersistence', name: 'hypersistence-utils-hibernate-63', version: '3.9.1'
|
implementation group: 'io.hypersistence', name: 'hypersistence-utils-hibernate-63', version: '3.9.1'
|
||||||
|
// https://mvnrepository.com/artifact/org.flywaydb/flyway-database-postgresql
|
||||||
|
runtimeOnly group: 'org.flywaydb', name: 'flyway-database-postgresql', version: '11.3.1'
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -60,26 +63,6 @@ tasks.named('test') {
|
|||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register('generateMigration', JavaExec) {
|
|
||||||
dependsOn 'classes'
|
|
||||||
|
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
|
||||||
mainClass = 'org.hibernate.tool.Main'
|
|
||||||
|
|
||||||
args = [
|
|
||||||
'--hbm2ddl-auto', 'update',
|
|
||||||
'--properties', 'application.properties',
|
|
||||||
'--output', 'src/main/resources/db/migration/V' + getNextMigrationVersion() + '__auto_generated.sql'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
def getNextMigrationVersion() {
|
|
||||||
def migrationDir = project.file('src/main/resources/db/migration')
|
|
||||||
def existing = migrationDir.listFiles()?.collect {
|
|
||||||
(it.name =~ /V(\d+)__/)[0][1]
|
|
||||||
}?.max() ?: 0
|
|
||||||
return String.format("%03d", existing.toInteger() + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
flyway {
|
flyway {
|
||||||
locations = ['classpath:db/migration']
|
locations = ['classpath:db/migration']
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class KeyboardHelper {
|
|||||||
KeyboardRow row2 = new KeyboardRow();
|
KeyboardRow row2 = new KeyboardRow();
|
||||||
row2.add(new KeyboardButton(BACK));
|
row2.add(new KeyboardButton(BACK));
|
||||||
|
|
||||||
keyboardRows.add(row1);
|
//keyboardRows.add(row1);
|
||||||
keyboardRows.add(row2);
|
keyboardRows.add(row2);
|
||||||
|
|
||||||
ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup(keyboardRows);
|
ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup(keyboardRows);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package ru.cathub.telegabot.bot;
|
|||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -27,12 +28,14 @@ import ru.cathub.telegabot.model.BotUser;
|
|||||||
import ru.cathub.telegabot.service.BookManageService;
|
import ru.cathub.telegabot.service.BookManageService;
|
||||||
import ru.cathub.telegabot.service.DataService;
|
import ru.cathub.telegabot.service.DataService;
|
||||||
import ru.cathub.telegabot.service.TelegramBotService;
|
import ru.cathub.telegabot.service.TelegramBotService;
|
||||||
|
import ru.cathub.telegabot.service.TelegramClientService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class TelegaBot implements SpringLongPollingBot, LongPollingSingleThreadUpdateConsumer {
|
public class TelegaBot implements SpringLongPollingBot, LongPollingSingleThreadUpdateConsumer {
|
||||||
|
|
||||||
// private final QwenService qwenService;
|
// private final QwenService qwenService;
|
||||||
@@ -48,17 +51,19 @@ public class TelegaBot implements SpringLongPollingBot, LongPollingSingleThreadU
|
|||||||
private final String botUsername;
|
private final String botUsername;
|
||||||
private final OkHttpTelegramClient telegramClient;
|
private final OkHttpTelegramClient telegramClient;
|
||||||
private final TelegramBotService telegramBotService;
|
private final TelegramBotService telegramBotService;
|
||||||
|
private final TelegramClientService telegramClientService;
|
||||||
private final DataService dataService;
|
private final DataService dataService;
|
||||||
|
|
||||||
public TelegaBot(
|
public TelegaBot(
|
||||||
@Value("${bot.token}") String botToken,
|
@Value("${bot.token}") String botToken,
|
||||||
@Value("${bot.name}") String botUsername,
|
@Value("${bot.name}") String botUsername,
|
||||||
TelegramBotService telegramBotService, DataService dataService
|
TelegramBotService telegramBotService, TelegramClientService telegramClientService, DataService dataService
|
||||||
) {
|
) {
|
||||||
this.botToken = botToken;
|
this.botToken = botToken;
|
||||||
this.botUsername = botUsername;
|
this.botUsername = botUsername;
|
||||||
this.telegramClient = new OkHttpTelegramClient(botToken);
|
this.telegramClient = new OkHttpTelegramClient(botToken);
|
||||||
this.telegramBotService = telegramBotService;
|
this.telegramBotService = telegramBotService;
|
||||||
|
this.telegramClientService = telegramClientService;
|
||||||
this.dataService = dataService;
|
this.dataService = dataService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +111,8 @@ public class TelegaBot implements SpringLongPollingBot, LongPollingSingleThreadU
|
|||||||
try {
|
try {
|
||||||
telegramBotService.processInput(user,messageText);
|
telegramBotService.processInput(user,messageText);
|
||||||
} catch (ServiceException e) {
|
} catch (ServiceException e) {
|
||||||
throw new RuntimeException(e);
|
telegramClientService.sendMessage(user, "❌ Ошибка!");
|
||||||
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
} else if (update.hasMessage() && update.getMessage().hasDocument()) {
|
} else if (update.hasMessage() && update.getMessage().hasDocument()) {
|
||||||
//TODO
|
//TODO
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package ru.cathub.telegabot.model;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class BookEditStateCache {
|
|||||||
NONE
|
NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Builder.Default()
|
||||||
private BookEditState bookEditState = BookEditState.NONE;
|
private BookEditState bookEditState = BookEditState.NONE;
|
||||||
|
|
||||||
private Long bookId;
|
private Long bookId;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class ProfileServiceImpl implements ProfileService {
|
|||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
telegramClientService.sendMessage(
|
telegramClientService.sendMessage(
|
||||||
user,
|
user,
|
||||||
"⌨️ Режим редактирования профиля:\nУстановите цель по количеству книг или вернитесь назад",
|
"⌨️ Режим редактирования профиля:\nВведите цель по количеству книг или вернитесь назад",
|
||||||
KeyboardHelper.getProfileMenuKeyboard()
|
KeyboardHelper.getProfileMenuKeyboard()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,8 @@ public class ProfileServiceImpl implements ProfileService {
|
|||||||
throw new NumberFormatException();
|
throw new NumberFormatException();
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new ServiceException("❌ Пожалуйста, введите положительное число");
|
telegramClientService.sendMessage(user, "❌ Ошибка! Введите целое число",
|
||||||
|
KeyboardHelper.getProfileMenuKeyboard());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ cbr.currency.rates.xml.url=http://www.cbr.ru/scripts/XML_daily.asp
|
|||||||
spring.datasource.url=jdbc:postgresql://192.168.0.10:5432/telegabot
|
spring.datasource.url=jdbc:postgresql://192.168.0.10:5432/telegabot
|
||||||
spring.datasource.username=postgres
|
spring.datasource.username=postgres
|
||||||
spring.datasource.password=Vftrixpo05
|
spring.datasource.password=Vftrixpo05
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=validate
|
||||||
spring.jpa.generate-ddl=true
|
|
||||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||||
|
|
||||||
# Flyway Configuration
|
# Flyway Configuration
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
CREATE TABLE books
|
||||||
|
(
|
||||||
|
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||||
|
title VARCHAR(255),
|
||||||
|
author VARCHAR(255),
|
||||||
|
rating INTEGER,
|
||||||
|
bot_user_id BIGINT,
|
||||||
|
CONSTRAINT pk_books PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE bot_user
|
||||||
|
(
|
||||||
|
id BIGINT NOT NULL,
|
||||||
|
books_to_read INTEGER,
|
||||||
|
chat_id BIGINT,
|
||||||
|
user_type VARCHAR(255),
|
||||||
|
working_mode VARCHAR(255),
|
||||||
|
created_date_time TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
CONSTRAINT pk_botuser PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE messages
|
||||||
|
(
|
||||||
|
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||||
|
content TEXT,
|
||||||
|
type VARCHAR(255),
|
||||||
|
created_at TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
bot_user_id BIGINT,
|
||||||
|
CONSTRAINT pk_messages PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE books
|
||||||
|
ADD CONSTRAINT FK_BOOKS_ON_BOT_USER FOREIGN KEY (bot_user_id) REFERENCES bot_user (id);
|
||||||
|
|
||||||
|
ALTER TABLE messages
|
||||||
|
ADD CONSTRAINT FK_MESSAGES_ON_BOTUSER FOREIGN KEY (bot_user_id) REFERENCES bot_user (id);
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS bot_user (
|
|
||||||
id BIGINT PRIMARY KEY,
|
|
||||||
chat_id BIGINT NOT NULL,
|
|
||||||
user_type VARCHAR(20) NOT NULL,
|
|
||||||
working_mode VARCHAR(20) NOT NULL,
|
|
||||||
books_to_read INT,
|
|
||||||
created_date_time TIMESTAMP,
|
|
||||||
UNIQUE(chat_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS books (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
title VARCHAR(255) NOT NULL,
|
|
||||||
author VARCHAR(255) NOT NULL,
|
|
||||||
rating INT CHECK (rating BETWEEN 1 AND 5),
|
|
||||||
bot_user_id BIGINT NOT NULL REFERENCES bot_user(id),
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS messages (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
content TEXT NOT NULL,
|
|
||||||
type VARCHAR(20) NOT NULL,
|
|
||||||
created_at TIMESTAMP NOT NULL,
|
|
||||||
bot_user_id BIGINT NOT NULL REFERENCES bot_user(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_books_bot_user_id ON books(bot_user_id);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_messages_bot_user_id ON messages(bot_user_id);
|
|
||||||
Reference in New Issue
Block a user