diff --git a/booklore-api/build.gradle b/booklore-api/build.gradle index 0018d35c3..22fde50da 100644 --- a/booklore-api/build.gradle +++ b/booklore-api/build.gradle @@ -40,7 +40,7 @@ dependencies { annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' // Database & Flyway - runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' + implementation 'com.h2database:h2' implementation 'org.flywaydb:flyway-mysql:10.12.0' // Book and Image Libraries diff --git a/booklore-api/h2-2.3.232.jar b/booklore-api/h2-2.3.232.jar new file mode 100755 index 000000000..971a81bb5 Binary files /dev/null and b/booklore-api/h2-2.3.232.jar differ diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/controller/AppSettingController.java b/booklore-api/src/main/java/com/adityachandel/booklore/controller/AppSettingController.java index 6fe6449bb..04aaa17c9 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/controller/AppSettingController.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/controller/AppSettingController.java @@ -17,8 +17,8 @@ public class AppSettingController { } @PutMapping("/api/settings") - public void updateSetting(@RequestParam String category, @RequestParam String key, @RequestParam String newValue) { - appSettingService.updateSetting(category, key, newValue); + public void updateSetting(@RequestParam String category, @RequestParam String name, @RequestParam String newValue) { + appSettingService.updateSetting(category, name, newValue); } } \ No newline at end of file diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/AppSettingEntity.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/AppSettingEntity.java index 7d9c83038..d332be9a2 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/AppSettingEntity.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/AppSettingEntity.java @@ -15,9 +15,9 @@ public class AppSettingEntity { @Column(name = "category", nullable = false) private String category; - @Column(name = "key1", nullable = false) - private String key; + @Column(name = "name", nullable = false) + private String name; - @Column(name = "value", nullable = false, columnDefinition = "TEXT") - private String value; + @Column(name = "val", nullable = false, columnDefinition = "TEXT") + private String val; } diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/repository/AppSettingsRepository.java b/booklore-api/src/main/java/com/adityachandel/booklore/repository/AppSettingsRepository.java index 4c542c67c..3369b3bfd 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/repository/AppSettingsRepository.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/repository/AppSettingsRepository.java @@ -6,5 +6,5 @@ import org.springframework.stereotype.Repository; @Repository public interface AppSettingsRepository extends JpaRepository { - AppSettingEntity findByCategoryAndKey(String category, String key);; + AppSettingEntity findByCategoryAndName(String category, String name);; } diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/AppSettingService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/AppSettingService.java index 25e153bdd..de94cfe64 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/AppSettingService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/AppSettingService.java @@ -19,7 +19,7 @@ public class AppSettingService { public AppSettings getAppSettings() { List settings = appSettingsRepository.findAll(); - Map> settingsMap = settings.stream().collect(Collectors.groupingBy(AppSettingEntity::getCategory, Collectors.toMap(AppSettingEntity::getKey, AppSettingEntity::getValue))); + Map> settingsMap = settings.stream().collect(Collectors.groupingBy(AppSettingEntity::getCategory, Collectors.toMap(AppSettingEntity::getName, AppSettingEntity::getVal))); AppSettings appSettings = new AppSettings(); if (settingsMap.containsKey("epub")) { Map epubSettings = settingsMap.get("epub"); @@ -33,13 +33,13 @@ public class AppSettingService { } @Transactional - public void updateSetting(String category, String key, String newValue) { - AppSettingEntity setting = appSettingsRepository.findByCategoryAndKey(category, key); + public void updateSetting(String category, String name, String newValue) { + AppSettingEntity setting = appSettingsRepository.findByCategoryAndName(category, name); if (setting != null) { - setting.setValue(newValue); + setting.setVal(newValue); appSettingsRepository.save(setting); } else { - throw new IllegalArgumentException("Setting not found for category: " + category + " and key: " + key); + throw new IllegalArgumentException("Setting not found for category: " + category + " and key: " + name); } } } diff --git a/booklore-api/src/main/resources/application.yaml b/booklore-api/src/main/resources/application.yaml index 5cf7224fe..c322fafc8 100644 --- a/booklore-api/src/main/resources/application.yaml +++ b/booklore-api/src/main/resources/application.yaml @@ -14,10 +14,10 @@ spring: application: name: booklore-api datasource: - driver-class-name: org.mariadb.jdbc.Driver - url: ${SOLITUDE_API_MARIADB_URL:jdbc:mariadb://localhost:3306/booklore} - username: ${SOLITUDE_API_MARIADB_USERNAME:root} - password: ${SOLITUDE_API_MARIADB_PASSWORD:cfcNEBdUm6QerR6oo2UM} + driver-class-name: org.h2.Driver + url: jdbc:h2:tcp://localhost:9092/~/my-library-temp/config/db/booklore + username: sa + password: password jpa: hibernate: naming: diff --git a/booklore-api/src/main/resources/db/migration/V1__Create_Library_and_Book_Tables.sql b/booklore-api/src/main/resources/db/migration/V1__Create_Library_and_Book_Tables.sql index 0c215cb9c..c0e4e03ea 100644 --- a/booklore-api/src/main/resources/db/migration/V1__Create_Library_and_Book_Tables.sql +++ b/booklore-api/src/main/resources/db/migration/V1__Create_Library_and_Book_Tables.sql @@ -1,3 +1,4 @@ +-- Create the library table CREATE TABLE IF NOT EXISTS library ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -6,6 +7,7 @@ CREATE TABLE IF NOT EXISTS library icon VARCHAR(64) NOT NULL ); +-- Create the library_path table CREATE TABLE IF NOT EXISTS library_path ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -14,6 +16,7 @@ CREATE TABLE IF NOT EXISTS library_path CONSTRAINT fk_library_path FOREIGN KEY (library_id) REFERENCES library (id) ); +-- Create the book table CREATE TABLE IF NOT EXISTS book ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -27,11 +30,14 @@ CREATE TABLE IF NOT EXISTS book epub_progress VARCHAR(1000) NULL, CONSTRAINT fk_library FOREIGN KEY (library_id) REFERENCES library (id) ON DELETE CASCADE, - CONSTRAINT unique_file_library UNIQUE (file_name, library_id), - INDEX idx_library_id (library_id), - INDEX idx_last_read_time (last_read_time) + CONSTRAINT unique_file_library UNIQUE (file_name, library_id) ); +-- Create indexes for the book table +CREATE INDEX IF NOT EXISTS idx_library_id ON book (library_id); +CREATE INDEX IF NOT EXISTS idx_last_read_time ON book (last_read_time); + +-- Create the book_metadata table CREATE TABLE IF NOT EXISTS book_metadata ( book_id BIGINT NOT NULL PRIMARY KEY, @@ -50,6 +56,7 @@ CREATE TABLE IF NOT EXISTS book_metadata CONSTRAINT fk_book_metadata FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE ); +-- Create the author table CREATE TABLE IF NOT EXISTS author ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -57,12 +64,14 @@ CREATE TABLE IF NOT EXISTS author CONSTRAINT unique_name UNIQUE (name) ); +-- Create the category table CREATE TABLE IF NOT EXISTS category ( id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL UNIQUE ); +-- Create the book_viewer_setting table CREATE TABLE IF NOT EXISTS book_viewer_setting ( book_id BIGINT PRIMARY KEY, @@ -73,6 +82,7 @@ CREATE TABLE IF NOT EXISTS book_viewer_setting CONSTRAINT fk_book_viewer_setting FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE ); +-- Create the book_metadata_category_mapping table CREATE TABLE IF NOT EXISTS book_metadata_category_mapping ( book_id BIGINT NOT NULL, @@ -82,18 +92,21 @@ CREATE TABLE IF NOT EXISTS book_metadata_category_mapping CONSTRAINT fk_book_metadata_category_mapping_category FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE ); +-- Create the book_metadata_author_mapping table CREATE TABLE IF NOT EXISTS book_metadata_author_mapping ( book_id BIGINT NOT NULL, author_id BIGINT NOT NULL, PRIMARY KEY (book_id, author_id), CONSTRAINT fk_book_metadata_author_mapping_book FOREIGN KEY (book_id) REFERENCES book_metadata (book_id) ON DELETE CASCADE, - CONSTRAINT fk_book_metadata_author_mapping_author FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE, - INDEX idx_book_metadata_id (book_id), - INDEX idx_author_id (author_id) + CONSTRAINT fk_book_metadata_author_mapping_author FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE ); +-- Create indexes for the book_metadata_author_mapping table +CREATE INDEX IF NOT EXISTS idx_book_metadata_id ON book_metadata_author_mapping (book_id); +CREATE INDEX IF NOT EXISTS idx_author_id ON book_metadata_author_mapping (author_id); +-- Create the shelf table CREATE TABLE IF NOT EXISTS shelf ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -102,6 +115,7 @@ CREATE TABLE IF NOT EXISTS shelf icon VARCHAR(64) NOT NULL ); +-- Create the book_shelf_mapping table CREATE TABLE IF NOT EXISTS book_shelf_mapping ( book_id BIGINT NOT NULL, @@ -111,11 +125,12 @@ CREATE TABLE IF NOT EXISTS book_shelf_mapping CONSTRAINT fk_book_shelf_mapping_shelf FOREIGN KEY (shelf_id) REFERENCES shelf (id) ON DELETE CASCADE ); +-- Create the app_settings table CREATE TABLE app_settings ( id BIGINT AUTO_INCREMENT PRIMARY KEY, category VARCHAR(255) NOT NULL, - key1 VARCHAR(255) NOT NULL, - value TEXT NOT NULL, - UNIQUE (category, key1) + name VARCHAR(255) NOT NULL, + val TEXT NOT NULL, + UNIQUE (category, name) ); \ No newline at end of file diff --git a/booklore-api/src/main/resources/db/migration/V2__Insert_Initial_Data.sql b/booklore-api/src/main/resources/db/migration/V2__Insert_Initial_Data.sql index 7bbd47ef5..28e16f534 100644 --- a/booklore-api/src/main/resources/db/migration/V2__Insert_Initial_Data.sql +++ b/booklore-api/src/main/resources/db/migration/V2__Insert_Initial_Data.sql @@ -1,12 +1,12 @@ -INSERT INTO booklore.shelf (name, icon) +INSERT INTO shelf (name, icon) VALUES ('Favorites', 'heart'); -INSERT INTO app_settings (category, key1, value) +INSERT INTO app_settings (category, name, val) VALUES ('epub', 'theme', 'white'), ('epub', 'fontSize', '120'), ('epub', 'font', 'serif'); -INSERT INTO app_settings (category, key1, value) +INSERT INTO app_settings (category, name, val) VALUES ('pdf', 'spread', 'odd'), ('pdf', 'zoom', 'page-fit'), ('pdf', 'sidebar', 'true'); \ No newline at end of file