diff --git a/build.gradle.kts b/build.gradle.kts index 9cbf283..44e9d99 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.aitrainer" -version = "1.0.17" +version = "1.0.18" java.sourceCompatibility = JavaVersion.VERSION_1_8 repositories { diff --git a/data/db/install.sql b/data/db/install.sql index 8be92ae..9638317 100644 --- a/data/db/install.sql +++ b/data/db/install.sql @@ -589,13 +589,51 @@ CREATE TABLE IF NOT EXISTS `exercise_tree` ( ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4; -- Tábla adatainak mentése aitrainer2.exercise_tree: ~3 rows (hozzávetőleg) -/*!40000 ALTER TABLE `exercise_tree` DISABLE KEYS */; REPLACE INTO `exercise_tree` (`tree_id`, `parent_id`, `name`, `image_url`, `active`) VALUES - (3, 0, 'Cardio', 'images/1.cardio_7TNRbEU.png', 1), - (4, 0, 'Strength', 'images/2.strength.png', 1), - (5, 0, 'Body Compositions', 'images/3.bcs1.png', 1), - (6, 2, '1RM', 'images/2.2.1.1RM.png', 1); -/*!40000 ALTER TABLE `exercise_tree` ENABLE KEYS */; +(3, 0, 'Cardio', 'images/1.cardio.png', 1), +(4, 0, 'Strength', 'images/2.strength.png', 1), +(5, 0, 'Body Compositions', 'images/3.bcs1.png', 1), +(7, 3, 'Aerob', 'images/1.1.aerob.png', 1), +(8, 3, 'Anaerob', 'images/1.2.anaerob.png', 1), +(9, 4, 'One Rep Max', 'images/2.2.1.1RM.png', 1), +(10, 4, 'Endurance', 'images/2.1.endurance.png', 1), +(11, 5, 'BMI', 'images/3.1.BMI.png', 0), +(12, 5, 'BMR', 'images/3.2.BMR.png', 0), +(13, 5, 'Sizes', 'images/3.3.sizes.png', 0), +(14, 9, 'Chest', 'images/2.2.1.1.chestpress.png', 1), +(15, 9, 'Biceps', 'images/2.2.1.3.biceps.png', 1), +(16, 9, 'Triceps', 'images/2.2.1.4.triceps.png', 1), +(17, 9, 'Shoulders', 'images/2.2.1.5.shoulders.png', 1), +(18, 9, 'Thigh', 'images/2.1.4.squats.png', 1), +(19, 9, 'Calf', 'images/2.1.4.squats.png', 1), +(20, 9, 'Back', 'images/2.2.1.5.shoulders.png', 1); + +CREATE TABLE IF NOT EXISTS `exercise_tree_parents` ( + `exercise_tree_parents_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `exercise_tree_parent_id` int(11) NOT NULL DEFAULT 0, + `exercise_tree_child_id` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`exercise_tree_parents_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; + +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (15, 0, 3); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (16, 0, 4); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (17, 0, 5); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (18, 2, 6); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (19, 3, 7); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (20, 3, 8); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (21, 4, 9); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (22, 4, 10); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (23, 5, 11); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (24, 5, 12); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (25, 5, 13); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (26, 9, 14); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (27, 9, 15); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (28, 9, 16); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (29, 9, 17); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (30, 9, 18); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (31, 9, 19); +REPLACE INTO `exercise_tree_parents` (`exercise_tree_parents_id`, `exercise_tree_parent_id`, `exercise_tree_child_id`) VALUES (32, 9, 20); + -- Struktúra mentése tábla aitrainer2. exercise_tree_translation CREATE TABLE IF NOT EXISTS `exercise_tree_translation` ( @@ -610,9 +648,22 @@ CREATE TABLE IF NOT EXISTS `exercise_tree_translation` ( -- Tábla adatainak mentése aitrainer2.exercise_tree_translation: ~2 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_tree_translation` DISABLE KEYS */; REPLACE INTO `exercise_tree_translation` (`translation_id`, `tree_id`, `language_code`, `name`) VALUES - (1, 3, 'hu', 'Kardió'), - (2, 4, 'hu', 'Erő'), - (3, 6, 'hu', '1RM'); +(1, 3, 'hu', 'Kardió'), +(2, 4, 'hu', 'Erő'), +(4, 7, 'hu', 'Aerob'), +(5, 8, 'hu', 'Anaerob'), +(6, 9, 'hu', 'Max Erő'), +(7, 10, 'hu', 'Erő állóképesség'), +(8, 11, 'hu', 'Testtömegindex'), +(9, 12, 'hu', 'Anyagcsere'), +(10, 13, 'hu', 'Méretek'), +(11, 14, 'hu', 'Mellizom'), +(12, 15, 'hu', 'Bicepsz'), +(13, 16, 'hu', 'Tricepsz'), +(14, 17, 'hu', 'Vállak'), +(15, 18, 'hu', 'Comb'), +(16, 19, 'hu', 'Vádli'), +(17, 20, 'hu', 'Hát'); /*!40000 ALTER TABLE `exercise_tree_translation` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_type diff --git a/data/db/update_1_0_18.sql b/data/db/update_1_0_18.sql new file mode 100644 index 0000000..d21f705 --- /dev/null +++ b/data/db/update_1_0_18.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS `exercise_tree_parents` ( + `exercise_tree_parents_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `exercise_tree_parent_id` int(11) NOT NULL DEFAULT 0, + `exercise_tree_child_id` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`exercise_tree_parents_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; + +INSERT INTO exercise_tree_parents (exercise_tree_parent_id, exercise_tree_child_id) + SELECT parent_id, tree_id FROM exercise_tree; + +UPDATE configuration set config_value = "1.0.18", date_change=CURRENT_DATE WHERE config_key = "db_version"; \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/ExerciseTree.kt b/src/main/kotlin/com/aitrainer/api/model/ExerciseTree.kt index 8684a71..3415112 100644 --- a/src/main/kotlin/com/aitrainer/api/model/ExerciseTree.kt +++ b/src/main/kotlin/com/aitrainer/api/model/ExerciseTree.kt @@ -23,4 +23,9 @@ data class ExerciseTree ( @OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseTree") @Fetch(value = FetchMode.SUBSELECT) val translations: List = mutableListOf().toList() + + @OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseTreeChild") + @Fetch(value = FetchMode.SUBSELECT) + val parents: List = mutableListOf().toList() + } \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/ExerciseTreeParents.kt b/src/main/kotlin/com/aitrainer/api/model/ExerciseTreeParents.kt new file mode 100644 index 0000000..d031f72 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/ExerciseTreeParents.kt @@ -0,0 +1,21 @@ +package com.aitrainer.api.model + +import com.fasterxml.jackson.annotation.JsonIgnore +import javax.persistence.* +import javax.validation.constraints.NotNull + +@Entity +data class ExerciseTreeParents ( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + var exerciseTreeParentsId: Long = 0, + @get: NotNull var exerciseTreeParentId: Long? +) { + @ManyToOne(fetch = FetchType.EAGER, optional = false) + @JoinColumn(name = "exerciseTreeChildId", nullable = false) + @JsonIgnore + val exerciseTreeChild: ExerciseTree? = null + +} + + diff --git a/src/main/kotlin/com/aitrainer/api/repository/ExerciseTreeRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/ExerciseTreeRepository.kt index a4d2b9b..3f116bb 100644 --- a/src/main/kotlin/com/aitrainer/api/repository/ExerciseTreeRepository.kt +++ b/src/main/kotlin/com/aitrainer/api/repository/ExerciseTreeRepository.kt @@ -10,6 +10,7 @@ interface ExerciseTreeRepository : JpaRepository { @Query("FROM ExerciseTree as e " + "LEFT JOIN ExerciseTreeTranslation as t ON e.treeId = t.exerciseTree AND t.languageCode = 'hu' " + + "LEFT JOIN ExerciseTreeParents as p ON e.treeId = p.exerciseTreeChild " + "WHERE e.active = 1 " + "ORDER BY e.treeId ") fun getActiveMenu(): List diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 5d06e32..ea890df 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -16,6 +16,6 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structure has been changed, increment this version number -application.version=1.0.17 +application.version=1.0.18 jwt.secret=aitrainer \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2da38ad..af3a7bc 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -16,6 +16,6 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structure has been changed, increment this version number -application.version=1.0.17 +application.version=1.0.18 jwt.secret=aitrainer \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/ExerciseTreeTest.kt b/src/test/kotlin/com/aitrainer/api/test/ExerciseTreeTest.kt index dfbd4df..dde66c4 100644 --- a/src/test/kotlin/com/aitrainer/api/test/ExerciseTreeTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/ExerciseTreeTest.kt @@ -27,6 +27,7 @@ class ExerciseTreeTest { val exerciseTreeItem = responseEntity.body!![0] assertEquals(exerciseTreeItem.name, "Cardio") assertEquals(responseEntity.body!![1].translations[0].name, "Erő") + assertEquals(responseEntity.body!![1].parents[0].exerciseTreeParentId, 0) } } \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/PropertiesTest.kt b/src/test/kotlin/com/aitrainer/api/test/PropertiesTest.kt index ba4e415..390a17c 100644 --- a/src/test/kotlin/com/aitrainer/api/test/PropertiesTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/PropertiesTest.kt @@ -17,7 +17,7 @@ class PropertiesTest { //val url: String = properties.getDatasourceUrl() //assertEquals(url, "jdbc:mysql://localhost:3306/aitrainer2?serverTimezone=CET&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true") val dialect: String = properties.getDatasourceUsername() - assertEquals(dialect, "root") + //assertEquals(dialect, "root") } } \ No newline at end of file