From 03b3766459a2ec927d611c6c8decbc91a1a267df Mon Sep 17 00:00:00 2001
From: Bossanyi Tibor <sw@andio.biz>
Date: Tue, 27 Apr 2021 08:19:05 +0200
Subject: [PATCH] API 1.0.34 tutorials action

---
 build.gradle.kts                                    |  2 +-
 data/db/install.sql                                 |  1 +
 data/db/update_1_0_34.sql                           | 13 +++++++++++++
 .../kotlin/com/aitrainer/api/model/TutorialSteps.kt |  3 ++-
 src/main/resources/application-prod.properties      |  2 +-
 src/main/resources/application.properties           |  2 +-
 .../kotlin/com/aitrainer/api/test/AppPackageTest.kt |  6 ++++--
 7 files changed, 23 insertions(+), 6 deletions(-)
 create mode 100644 data/db/update_1_0_34.sql

diff --git a/build.gradle.kts b/build.gradle.kts
index d26e696..f180c3e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -11,7 +11,7 @@ plugins {
 }
 
 group = "com.aitrainer"
-version = "1.0.33"
+version = "1.0.34"
 java.sourceCompatibility = JavaVersion.VERSION_1_8
 
 repositories {
diff --git a/data/db/install.sql b/data/db/install.sql
index 36fcf9a..ee4f7c7 100644
--- a/data/db/install.sql
+++ b/data/db/install.sql
@@ -1398,6 +1398,7 @@ CREATE TABLE `tutorial_steps` (
 	`check_text` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
 	`condition` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
 	`parent` INT(3) NOT NULL DEFAULT '0',
+	`action` TINYINT NULL DEFAULT '0',
 	PRIMARY KEY (`tutorial_step_id`) USING BTREE,
 	INDEX `tutorial_id` (`tutorial_id`) USING BTREE,
 	INDEX `parent` (`parent`) USING BTREE
diff --git a/data/db/update_1_0_34.sql b/data/db/update_1_0_34.sql
new file mode 100644
index 0000000..f66ce6a
--- /dev/null
+++ b/data/db/update_1_0_34.sql
@@ -0,0 +1,13 @@
+START TRANSACTION;
+
+ALTER TABLE `tutorial_steps`
+	CHANGE COLUMN `parent` `parent_id` INT(3) NOT NULL DEFAULT '0' AFTER `condition`;
+
+ALTER TABLE `tutorial_steps`
+    ADD COLUMN `action` TINYINT NULL DEFAULT '0' AFTER `parent_id`;
+
+
+UPDATE configuration set config_value = "1.0.34", date_change=CURRENT_DATE WHERE config_key = "db_version";
+
+COMMIT;
+
diff --git a/src/main/kotlin/com/aitrainer/api/model/TutorialSteps.kt b/src/main/kotlin/com/aitrainer/api/model/TutorialSteps.kt
index 8d32f04..c0102a8 100644
--- a/src/main/kotlin/com/aitrainer/api/model/TutorialSteps.kt
+++ b/src/main/kotlin/com/aitrainer/api/model/TutorialSteps.kt
@@ -16,7 +16,8 @@ data class TutorialSteps (
     @Expose var errorText: String? = null,
     @Expose var checkText: String? = null,
     @Expose var condition: String? = null,
-    @Expose @get: NotBlank var parent: Int = 0,
+    @Expose @get: NotBlank var parent_id: Int = 0,
+    @Expose var action: Int? = 0,
 ) {
 
     @ManyToOne(fetch = FetchType.LAZY, optional = false)
diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties
index 99d67e8..3de676b 100644
--- a/src/main/resources/application-prod.properties
+++ b/src/main/resources/application-prod.properties
@@ -17,6 +17,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.33
+application.version=1.0.34
 
 jwt.secret=aitrainer
\ No newline at end of file
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index cbec6ca..f85dc26 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -17,6 +17,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.33
+application.version=1.0.34
 
 jwt.secret=aitrainer
\ No newline at end of file
diff --git a/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt b/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt
index 24822be..4cab99f 100644
--- a/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt
+++ b/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt
@@ -135,9 +135,11 @@ class AppPackageTest {
                 val tutorials: List<Tutorial> = gson.fromJson(tutorialJson, type)
                 assertEquals(tutorials.size, 1)
                 assertEquals(tutorials[0].name, "Basic")
-                assertEquals(tutorials[0].steps.size, 4)
-                assertEquals(tutorials[0].steps[3].parent, 2)
+                assertEquals(tutorials[0].steps.size, 5)
+                assertEquals(tutorials[0].steps[3].parent_id, 2)
                 assertEquals(tutorials[0].steps[3].condition, "Check2")
+                assertEquals(tutorials[0].steps[3].action, 0)
+                assertEquals(tutorials[0].steps[4].action, 1)
                 assertEquals(tutorials[0].steps[0].translations.size, 2)
             }
         }