Merge branch 'tibor' into 'master'

API 1.0.32 tutorials

See merge request bossanyit/aitrainer_server!50
This commit is contained in:
Bossányi Tibor 2021-04-24 12:49:14 +00:00
commit e7a7538b9d
11 changed files with 191 additions and 8 deletions

View File

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

View File

@ -1377,6 +1377,47 @@ INSERT INTO `sport_translation` (`translation_id`, `language_code`, `sport_id`,
/*!40000 ALTER TABLE `tracking` DISABLE KEYS */; /*!40000 ALTER TABLE `tracking` DISABLE KEYS */;
/*!40000 ALTER TABLE `tracking` ENABLE KEYS */; /*!40000 ALTER TABLE `tracking` ENABLE KEYS */;
CREATE TABLE `tutorial` (
`tutorial_id` INT(11) NOT NULL AUTO_INCREMENT,
`name` CHAR(50) NOT NULL COLLATE 'utf8_hungarian_ci',
PRIMARY KEY (`tutorial_id`) USING BTREE
)
COLLATE='utf8_hungarian_ci'
ENGINE=InnoDB
;
CREATE TABLE `tutorial_steps` (
`tutorial_step_id` INT(11) NOT NULL AUTO_INCREMENT,
`tutorial_id` INT(11) NOT NULL DEFAULT '0',
`step` INT(3) NOT NULL DEFAULT '0',
`tutorial_text` TEXT NOT NULL COLLATE 'utf8_hungarian_ci',
`error_text` TEXT NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
`check_text` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
PRIMARY KEY (`tutorial_step_id`) USING BTREE,
INDEX `tutorial_id` (`tutorial_id`) USING BTREE
)
COLLATE='utf8_hungarian_ci'
ENGINE=InnoDB
;
CREATE TABLE `tutorial_translation` (
`translation_id` INT(13) NOT NULL AUTO_INCREMENT,
`language_code` CHAR(2) NOT NULL DEFAULT 'en' COLLATE 'utf8mb4_general_ci',
`tutorial_step_id` INT(13) NOT NULL DEFAULT '0',
`tutorial_text` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
`error_text` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
`check_text` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
PRIMARY KEY (`translation_id`) USING BTREE,
INDEX `tutorial_step_id` (`tutorial_step_id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */; /*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

45
data/db/update_1_0_32.sql Normal file
View File

@ -0,0 +1,45 @@
START TRANSACTION;
CREATE TABLE `tutorial` (
`tutorial_id` INT(11) NOT NULL AUTO_INCREMENT,
`name` CHAR(50) NOT NULL COLLATE 'utf8_hungarian_ci',
PRIMARY KEY (`tutorial_id`) USING BTREE
)
COLLATE='utf8_hungarian_ci'
ENGINE=InnoDB
;
CREATE TABLE `tutorial_steps` (
`tutorial_step_id` INT(11) NOT NULL AUTO_INCREMENT,
`tutorial_id` INT(11) NOT NULL DEFAULT '0',
`step` INT(3) NOT NULL DEFAULT '0',
`tutorial_text` TEXT NOT NULL COLLATE 'utf8_hungarian_ci',
`error_text` TEXT NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
`check_text` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
PRIMARY KEY (`tutorial_step_id`) USING BTREE,
INDEX `tutorial_id` (`tutorial_id`) USING BTREE
)
COLLATE='utf8_hungarian_ci'
ENGINE=InnoDB
;
CREATE TABLE `tutorial_translation` (
`translation_id` INT(13) NOT NULL AUTO_INCREMENT,
`language_code` CHAR(2) NOT NULL DEFAULT 'en' COLLATE 'utf8mb4_general_ci',
`tutorial_step_id` INT(13) NOT NULL DEFAULT '0',
`tutorial_text` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
`error_text` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
`check_text` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
PRIMARY KEY (`translation_id`) USING BTREE,
INDEX `tutorial_step_id` (`tutorial_step_id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;
UPDATE configuration set config_value = "1.0.32", date_change=CURRENT_DATE WHERE config_key = "db_version";
COMMIT;

View File

@ -21,7 +21,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
private val exerciseTreeParentsRepository: ExerciseTreeParentsRepository, private val exerciseTreeParentsRepository: ExerciseTreeParentsRepository,
private val exercisePlanTemplateRepository: ExercisePlanTemplateRepository, private val exercisePlanTemplateRepository: ExercisePlanTemplateRepository,
private val evaluationRepository: EvaluationRepository, private val evaluationRepository: EvaluationRepository,
private val sportRepository: SportRepository private val sportRepository: SportRepository,
private val tutorialRepository: TutorialRepository
) { ) {
private val logger = LoggerFactory.getLogger(javaClass) private val logger = LoggerFactory.getLogger(javaClass)
@ -61,7 +62,10 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
val listEvaluationJson: String = gson.toJson(listEvaluations) val listEvaluationJson: String = gson.toJson(listEvaluations)
val listSports = sportRepository.getSports() val listSports = sportRepository.getSports()
val listSportsJson: String = gson.toJson((listSports)) val listSportsJson: String = gson.toJson(listSports)
val listTutorials = tutorialRepository.findAll()
val listTutorialJson: String = gson.toJson(listTutorials)
val packageJson: String = val packageJson: String =
getClassRecord(ExerciseDevice::class.simpleName, listDevicesJson) + getClassRecord(ExerciseDevice::class.simpleName, listDevicesJson) +
@ -73,7 +77,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
"|||" + getClassRecord(ExerciseTreeParents::class.simpleName, listExerciseTreeParentsJson) + "|||" + getClassRecord(ExerciseTreeParents::class.simpleName, listExerciseTreeParentsJson) +
"|||" + getClassRecord(ExercisePlanTemplate::class.simpleName, listPlanTemplateJson) + "|||" + getClassRecord(ExercisePlanTemplate::class.simpleName, listPlanTemplateJson) +
"|||" + getClassRecord(Evaluation::class.simpleName, listEvaluationJson) + "|||" + getClassRecord(Evaluation::class.simpleName, listEvaluationJson) +
"|||" + getClassRecord(Sport::class.simpleName, listSportsJson) "|||" + getClassRecord(Sport::class.simpleName, listSportsJson) +
"|||" + getClassRecord(Tutorial::class.simpleName, listTutorialJson)
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
ResponseEntity.ok().body(packageJson) ResponseEntity.ok().body(packageJson)

View File

@ -0,0 +1,20 @@
package com.aitrainer.api.model
import com.google.gson.annotations.Expose
import kotlinx.serialization.Serializable
import org.hibernate.annotations.Fetch
import org.hibernate.annotations.FetchMode
import org.springframework.lang.NonNull
import javax.persistence.*
import javax.validation.constraints.NotBlank
@Entity
data class Tutorial (
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var tutorialId: Long = 0,
@Expose @get: NotBlank var name: String = "",
) {
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "tutorial")
@Fetch(value = FetchMode.SUBSELECT)
@Expose val steps: List<TutorialSteps> = mutableListOf<TutorialSteps>().toList()
}

View File

@ -0,0 +1,30 @@
package com.aitrainer.api.model
import com.fasterxml.jackson.annotation.JsonIgnore
import com.google.gson.annotations.Expose
import org.hibernate.annotations.Fetch
import org.hibernate.annotations.FetchMode
import org.springframework.lang.NonNull
import javax.persistence.*
import javax.validation.constraints.NotBlank
@Entity
data class TutorialSteps (
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var tutorialStepId: Long = 0,
@Expose @get: NotBlank var tutorialText: String = "",
@Expose @get: NotBlank var step: Int = 0,
@Expose var errorText: String? = null,
@Expose var checkText: String? = null,
) {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "tutorialId", nullable = false)
@JsonIgnore
val tutorial: Tutorial? = null
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "tutorialSteps")
@Fetch(value = FetchMode.SUBSELECT)
@Expose val translations: List<TutorialTranslation> = mutableListOf<TutorialTranslation>().toList()
}

