From b029c3acaddb3f16695645e67a55404f02037768 Mon Sep 17 00:00:00 2001 From: Sanders Date: Mon, 17 Feb 2025 17:17:13 +0300 Subject: [PATCH] Add lastReadDate --- build.gradle | 3 +++ src/main/java/ru/cathub/telegabot/model/BotUser.java | 3 +++ .../telegabot/service/impl/BookCreationServiceImpl.java | 4 ++++ src/main/resources/application.properties | 8 +++++--- src/main/resources/db/migration/V3__add_last_read.sql | 2 ++ 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/db/migration/V3__add_last_read.sql diff --git a/build.gradle b/build.gradle index c0aa098..e0e1637 100644 --- a/build.gradle +++ b/build.gradle @@ -65,4 +65,7 @@ tasks.named('test') { flyway { locations = ['classpath:db/migration'] + url = project.properties['DB_URL'] + user = project.properties['DB_USER'] + password = project.properties['DB_PASSWORD'] } diff --git a/src/main/java/ru/cathub/telegabot/model/BotUser.java b/src/main/java/ru/cathub/telegabot/model/BotUser.java index d044d3d..e0c7a2d 100644 --- a/src/main/java/ru/cathub/telegabot/model/BotUser.java +++ b/src/main/java/ru/cathub/telegabot/model/BotUser.java @@ -4,6 +4,7 @@ import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.CreationTimestamp; +import java.sql.Date; import java.time.LocalDateTime; import java.util.List; @@ -48,4 +49,6 @@ public class BotUser { @OneToMany(mappedBy = "botUser", cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List books; + private Date lastReadDate; + } diff --git a/src/main/java/ru/cathub/telegabot/service/impl/BookCreationServiceImpl.java b/src/main/java/ru/cathub/telegabot/service/impl/BookCreationServiceImpl.java index 320e027..8819b14 100644 --- a/src/main/java/ru/cathub/telegabot/service/impl/BookCreationServiceImpl.java +++ b/src/main/java/ru/cathub/telegabot/service/impl/BookCreationServiceImpl.java @@ -17,6 +17,7 @@ import java.sql.Date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import static ru.cathub.telegabot.utils.BookFormatUtils.*; @@ -165,6 +166,9 @@ public class BookCreationServiceImpl implements BookCreationService { telegramClientService.sendMessageWithMarkdown(user, message + stats); bookRepository.save(book); + + user.setLastReadDate(new Date(System.currentTimeMillis())); + userRepository.save(user); try { String prompt = String.format("Придумай креативное поздравление с прочтением книги \"%s\" от автора \"%s\". Учитывай что пользователь поставил оценку %d/10. ", cache.getTitle(), cache.getAuthor(), cache.getRating()); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c306e24..fef51db 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -8,13 +8,15 @@ spring.jpa.hibernate.ddl-auto=validate spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.datasource.driver-class-name=org.postgresql.Driver spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.properties.hibernate.default_schema=telegabot # Flyway Configuration spring.flyway.enabled=true spring.flyway.locations=classpath:db/migration -spring.flyway.baseline-on-migrate=true -spring.flyway.validate-on-migrate=true -spring.flyway.Schemas=telegabot +spring.flyway.schemas=telegabot +spring.flyway.baselineOnMigrate=true +spring.flyway.validateOnMigrate=true + diff --git a/src/main/resources/db/migration/V3__add_last_read.sql b/src/main/resources/db/migration/V3__add_last_read.sql new file mode 100644 index 0000000..abb3b3b --- /dev/null +++ b/src/main/resources/db/migration/V3__add_last_read.sql @@ -0,0 +1,2 @@ +ALTER TABLE bot_user + ADD last_read_date date; \ No newline at end of file