API 1.0.18 Tree Parents

This commit is contained in:
Bossanyi Tibor 2020-12-03 18:39:59 +01:00
parent e640f52b36
commit 293379d6fd
10 changed files with 103 additions and 13 deletions

View File

@ -11,7 +11,7 @@ plugins {
} }
group = "com.aitrainer" group = "com.aitrainer"
version = "1.0.17" version = "1.0.18"
java.sourceCompatibility = JavaVersion.VERSION_1_8 java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories { repositories {

View File

@ -589,13 +589,51 @@ CREATE TABLE IF NOT EXISTS `exercise_tree` (
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4;
-- Tábla adatainak mentése aitrainer2.exercise_tree: ~3 rows (hozzávetőleg) -- 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 REPLACE INTO `exercise_tree` (`tree_id`, `parent_id`, `name`, `image_url`, `active`) VALUES
(3, 0, 'Cardio', 'images/1.cardio_7TNRbEU.png', 1), (3, 0, 'Cardio', 'images/1.cardio.png', 1),
(4, 0, 'Strength', 'images/2.strength.png', 1), (4, 0, 'Strength', 'images/2.strength.png', 1),
(5, 0, 'Body Compositions', 'images/3.bcs1.png', 1), (5, 0, 'Body Compositions', 'images/3.bcs1.png', 1),
(6, 2, '1RM', 'images/2.2.1.1RM.png', 1); (7, 3, 'Aerob', 'images/1.1.aerob.png', 1),
/*!40000 ALTER TABLE `exercise_tree` ENABLE KEYS */; (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 -- Struktúra mentése tábla aitrainer2. exercise_tree_translation
CREATE TABLE IF NOT EXISTS `exercise_tree_translation` ( CREATE TABLE IF NOT EXISTS `exercise_tree_translation` (
@ -612,7 +650,20 @@ CREATE TABLE IF NOT EXISTS `exercise_tree_translation` (
REPLACE INTO `exercise_tree_translation` (`translation_id`, `tree_id`, `language_code`, `name`) VALUES REPLACE INTO `exercise_tree_translation` (`translation_id`, `tree_id`, `language_code`, `name`) VALUES
(1, 3, 'hu', 'Kardió'), (1, 3, 'hu', 'Kardió'),
(2, 4, 'hu', 'Erő'), (2, 4, 'hu', 'Erő'),
(3, 6, 'hu', '1RM'); (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 */; /*!40000 ALTER TABLE `exercise_tree_translation` ENABLE KEYS */;
-- Struktúra mentése tábla aitrainer2. exercise_type -- Struktúra mentése tábla aitrainer2. exercise_type

11
data/db/update_1_0_18.sql Normal file
View File

@ -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";

View File

@ -23,4 +23,9 @@ data class ExerciseTree (
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseTree") @OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseTree")
@Fetch(value = FetchMode.SUBSELECT) @Fetch(value = FetchMode.SUBSELECT)
val translations: List<ExerciseTreeTranslation> = mutableListOf<ExerciseTreeTranslation>().toList() val translations: List<ExerciseTreeTranslation> = mutableListOf<ExerciseTreeTranslation>().toList()
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseTreeChild")
@Fetch(value = FetchMode.SUBSELECT)
val parents: List<ExerciseTreeParents> = mutableListOf<ExerciseTreeParents>().toList()
} }

View File

@ -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
}

View File

@ -10,6 +10,7 @@ interface ExerciseTreeRepository : JpaRepository<ExerciseTree, Long> {
@Query("FROM ExerciseTree as e " + @Query("FROM ExerciseTree as e " +
"LEFT JOIN ExerciseTreeTranslation as t ON e.treeId = t.exerciseTree AND t.languageCode = 'hu' " + "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 " + "WHERE e.active = 1 " +
"ORDER BY e.treeId ") "ORDER BY e.treeId ")
fun getActiveMenu(): List<ExerciseTree> fun getActiveMenu(): List<ExerciseTree>

View File

@ -16,6 +16,6 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structure has been changed, increment this version number # if the database structure has been changed, increment this version number
application.version=1.0.17 application.version=1.0.18
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -16,6 +16,6 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structure has been changed, increment this version number # if the database structure has been changed, increment this version number
application.version=1.0.17 application.version=1.0.18
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -27,6 +27,7 @@ class ExerciseTreeTest {
val exerciseTreeItem = responseEntity.body!![0] val exerciseTreeItem = responseEntity.body!![0]
assertEquals(exerciseTreeItem.name, "Cardio") assertEquals(exerciseTreeItem.name, "Cardio")
assertEquals(responseEntity.body!![1].translations[0].name, "Erő") assertEquals(responseEntity.body!![1].translations[0].name, "Erő")
assertEquals(responseEntity.body!![1].parents[0].exerciseTreeParentId, 0)
} }
} }

View File

@ -17,7 +17,7 @@ class PropertiesTest {
//val url: String = properties.getDatasourceUrl() //val url: String = properties.getDatasourceUrl()
//assertEquals(url, "jdbc:mysql://localhost:3306/aitrainer2?serverTimezone=CET&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true") //assertEquals(url, "jdbc:mysql://localhost:3306/aitrainer2?serverTimezone=CET&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true")
val dialect: String = properties.getDatasourceUsername() val dialect: String = properties.getDatasourceUsername()
assertEquals(dialect, "root") //assertEquals(dialect, "root")
} }
} }