View File

@ -0,0 +1,21 @@
package com.aitrainer.api.model
import com.fasterxml.jackson.annotation.JsonIgnore
import com.google.gson.annotations.Expose
import javax.persistence.*
import javax.validation.constraints.NotBlank
@Entity
data class TutorialTranslation (
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val translationId: Long = 0,
@Expose @get: NotBlank var languageCode: String?,
@Expose @get: NotBlank var tutorialText: String = "",
@Expose var errorText: String? = null,
) {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "tutorialStepId", nullable = false)
@JsonIgnore
val tutorialSteps: TutorialSteps? = null
}

View File

@ -0,0 +1,9 @@
package com.aitrainer.api.repository
import com.aitrainer.api.model.Tutorial
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface TutorialRepository: JpaRepository<Tutorial, Long> {
}

View File

@ -17,6 +17,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.31 application.version=1.0.32
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -17,6 +17,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.31 application.version=1.0.32
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -37,6 +37,8 @@ class AppPackageTest {
private lateinit var evaluationRepository: EvaluationRepository private lateinit var evaluationRepository: EvaluationRepository
@Autowired @Autowired
private lateinit var sportRepository: SportRepository private lateinit var sportRepository: SportRepository
@Autowired
private lateinit var tutorialRepository: TutorialRepository
@Test @Test
fun testAppPackage() { fun testAppPackage() {
@ -52,7 +54,8 @@ class AppPackageTest {
exerciseTreeParentsRepository, exerciseTreeParentsRepository,
exercisePlanTemplateRepository, exercisePlanTemplateRepository,
evaluationRepository, evaluationRepository,
sportRepository sportRepository,
tutorialRepository
) )
val response: ResponseEntity<*> = controller.getPackageData() val response: ResponseEntity<*> = controller.getPackageData()
@ -66,7 +69,7 @@ class AppPackageTest {
val record = it.split("***") val record = it.split("***")
print(record[0] + "\n") print(record[0] + "\n")
if ( record[0] == ExerciseType::class.simpleName) { if ( record[0] == ExerciseType::class.simpleName) {
print("List ExerciseType: " + record[1]) //print("List ExerciseType: " + record[1])
val exerciseTypeJson: String = record[1] val exerciseTypeJson: String = record[1]
val type = object : TypeToken<List<ExerciseType?>?>() {}.type val type = object : TypeToken<List<ExerciseType?>?>() {}.type
val listExerciseType: List<ExerciseType> = gson.fromJson(exerciseTypeJson, type) val listExerciseType: List<ExerciseType> = gson.fromJson(exerciseTypeJson, type)
@ -125,6 +128,15 @@ class AppPackageTest {
assertEquals(sports[2].name, "Footgolf") assertEquals(sports[2].name, "Footgolf")
assertEquals(sports[2].translations[0].sportName, "Footgolf") assertEquals(sports[2].translations[0].sportName, "Footgolf")
assertEquals(sports[3].translations[0].sportName, "Tenisz") assertEquals(sports[3].translations[0].sportName, "Tenisz")
} else if (record[0] == Tutorial::class.simpleName) {
print("List Tutorial: " + record[1])
val tutorialJson: String = record[1]
val type = object : TypeToken<List<Tutorial?>?>() {}.type
val tutorials: List<Tutorial> = gson.fromJson(tutorialJson, type)
assertEquals(tutorials.size, 1)
assertEquals(tutorials[0].name, "Basic")
assertEquals(tutorials[0].steps.size, 2)
assertEquals(tutorials[0].steps[0].translations.size, 2)
} }
} }