From e640f52b36b4660a101e8aba957e2c8444087ba9 Mon Sep 17 00:00:00 2001 From: Bossanyi Tibor Date: Thu, 3 Dec 2020 15:01:38 +0100 Subject: [PATCH 1/2] API 1.0.17 ExerciseTypeAlternative ExerciseDeviceAlternative ExerciseTypeParents --- build.gradle.kts | 2 +- data/db/install.sql | 90 ++++++------------- data/db/update_1_0_17.sql | 25 ++++++ .../com/aitrainer/api/model/ExerciseDevice.kt | 4 + .../api/model/ExerciseDeviceAlternative.kt | 22 +++++ .../com/aitrainer/api/model/ExerciseType.kt | 8 ++ .../api/model/ExerciseTypeAlternative.kt | 22 +++++ .../api/model/ExerciseTypeParents.kt | 22 +++++ .../repository/ExerciseDeviceRepository.kt | 1 + .../api/repository/ExerciseTypeRepository.kt | 2 + .../resources/application-prod.properties | 2 +- src/main/resources/application.properties | 2 +- .../aitrainer/api/test/ExerciseTypeTest.kt | 2 + 13 files changed, 140 insertions(+), 64 deletions(-) create mode 100644 data/db/update_1_0_17.sql create mode 100644 src/main/kotlin/com/aitrainer/api/model/ExerciseDeviceAlternative.kt create mode 100644 src/main/kotlin/com/aitrainer/api/model/ExerciseTypeAlternative.kt create mode 100644 src/main/kotlin/com/aitrainer/api/model/ExerciseTypeParents.kt diff --git a/build.gradle.kts b/build.gradle.kts index 0e91833..9cbf283 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.aitrainer" -version = "1.0.16" +version = "1.0.17" java.sourceCompatibility = JavaVersion.VERSION_1_8 repositories { diff --git a/data/db/install.sql b/data/db/install.sql index a07ac23..8be92ae 100644 --- a/data/db/install.sql +++ b/data/db/install.sql @@ -13,7 +13,6 @@ /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- Struktúra mentése tábla aitrainer2. auth_group -DROP TABLE IF EXISTS `auth_group`; CREATE TABLE IF NOT EXISTS `auth_group` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(150) COLLATE utf8_hungarian_ci NOT NULL, @@ -26,7 +25,6 @@ CREATE TABLE IF NOT EXISTS `auth_group` ( /*!40000 ALTER TABLE `auth_group` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. auth_group_permissions -DROP TABLE IF EXISTS `auth_group_permissions`; CREATE TABLE IF NOT EXISTS `auth_group_permissions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `group_id` int(11) NOT NULL, @@ -43,7 +41,6 @@ CREATE TABLE IF NOT EXISTS `auth_group_permissions` ( /*!40000 ALTER TABLE `auth_group_permissions` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. auth_permission -DROP TABLE IF EXISTS `auth_permission`; CREATE TABLE IF NOT EXISTS `auth_permission` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_hungarian_ci NOT NULL, @@ -56,7 +53,7 @@ CREATE TABLE IF NOT EXISTS `auth_permission` ( -- Tábla adatainak mentése aitrainer2.auth_permission: ~32 rows (hozzávetőleg) /*!40000 ALTER TABLE `auth_permission` DISABLE KEYS */; -INSERT INTO `auth_permission` (`id`, `name`, `content_type_id`, `codename`) VALUES +REPLACE INTO `auth_permission` (`id`, `name`, `content_type_id`, `codename`) VALUES (1, 'Can add exercise type', 1, 'add_exercisetype'), (2, 'Can change exercise type', 1, 'change_exercisetype'), (3, 'Can delete exercise type', 1, 'delete_exercisetype'), @@ -92,7 +89,6 @@ INSERT INTO `auth_permission` (`id`, `name`, `content_type_id`, `codename`) VALU /*!40000 ALTER TABLE `auth_permission` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. auth_user -DROP TABLE IF EXISTS `auth_user`; CREATE TABLE IF NOT EXISTS `auth_user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `password` varchar(128) COLLATE utf8_hungarian_ci NOT NULL, @@ -111,13 +107,12 @@ CREATE TABLE IF NOT EXISTS `auth_user` ( -- Tábla adatainak mentése aitrainer2.auth_user: ~2 rows (hozzávetőleg) /*!40000 ALTER TABLE `auth_user` DISABLE KEYS */; -INSERT INTO `auth_user` (`id`, `password`, `last_login`, `is_superuser`, `username`, `first_name`, `last_name`, `email`, `is_staff`, `is_active`, `date_joined`) VALUES +REPLACE INTO `auth_user` (`id`, `password`, `last_login`, `is_superuser`, `username`, `first_name`, `last_name`, `email`, `is_staff`, `is_active`, `date_joined`) VALUES (1, 'pbkdf2_sha256$180000$WhaET4L6Ebme$JTn/z9eX1S0zZVJeO0saJClgwakCR9PXIBYXQtVHBjs=', '2020-11-19 19:36:52.009635', 1, 'bossanyit', '', '', 'tibor.bossanyi@aitrainer.app', 1, 1, '2020-07-15 20:42:37.000000'), (2, 'pbkdf2_sha256$180000$KWuUPcTheOKy$r3pccArHppBYlHIPxb9bInGPLxFmLKMBUXwuPrcQ/2w=', NULL, 0, 'bossanyiz', '', '', '', 1, 1, '2020-07-15 21:17:11.000000'); /*!40000 ALTER TABLE `auth_user` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. auth_user_groups -DROP TABLE IF EXISTS `auth_user_groups`; CREATE TABLE IF NOT EXISTS `auth_user_groups` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, @@ -134,7 +129,6 @@ CREATE TABLE IF NOT EXISTS `auth_user_groups` ( /*!40000 ALTER TABLE `auth_user_groups` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. auth_user_user_permissions -DROP TABLE IF EXISTS `auth_user_user_permissions`; CREATE TABLE IF NOT EXISTS `auth_user_user_permissions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, @@ -148,7 +142,7 @@ CREATE TABLE IF NOT EXISTS `auth_user_user_permissions` ( -- Tábla adatainak mentése aitrainer2.auth_user_user_permissions: ~12 rows (hozzávetőleg) /*!40000 ALTER TABLE `auth_user_user_permissions` DISABLE KEYS */; -INSERT INTO `auth_user_user_permissions` (`id`, `user_id`, `permission_id`) VALUES +REPLACE INTO `auth_user_user_permissions` (`id`, `user_id`, `permission_id`) VALUES (1, 2, 1), (2, 2, 2), (3, 2, 3), @@ -164,7 +158,6 @@ INSERT INTO `auth_user_user_permissions` (`id`, `user_id`, `permission_id`) VALU /*!40000 ALTER TABLE `auth_user_user_permissions` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. configuration -DROP TABLE IF EXISTS `configuration`; CREATE TABLE IF NOT EXISTS `configuration` ( `configuration_id` int(11) NOT NULL AUTO_INCREMENT, `config_key` char(50) COLLATE utf8_hungarian_ci DEFAULT NULL, @@ -176,12 +169,11 @@ CREATE TABLE IF NOT EXISTS `configuration` ( -- Tábla adatainak mentése aitrainer2.configuration: ~0 rows (hozzávetőleg) /*!40000 ALTER TABLE `configuration` DISABLE KEYS */; -INSERT INTO `configuration` (`configuration_id`, `config_key`, `config_value`, `date_add`, `date_change`) VALUES +REPLACE INTO `configuration` (`configuration_id`, `config_key`, `config_value`, `date_add`, `date_change`) VALUES (1, 'db_version', '1.0.16', '2020-05-30 07:00:00', '2020-11-26 00:00:00'); /*!40000 ALTER TABLE `configuration` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. customer -DROP TABLE IF EXISTS `customer`; CREATE TABLE IF NOT EXISTS `customer` ( `customer_id` int(11) NOT NULL AUTO_INCREMENT, `name` char(100) COLLATE utf8_hungarian_ci NOT NULL, @@ -209,7 +201,7 @@ CREATE TABLE IF NOT EXISTS `customer` ( -- Tábla adatainak mentése aitrainer2.customer: ~17 rows (hozzávetőleg) /*!40000 ALTER TABLE `customer` DISABLE KEYS */; -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES +REPLACE INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (1, 'Átlag 13 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', NULL, 'firebaseuid_customer_1'), (2, 'Átlag 14 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), (3, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), @@ -230,7 +222,6 @@ INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, /*!40000 ALTER TABLE `customer` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. customer_exercise_device -DROP TABLE IF EXISTS `customer_exercise_device`; CREATE TABLE IF NOT EXISTS `customer_exercise_device` ( `customer_exercise_device_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `customer_id` int(11) NOT NULL DEFAULT 0, @@ -242,14 +233,13 @@ CREATE TABLE IF NOT EXISTS `customer_exercise_device` ( -- Tábla adatainak mentése aitrainer2.customer_exercise_device: ~2 rows (hozzávetőleg) /*!40000 ALTER TABLE `customer_exercise_device` DISABLE KEYS */; -INSERT INTO `customer_exercise_device` (`customer_exercise_device_id`, `customer_id`, `exercise_device_id`, `date_add`, `favourite`) VALUES +REPLACE INTO `customer_exercise_device` (`customer_exercise_device_id`, `customer_id`, `exercise_device_id`, `date_add`, `favourite`) VALUES (1, 90, 1, NULL, NULL), (2, 90, 2, NULL, NULL), (3, 90, 5, NULL, NULL); /*!40000 ALTER TABLE `customer_exercise_device` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. customer_information -DROP TABLE IF EXISTS `customer_information`; CREATE TABLE IF NOT EXISTS `customer_information` ( `customer_information_id` int(11) NOT NULL AUTO_INCREMENT, `title` char(50) COLLATE utf8_hungarian_ci DEFAULT '', @@ -263,14 +253,13 @@ CREATE TABLE IF NOT EXISTS `customer_information` ( -- Tábla adatainak mentése aitrainer2.customer_information: ~3 rows (hozzávetőleg) /*!40000 ALTER TABLE `customer_information` DISABLE KEYS */; -INSERT INTO `customer_information` (`customer_information_id`, `title`, `description`, `date_add`, `display_begin`, `display_end`) VALUES +REPLACE INTO `customer_information` (`customer_information_id`, `title`, `description`, `date_add`, `display_begin`, `display_end`) VALUES (1, 'Fekvőtámasz világcsúcs', 'Világcsúcs fekvőtámasz: KJ Joseph 1 perc alatt 82 szabályos fekvőtámaszt végzett', '2020-06-01 08:00:00', '2020-06-01 08:00:00', '2023-07-01 08:00:00'), (2, 'Húzódszkodás csúcs', '24 órás csúcstartója Joonas Mäkipelto 5050 gyakorlattal', '2020-06-01 08:00:00', '2020-06-01 08:00:00', '2023-07-01 08:00:00'), (3, 'Fekvenyomás', '2015-ben a fekvenyomó világbajnokságot Smulter Fredrik finn súlyemelő 401 Kg-al nyerte', '2020-06-01 08:00:00', '2020-05-01 00:00:00', '2020-06-01 08:00:01'); /*!40000 ALTER TABLE `customer_information` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. customer_property -DROP TABLE IF EXISTS `customer_property`; CREATE TABLE IF NOT EXISTS `customer_property` ( `customer_property_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `customer_id` int(10) unsigned NOT NULL DEFAULT 0, @@ -282,7 +271,7 @@ CREATE TABLE IF NOT EXISTS `customer_property` ( -- Tábla adatainak mentése aitrainer2.customer_property: ~7 rows (hozzávetőleg) /*!40000 ALTER TABLE `customer_property` DISABLE KEYS */; -INSERT INTO `customer_property` (`customer_property_id`, `customer_id`, `property_id`, `property_value`, `date_add`) VALUES +REPLACE INTO `customer_property` (`customer_property_id`, `customer_id`, `property_id`, `property_value`, `date_add`) VALUES (1, 90, 1, 81, '2020-09-09 21:53:29'), (2, 90, 1, 82, '2020-11-09 21:53:53'), (3, 90, 2, 172, '2020-09-09 21:55:18'), @@ -293,7 +282,6 @@ INSERT INTO `customer_property` (`customer_property_id`, `customer_id`, `propert /*!40000 ALTER TABLE `customer_property` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. django_admin_log -DROP TABLE IF EXISTS `django_admin_log`; CREATE TABLE IF NOT EXISTS `django_admin_log` ( `id` int(11) NOT NULL AUTO_INCREMENT, `action_time` datetime(6) NOT NULL, @@ -312,7 +300,7 @@ CREATE TABLE IF NOT EXISTS `django_admin_log` ( -- Tábla adatainak mentése aitrainer2.django_admin_log: ~60 rows (hozzávetőleg) /*!40000 ALTER TABLE `django_admin_log` DISABLE KEYS */; -INSERT INTO `django_admin_log` (`id`, `action_time`, `object_id`, `object_repr`, `action_flag`, `change_message`, `content_type_id`, `user_id`) VALUES +REPLACE INTO `django_admin_log` (`id`, `action_time`, `object_id`, `object_repr`, `action_flag`, `change_message`, `content_type_id`, `user_id`) VALUES (1, '2020-07-15 21:17:11.320125', '2', 'bossanyiz', 1, '[{"added": {}}]', 6, 1), (2, '2020-07-15 21:18:14.459237', '2', 'bossanyiz', 2, '[{"changed": {"fields": ["Staff status", "User permissions"]}}]', 6, 1), (3, '2020-07-15 21:18:34.536886', '1', 'bossanyit', 2, '[]', 6, 1), @@ -385,7 +373,6 @@ INSERT INTO `django_admin_log` (`id`, `action_time`, `object_id`, `object_repr`, /*!40000 ALTER TABLE `django_admin_log` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. django_content_type -DROP TABLE IF EXISTS `django_content_type`; CREATE TABLE IF NOT EXISTS `django_content_type` ( `id` int(11) NOT NULL AUTO_INCREMENT, `app_label` varchar(100) COLLATE utf8_hungarian_ci NOT NULL, @@ -396,7 +383,7 @@ CREATE TABLE IF NOT EXISTS `django_content_type` ( -- Tábla adatainak mentése aitrainer2.django_content_type: ~16 rows (hozzávetőleg) /*!40000 ALTER TABLE `django_content_type` DISABLE KEYS */; -INSERT INTO `django_content_type` (`id`, `app_label`, `model`) VALUES +REPLACE INTO `django_content_type` (`id`, `app_label`, `model`) VALUES (3, 'admin', 'logentry'), (14, 'aitrainer_backoffice', 'customerproduct'), (17, 'aitrainer_backoffice', 'exercisedevice'), @@ -417,7 +404,6 @@ INSERT INTO `django_content_type` (`id`, `app_label`, `model`) VALUES /*!40000 ALTER TABLE `django_content_type` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. django_migrations -DROP TABLE IF EXISTS `django_migrations`; CREATE TABLE IF NOT EXISTS `django_migrations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `app` varchar(255) COLLATE utf8_hungarian_ci NOT NULL, @@ -428,7 +414,7 @@ CREATE TABLE IF NOT EXISTS `django_migrations` ( -- Tábla adatainak mentése aitrainer2.django_migrations: ~17 rows (hozzávetőleg) /*!40000 ALTER TABLE `django_migrations` DISABLE KEYS */; -INSERT INTO `django_migrations` (`id`, `app`, `name`, `applied`) VALUES +REPLACE INTO `django_migrations` (`id`, `app`, `name`, `applied`) VALUES (1, 'contenttypes', '0001_initial', '2020-07-15 20:37:56.322447'), (2, 'auth', '0001_initial', '2020-07-15 20:37:56.612931'), (3, 'admin', '0001_initial', '2020-07-15 20:37:57.660438'), @@ -449,7 +435,6 @@ INSERT INTO `django_migrations` (`id`, `app`, `name`, `applied`) VALUES /*!40000 ALTER TABLE `django_migrations` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. django_session -DROP TABLE IF EXISTS `django_session`; CREATE TABLE IF NOT EXISTS `django_session` ( `session_key` varchar(40) COLLATE utf8_hungarian_ci NOT NULL, `session_data` longtext COLLATE utf8_hungarian_ci NOT NULL, @@ -460,7 +445,7 @@ CREATE TABLE IF NOT EXISTS `django_session` ( -- Tábla adatainak mentése aitrainer2.django_session: ~6 rows (hozzávetőleg) /*!40000 ALTER TABLE `django_session` DISABLE KEYS */; -INSERT INTO `django_session` (`session_key`, `session_data`, `expire_date`) VALUES +REPLACE INTO `django_session` (`session_key`, `session_data`, `expire_date`) VALUES ('6oeeoxy9mt0kdbjgmvhl74qeqpefxaox', 'OWQ2YmUzOGUyZjA1MmRmNDFhYjU5MDQ3ODMzZmNkZWZkYjQ2MjA2MDp7Il9hdXRoX3VzZXJfaWQiOiIxIiwiX2F1dGhfdXNlcl9iYWNrZW5kIjoiZGphbmdvLmNvbnRyaWIuYXV0aC5iYWNrZW5kcy5Nb2RlbEJhY2tlbmQiLCJfYXV0aF91c2VyX2hhc2giOiJmM2ZiZmYzNWVjOTljMWEwZjk3OTg2MjM3Nzg4MGY5M2I0MDY5OGI0In0=', '2020-07-29 20:45:32.410329'), ('j85p9jioio21gkg781wlih3ai1p8wrwv', 'OWFmMzBlYmEzMzE4YWZhMzQyYzY2ZDljNmMxZmFmNWJkMTZlN2Q5Yjp7Il9hdXRoX3VzZXJfaWQiOiIxIiwiX2F1dGhfdXNlcl9iYWNrZW5kIjoiZGphbmdvLmNvbnRyaWIuYXV0aC5iYWNrZW5kcy5Nb2RlbEJhY2tlbmQiLCJfYXV0aF91c2VyX2hhc2giOiI4M2ExMzllOTNmZDVlYmI4ODE1NWZkZWZjMjg3NWQ2NTAxNzJmNzNjIn0=', '2020-12-03 19:36:52.014607'), ('job30dq18a2wr4upc589m348alh30yh2', 'OWFmMzBlYmEzMzE4YWZhMzQyYzY2ZDljNmMxZmFmNWJkMTZlN2Q5Yjp7Il9hdXRoX3VzZXJfaWQiOiIxIiwiX2F1dGhfdXNlcl9iYWNrZW5kIjoiZGphbmdvLmNvbnRyaWIuYXV0aC5iYWNrZW5kcy5Nb2RlbEJhY2tlbmQiLCJfYXV0aF91c2VyX2hhc2giOiI4M2ExMzllOTNmZDVlYmI4ODE1NWZkZWZjMjg3NWQ2NTAxNzJmNzNjIn0=', '2020-08-01 14:20:28.190449'), @@ -470,7 +455,6 @@ INSERT INTO `django_session` (`session_key`, `session_data`, `expire_date`) VALU /*!40000 ALTER TABLE `django_session` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercises -DROP TABLE IF EXISTS `exercises`; CREATE TABLE IF NOT EXISTS `exercises` ( `exercise_id` int(11) NOT NULL AUTO_INCREMENT, `exercise_type_id` int(11) NOT NULL, @@ -488,7 +472,7 @@ CREATE TABLE IF NOT EXISTS `exercises` ( -- Tábla adatainak mentése aitrainer2.exercises: ~4 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercises` DISABLE KEYS */; -INSERT INTO `exercises` (`exercise_id`, `exercise_type_id`, `customer_id`, `date_add`, `quantity`, `unit`, `unit_quantity`, `rest_time`, `exercise_plan_detail_id`) VALUES +REPLACE INTO `exercises` (`exercise_id`, `exercise_type_id`, `customer_id`, `date_add`, `quantity`, `unit`, `unit_quantity`, `rest_time`, `exercise_plan_detail_id`) VALUES (1, 1, 1, '2020-05-01 00:00:00', 12.2, 'repeat', NULL, NULL, 0), (2, 3, 11, '2020-05-13 04:32:00', 100, 'repeat', 30, NULL, 0), (69, 2, 1, '2020-05-14 03:43:45', 30, 'repeat', 12, NULL, 0), @@ -496,7 +480,6 @@ INSERT INTO `exercises` (`exercise_id`, `exercise_type_id`, `customer_id`, `date /*!40000 ALTER TABLE `exercises` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_device -DROP TABLE IF EXISTS `exercise_device`; CREATE TABLE IF NOT EXISTS `exercise_device` ( `exercise_device_id` int(11) NOT NULL AUTO_INCREMENT, `name` char(50) COLLATE utf8_hungarian_ci DEFAULT NULL, @@ -509,7 +492,7 @@ CREATE TABLE IF NOT EXISTS `exercise_device` ( -- Tábla adatainak mentése aitrainer2.exercise_device: ~2 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_device` DISABLE KEYS */; -INSERT INTO `exercise_device` (`exercise_device_id`, `name`, `description`, `image_url`, `sort`, `place`) VALUES +REPLACE INTO `exercise_device` (`exercise_device_id`, `name`, `description`, `image_url`, `sort`, `place`) VALUES (1, 'Weight', NULL, NULL, 5, 0), (2, 'Own Weight', NULL, NULL, 4, 0), (3, 'Machine', '', 'images/csengo2.png', 3, 0), @@ -518,7 +501,6 @@ INSERT INTO `exercise_device` (`exercise_device_id`, `name`, `description`, `ima /*!40000 ALTER TABLE `exercise_device` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_device_translation -DROP TABLE IF EXISTS `exercise_device_translation`; CREATE TABLE IF NOT EXISTS `exercise_device_translation` ( `translation_id` int(11) NOT NULL AUTO_INCREMENT, `exercise_device_id` int(11) DEFAULT NULL, @@ -530,14 +512,13 @@ CREATE TABLE IF NOT EXISTS `exercise_device_translation` ( -- Tábla adatainak mentése aitrainer2.exercise_device_translation: ~3 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_device_translation` DISABLE KEYS */; -INSERT INTO `exercise_device_translation` (`translation_id`, `exercise_device_id`, `language_code`, `name`) VALUES +REPLACE INTO `exercise_device_translation` (`translation_id`, `exercise_device_id`, `language_code`, `name`) VALUES (1, 1, 'hu', 'Súlyzó'), (2, 2, 'hu', 'Saját testsúly'), (3, 3, 'hu', 'Edzőtermi gép'); /*!40000 ALTER TABLE `exercise_device_translation` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_plan -DROP TABLE IF EXISTS `exercise_plan`; CREATE TABLE IF NOT EXISTS `exercise_plan` ( `exercise_plan_id` int(11) NOT NULL AUTO_INCREMENT, `customer_id` int(11) NOT NULL DEFAULT 0, @@ -551,7 +532,7 @@ CREATE TABLE IF NOT EXISTS `exercise_plan` ( -- Tábla adatainak mentése aitrainer2.exercise_plan: ~4 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_plan` DISABLE KEYS */; -INSERT INTO `exercise_plan` (`exercise_plan_id`, `customer_id`, `name`, `description`, `private`, `date_add`, `date_upd`) VALUES +REPLACE INTO `exercise_plan` (`exercise_plan_id`, `customer_id`, `name`, `description`, `private`, `date_add`, `date_upd`) VALUES (3, 90, 'Common', 'Common training plan', 0, NULL, NULL), (4, 90, 'Chuck Norris Plan', '', 0, NULL, NULL), (6, 90, 'Boss private', '', 1, '2020-09-08 00:06:26', NULL), @@ -559,7 +540,6 @@ INSERT INTO `exercise_plan` (`exercise_plan_id`, `customer_id`, `name`, `descrip /*!40000 ALTER TABLE `exercise_plan` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_plan_detail -DROP TABLE IF EXISTS `exercise_plan_detail`; CREATE TABLE IF NOT EXISTS `exercise_plan_detail` ( `exercise_plan_detail_id` int(11) NOT NULL AUTO_INCREMENT, `exercise_plan_id` int(11) NOT NULL DEFAULT 0, @@ -572,7 +552,7 @@ CREATE TABLE IF NOT EXISTS `exercise_plan_detail` ( -- Tábla adatainak mentése aitrainer2.exercise_plan_detail: ~5 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_plan_detail` DISABLE KEYS */; -INSERT INTO `exercise_plan_detail` (`exercise_plan_detail_id`, `exercise_plan_id`, `exercise_type_id`, `serie`, `repeats`, `weight_equation`) VALUES +REPLACE INTO `exercise_plan_detail` (`exercise_plan_detail_id`, `exercise_plan_id`, `exercise_type_id`, `serie`, `repeats`, `weight_equation`) VALUES (1, 3, 35, 3, 20, '75%'), (2, 3, 36, 3, 50, '75%'), (3, 4, 37, 3, 12, '85%'), @@ -581,7 +561,6 @@ INSERT INTO `exercise_plan_detail` (`exercise_plan_detail_id`, `exercise_plan_id /*!40000 ALTER TABLE `exercise_plan_detail` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_plan_translation -DROP TABLE IF EXISTS `exercise_plan_translation`; CREATE TABLE IF NOT EXISTS `exercise_plan_translation` ( `translation_id` int(11) NOT NULL AUTO_INCREMENT, `language_code` char(2) NOT NULL DEFAULT '0', @@ -593,13 +572,12 @@ CREATE TABLE IF NOT EXISTS `exercise_plan_translation` ( -- Tábla adatainak mentése aitrainer2.exercise_plan_translation: ~2 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_plan_translation` DISABLE KEYS */; -INSERT INTO `exercise_plan_translation` (`translation_id`, `language_code`, `name`, `description`, `exercise_plan_id`) VALUES +REPLACE INTO `exercise_plan_translation` (`translation_id`, `language_code`, `name`, `description`, `exercise_plan_id`) VALUES (1, 'hu', 'Általános', 'Általános edzésterv', 3), (2, 'hu', 'Chuck Norris', '', 4); /*!40000 ALTER TABLE `exercise_plan_translation` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_tree -DROP TABLE IF EXISTS `exercise_tree`; CREATE TABLE IF NOT EXISTS `exercise_tree` ( `tree_id` int(11) NOT NULL AUTO_INCREMENT, `parent_id` int(11) NOT NULL DEFAULT 0, @@ -612,7 +590,7 @@ CREATE TABLE IF NOT EXISTS `exercise_tree` ( -- Tábla adatainak mentése aitrainer2.exercise_tree: ~3 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_tree` DISABLE KEYS */; -INSERT 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), (4, 0, 'Strength', 'images/2.strength.png', 1), (5, 0, 'Body Compositions', 'images/3.bcs1.png', 1), @@ -620,7 +598,6 @@ INSERT INTO `exercise_tree` (`tree_id`, `parent_id`, `name`, `image_url`, `activ /*!40000 ALTER TABLE `exercise_tree` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_tree_translation -DROP TABLE IF EXISTS `exercise_tree_translation`; CREATE TABLE IF NOT EXISTS `exercise_tree_translation` ( `translation_id` int(13) NOT NULL AUTO_INCREMENT, `tree_id` int(13) NOT NULL DEFAULT 0, @@ -632,14 +609,13 @@ 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 */; -INSERT 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ó'), (2, 4, 'hu', 'Erő'), (3, 6, 'hu', '1RM'); /*!40000 ALTER TABLE `exercise_tree_translation` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_type -DROP TABLE IF EXISTS `exercise_type`; CREATE TABLE IF NOT EXISTS `exercise_type` ( `exercise_type_id` int(11) NOT NULL AUTO_INCREMENT, `tree_id` int(11) NOT NULL, @@ -656,7 +632,7 @@ CREATE TABLE IF NOT EXISTS `exercise_type` ( -- Tábla adatainak mentése aitrainer2.exercise_type: ~26 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_type` DISABLE KEYS */; -INSERT INTO `exercise_type` (`exercise_type_id`, `tree_id`, `name`, `description`, `unit`, `unit_quantity`, `unit_quantity_unit`, `active`, `base`) VALUES +REPLACE INTO `exercise_type` (`exercise_type_id`, `tree_id`, `name`, `description`, `unit`, `unit_quantity`, `unit_quantity_unit`, `active`, `base`) VALUES (1, 0, 'Melső fekvőtámasz 1 perc', 'Ezt igazolja a 2016 márciusában beállított guinness rekord is,\r\namelyben KJ Joseph 1 perc alatt 82 szabályos karhajlítás-nyújtást\r\nvégzett.', 'repeat', 60, 'second', NULL, 0), (2, 0, 'Húzódzkodás', 'Ennek a gyakorlatnak a 24 órás csúcstartója Joonas Mäkipelto 5050\r\ngyakorlattal.', 'repeat', NULL, NULL, NULL, 0), (3, 0, 'Melső fekvőtámasz 30mp', 'A gyakorlatot 30 másodperc alatt olyan sokszor kell végrehajtani, ahányszor a\r\nfelvételiző képes rá. Azonban törekedni kell a szabályos végrehajtásra, ugyanis csak azokat\r\nszámolják. A nők esetében 20, a férfiak esetében 35 gyakorlatot kell végrehajtani a maximális\r\npont megszerzéséért. A gyakorlat akkor sikeres, ha a női legalább 1, a férfi felvételiző\r\nlegalább 11 gyakorlatot képes végrehajtani.', 'repeat', 30, 'second', NULL, 0), @@ -686,7 +662,6 @@ INSERT INTO `exercise_type` (`exercise_type_id`, `tree_id`, `name`, `description /*!40000 ALTER TABLE `exercise_type` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_type_device -DROP TABLE IF EXISTS `exercise_type_device`; CREATE TABLE IF NOT EXISTS `exercise_type_device` ( `exercise_type_device_id` int(11) NOT NULL AUTO_INCREMENT, `exercise_type_id` int(11) NOT NULL DEFAULT 0, @@ -698,14 +673,13 @@ CREATE TABLE IF NOT EXISTS `exercise_type_device` ( -- Tábla adatainak mentése aitrainer2.exercise_type_device: ~3 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_type_device` DISABLE KEYS */; -INSERT INTO `exercise_type_device` (`exercise_type_device_id`, `exercise_type_id`, `exercise_device_id`) VALUES +REPLACE INTO `exercise_type_device` (`exercise_type_device_id`, `exercise_type_id`, `exercise_device_id`) VALUES (1, 37, 1), (2, 38, 1), (3, 38, 3); /*!40000 ALTER TABLE `exercise_type_device` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_type_image -DROP TABLE IF EXISTS `exercise_type_image`; CREATE TABLE IF NOT EXISTS `exercise_type_image` ( `image_id` int(13) NOT NULL AUTO_INCREMENT, `exercise_type_id` int(13) DEFAULT 0, @@ -717,7 +691,7 @@ CREATE TABLE IF NOT EXISTS `exercise_type_image` ( -- Tábla adatainak mentése aitrainer2.exercise_type_image: ~5 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_type_image` DISABLE KEYS */; -INSERT INTO `exercise_type_image` (`image_id`, `exercise_type_id`, `name`, `type`, `url`) VALUES +REPLACE INTO `exercise_type_image` (`image_id`, `exercise_type_id`, `name`, `type`, `url`) VALUES (3, 43, 'Menu', 'menu', '3.2.BMR.png'), (4, 42, 'Menu', 'menu', 'images/3.1.BMI.png'), (5, 37, 'Menu', 'menu', 'images/2.2.1.1.chestpress.png'), @@ -726,7 +700,6 @@ INSERT INTO `exercise_type_image` (`image_id`, `exercise_type_id`, `name`, `type /*!40000 ALTER TABLE `exercise_type_image` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. exercise_type_translation -DROP TABLE IF EXISTS `exercise_type_translation`; CREATE TABLE IF NOT EXISTS `exercise_type_translation` ( `translation_id` int(13) NOT NULL AUTO_INCREMENT, `language_code` char(2) NOT NULL DEFAULT 'en', @@ -738,7 +711,7 @@ CREATE TABLE IF NOT EXISTS `exercise_type_translation` ( -- Tábla adatainak mentése aitrainer2.exercise_type_translation: ~7 rows (hozzávetőleg) /*!40000 ALTER TABLE `exercise_type_translation` DISABLE KEYS */; -INSERT INTO `exercise_type_translation` (`translation_id`, `language_code`, `exercise_type_id`, `name`, `description`) VALUES +REPLACE INTO `exercise_type_translation` (`translation_id`, `language_code`, `exercise_type_id`, `name`, `description`) VALUES (1, 'hu', 42, 'Testtömegindex', NULL), (2, 'hu', 33, 'Fekvőtámasz', 'fekvőtámasz'), (3, 'en', 33, 'Pushups', 'pushup'), @@ -749,7 +722,6 @@ INSERT INTO `exercise_type_translation` (`translation_id`, `language_code`, `exe /*!40000 ALTER TABLE `exercise_type_translation` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. product -DROP TABLE IF EXISTS `product`; CREATE TABLE IF NOT EXISTS `product` ( `product_id` int(11) NOT NULL AUTO_INCREMENT, `name` char(50) NOT NULL, @@ -762,7 +734,7 @@ CREATE TABLE IF NOT EXISTS `product` ( -- Tábla adatainak mentése aitrainer2.product: ~12 rows (hozzávetőleg) /*!40000 ALTER TABLE `product` DISABLE KEYS */; -INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES +REPLACE INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (1, 'Subscription A', '700 Ft', 'subscription', '2020-11-01', NULL), (2, 'Subscription B', '1000 Ft', 'subscription', '2020-11-01', NULL), (3, 'Subscription C', '1500 Ft', 'subscription', '2020-11-01', NULL), @@ -778,7 +750,6 @@ INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from` /*!40000 ALTER TABLE `product` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. product_test -DROP TABLE IF EXISTS `product_test`; CREATE TABLE IF NOT EXISTS `product_test` ( `product_test_id` int(11) NOT NULL AUTO_INCREMENT, `product_id` int(11) DEFAULT 0, @@ -791,14 +762,13 @@ CREATE TABLE IF NOT EXISTS `product_test` ( -- Tábla adatainak mentése aitrainer2.product_test: ~3 rows (hozzávetőleg) /*!40000 ALTER TABLE `product_test` DISABLE KEYS */; -INSERT INTO `product_test` (`product_test_id`, `product_id`, `customer_id`, `date_view`, `purchase_click`) VALUES +REPLACE INTO `product_test` (`product_test_id`, `product_id`, `customer_id`, `date_view`, `purchase_click`) VALUES (4, 2, 62, '2020-10-01 12:00:00', 0), (5, 2, 62, '2020-11-01 12:00:00', 0), (8, 1, 1, '2020-11-01 07:07:02', 0); /*!40000 ALTER TABLE `product_test` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. property -DROP TABLE IF EXISTS `property`; CREATE TABLE IF NOT EXISTS `property` ( `property_id` int(11) NOT NULL AUTO_INCREMENT, `property_name` char(50) COLLATE utf8_hungarian_ci DEFAULT NULL, @@ -808,7 +778,7 @@ CREATE TABLE IF NOT EXISTS `property` ( -- Tábla adatainak mentése aitrainer2.property: ~4 rows (hozzávetőleg) /*!40000 ALTER TABLE `property` DISABLE KEYS */; -INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES +REPLACE INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES (1, 'Weight', 'kg'), (2, 'Height', 'cm'), (3, 'Chest', 'cm'), @@ -816,7 +786,6 @@ INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES /*!40000 ALTER TABLE `property` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. property_translation -DROP TABLE IF EXISTS `property_translation`; CREATE TABLE IF NOT EXISTS `property_translation` ( `translation_id` int(13) NOT NULL AUTO_INCREMENT, `language_code` char(2) NOT NULL DEFAULT 'en', @@ -827,12 +796,11 @@ CREATE TABLE IF NOT EXISTS `property_translation` ( -- Tábla adatainak mentése aitrainer2.property_translation: ~0 rows (hozzávetőleg) /*!40000 ALTER TABLE `property_translation` DISABLE KEYS */; -INSERT INTO `property_translation` (`translation_id`, `language_code`, `property_id`, `property_name`) VALUES +REPLACE INTO `property_translation` (`translation_id`, `language_code`, `property_id`, `property_name`) VALUES (1, 'hu', 1, 'Tömeg'); /*!40000 ALTER TABLE `property_translation` ENABLE KEYS */; -- Struktúra mentése tábla aitrainer2. purchase -DROP TABLE IF EXISTS `purchase`; CREATE TABLE IF NOT EXISTS `purchase` ( `purchase_id` int(11) NOT NULL AUTO_INCREMENT, `customer_id` int(11) NOT NULL DEFAULT 0, @@ -846,7 +814,7 @@ CREATE TABLE IF NOT EXISTS `purchase` ( -- Tábla adatainak mentése aitrainer2.purchase: ~5 rows (hozzávetőleg) /*!40000 ALTER TABLE `purchase` DISABLE KEYS */; -INSERT INTO `purchase` (`purchase_id`, `customer_id`, `product_id`, `date_add`, `purchase_sum`, `currency`) VALUES +REPLACE INTO `purchase` (`purchase_id`, `customer_id`, `product_id`, `date_add`, `purchase_sum`, `currency`) VALUES (1, 62, 1, '2020-10-03 00:00:00', 1000, 'HUF'), (2, 62, 1, '2020-11-05 15:45:08', 1000, 'HUF'), (3, 2, 1, '2020-11-05 15:45:30', 1000, 'HUF'), diff --git a/data/db/update_1_0_17.sql b/data/db/update_1_0_17.sql new file mode 100644 index 0000000..ccdfcc6 --- /dev/null +++ b/data/db/update_1_0_17.sql @@ -0,0 +1,25 @@ +CREATE TABLE IF NOT EXISTS `exercise_device_alternative` ( + `exercise_device_alternative_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `exercise_device_parent_id` int(11) NOT NULL DEFAULT 0, + `exercise_device_child_id` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`exercise_device_alternative_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; + +CREATE TABLE IF NOT EXISTS `exercise_type_alternative` ( + `exercise_type_alternative_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `exercise_type_parent_id` int(11) NOT NULL DEFAULT 0, + `exercise_type_child_id` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`exercise_type_alternative_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; + +CREATE TABLE IF NOT EXISTS `exercise_type_parents` ( + `exercise_type_parents_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `exercise_tree_id` int(11) NOT NULL DEFAULT 0, + `exercise_type_id` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`exercise_type_parents_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; + +INSERT INTO exercise_type_parents (exercise_tree_id, exercise_type_id) + SELECT tree_id, exercise_type_id FROM exercise_type; + +UPDATE configuration set config_value = "1.0.17", 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/ExerciseDevice.kt b/src/main/kotlin/com/aitrainer/api/model/ExerciseDevice.kt index 188b8fe..0c37f69 100644 --- a/src/main/kotlin/com/aitrainer/api/model/ExerciseDevice.kt +++ b/src/main/kotlin/com/aitrainer/api/model/ExerciseDevice.kt @@ -20,4 +20,8 @@ data class ExerciseDevice ( @OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseDevice") @Fetch(value = FetchMode.SUBSELECT) val translations: List = mutableListOf().toList() + + @OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseDevice") + @Fetch(value = FetchMode.SUBSELECT) + val alternatives: List = mutableListOf().toList() } diff --git a/src/main/kotlin/com/aitrainer/api/model/ExerciseDeviceAlternative.kt b/src/main/kotlin/com/aitrainer/api/model/ExerciseDeviceAlternative.kt new file mode 100644 index 0000000..304a804 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/ExerciseDeviceAlternative.kt @@ -0,0 +1,22 @@ +package com.aitrainer.api.model + +import com.fasterxml.jackson.annotation.JsonIgnore +import javax.persistence.* +import javax.validation.constraints.NotNull + +@Entity +data class ExerciseDeviceAlternative ( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + var exerciseDeviceAlternativeId: Long = 0, + //@get: NotNull var exerciseDeviceParentId: Long?, + @get: NotNull var exerciseDeviceChildId: Long? +) { + @ManyToOne(fetch = FetchType.EAGER, optional = false) + @JoinColumn(name = "exerciseDeviceParentId", nullable = false) + @JsonIgnore + val exerciseDevice: ExerciseDevice? = null + +} + + diff --git a/src/main/kotlin/com/aitrainer/api/model/ExerciseType.kt b/src/main/kotlin/com/aitrainer/api/model/ExerciseType.kt index 2a65039..97d1576 100644 --- a/src/main/kotlin/com/aitrainer/api/model/ExerciseType.kt +++ b/src/main/kotlin/com/aitrainer/api/model/ExerciseType.kt @@ -32,4 +32,12 @@ data class ExerciseType( @Fetch(value = FetchMode.SUBSELECT) val translations: List = mutableListOf() + @OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseType") + @Fetch(value = FetchMode.SUBSELECT) + val alternatives: List = mutableListOf() + + @OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseType") + @Fetch(value = FetchMode.SUBSELECT) + val parents: List = mutableListOf() + } diff --git a/src/main/kotlin/com/aitrainer/api/model/ExerciseTypeAlternative.kt b/src/main/kotlin/com/aitrainer/api/model/ExerciseTypeAlternative.kt new file mode 100644 index 0000000..2950a58 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/ExerciseTypeAlternative.kt @@ -0,0 +1,22 @@ +package com.aitrainer.api.model + +import com.fasterxml.jackson.annotation.JsonIgnore +import javax.persistence.* +import javax.validation.constraints.NotNull + +@Entity +data class ExerciseTypeAlternative ( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + var exerciseTypeAlternativeId: Long = 0, + //@get: NotNull var exerciseTypeParentId: Long?, + @get: NotNull var exerciseTypeChildId: Long? +) { + @ManyToOne(fetch = FetchType.EAGER, optional = false) + @JoinColumn(name = "exerciseTypeParentId", nullable = false) + @JsonIgnore + val exerciseType: ExerciseType? = null + +} + + diff --git a/src/main/kotlin/com/aitrainer/api/model/ExerciseTypeParents.kt b/src/main/kotlin/com/aitrainer/api/model/ExerciseTypeParents.kt new file mode 100644 index 0000000..6e7dbd1 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/ExerciseTypeParents.kt @@ -0,0 +1,22 @@ +package com.aitrainer.api.model + +import com.fasterxml.jackson.annotation.JsonIgnore +import javax.persistence.* +import javax.validation.constraints.NotNull + +@Entity +data class ExerciseTypeParents ( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + var exerciseTypeParentsId: Long = 0, + @get: NotNull var exerciseTreeId: Long? + //@get: NotNull var exerciseTypeId: Long? +) { + @ManyToOne(fetch = FetchType.EAGER, optional = false) + @JoinColumn(name = "exerciseTypeId", nullable = false) + @JsonIgnore + val exerciseType: ExerciseType? = null + +} + + diff --git a/src/main/kotlin/com/aitrainer/api/repository/ExerciseDeviceRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/ExerciseDeviceRepository.kt index 6349a56..7de526c 100644 --- a/src/main/kotlin/com/aitrainer/api/repository/ExerciseDeviceRepository.kt +++ b/src/main/kotlin/com/aitrainer/api/repository/ExerciseDeviceRepository.kt @@ -9,6 +9,7 @@ import org.springframework.stereotype.Repository interface ExerciseDeviceRepository: JpaRepository { @Query("FROM ExerciseDevice as e " + "LEFT JOIN ExerciseDeviceTranslation as t ON e.exerciseDeviceId = t.exerciseDevice AND t.languageCode = 'hu' " + + "LEFT JOIN ExerciseDeviceAlternative as t ON e.exerciseDeviceId = t.exerciseDevice " + "ORDER BY e.exerciseDeviceId ") fun getExerciseDevices(): List } \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/repository/ExerciseTypeRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/ExerciseTypeRepository.kt index a5d1446..b5a1400 100644 --- a/src/main/kotlin/com/aitrainer/api/repository/ExerciseTypeRepository.kt +++ b/src/main/kotlin/com/aitrainer/api/repository/ExerciseTypeRepository.kt @@ -17,6 +17,8 @@ interface ExerciseTypeRepository : JpaRepository{ "LEFT JOIN ExerciseTypeImage as i ON e.exerciseTypeId = i.exerciseType " + "LEFT JOIN ExerciseTypeTranslation as t ON e.exerciseTypeId = t.exerciseType " + "LEFT JOIN ExerciseTypeDevice as td ON e.exerciseTypeId = td.exerciseType " + + "LEFT JOIN ExerciseTypeAlternative as td ON e.exerciseTypeId = td.exerciseType " + + "LEFT JOIN ExerciseTypeParents as td ON e.exerciseTypeId = td.exerciseType " + "WHERE e.active = 1 " + "AND t.languageCode = 'hu' " + "AND i.type = 'menu' " + diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 41b60bb..5d06e32 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.16 +application.version=1.0.17 jwt.secret=aitrainer \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 42eee8f..2da38ad 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.16 +application.version=1.0.17 jwt.secret=aitrainer \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/ExerciseTypeTest.kt b/src/test/kotlin/com/aitrainer/api/test/ExerciseTypeTest.kt index 7ef57ab..43df48e 100644 --- a/src/test/kotlin/com/aitrainer/api/test/ExerciseTypeTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/ExerciseTypeTest.kt @@ -45,6 +45,8 @@ class ExerciseTypeTest { assertEquals(exerciseTypes[15].name, "Timed Pushups") assertEquals(exerciseTypes[15].unit, "repeat") assertEquals(exerciseTypes[15].unitQuantityUnit, "second") + assertEquals(exerciseTypes[15].alternatives.size, 0) + assertEquals(exerciseTypes[15].parents.size, 1) } @Test From 293379d6fd8777e2053de2e645de99ca9b0fdd09 Mon Sep 17 00:00:00 2001 From: Bossanyi Tibor Date: Thu, 3 Dec 2020 18:39:59 +0100 Subject: [PATCH 2/2] API 1.0.18 Tree Parents --- build.gradle.kts | 2 +- data/db/install.sql | 69 ++++++++++++++++--- data/db/update_1_0_18.sql | 11 +++ .../com/aitrainer/api/model/ExerciseTree.kt | 5 ++ .../api/model/ExerciseTreeParents.kt | 21 ++++++ .../api/repository/ExerciseTreeRepository.kt | 1 + .../resources/application-prod.properties | 2 +- src/main/resources/application.properties | 2 +- .../aitrainer/api/test/ExerciseTreeTest.kt | 1 + .../com/aitrainer/api/test/PropertiesTest.kt | 2 +- 10 files changed, 103 insertions(+), 13 deletions(-) create mode 100644 data/db/update_1_0_18.sql create mode 100644 src/main/kotlin/com/aitrainer/api/model/ExerciseTreeParents.kt 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