Merge branch 'tibor' into 'master'
API 1.0.36 description table See merge request bossanyit/aitrainer_server!56
This commit is contained in:
commit
3f737ff00c
@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.aitrainer"
|
||||
version = "1.0.35"
|
||||
version = "1.0.36"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
repositories {
|
||||
|
@ -383,6 +383,31 @@ CREATE TABLE IF NOT EXISTS `django_admin_log` (
|
||||
CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci;
|
||||
|
||||
CREATE TABLE `description` (
|
||||
`description_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` CHAR(50) NOT NULL COLLATE 'utf8_hungarian_ci',
|
||||
`description` TEXT NOT NULL COLLATE 'utf8_hungarian_ci',
|
||||
`version` INT(3) NULL DEFAULT '0',
|
||||
`valid_from` DATETIME NULL DEFAULT NULL,
|
||||
`valid_to` DATETIME NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`description_id`) USING BTREE,
|
||||
INDEX `name` (`name`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8_hungarian_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
CREATE TABLE `description_translation` (
|
||||
`translation_id` INT(13) NOT NULL AUTO_INCREMENT,
|
||||
`description_id` INT(11) NOT NULL,
|
||||
`language_code` CHAR(2) NOT NULL DEFAULT 'en' COLLATE 'utf8mb4_general_ci',
|
||||
`description_translation` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
PRIMARY KEY (`translation_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
-- Tábla adatainak mentése aitrainer2.django_admin_log: ~118 rows (hozzávetőleg)
|
||||
/*!40000 ALTER TABLE `django_admin_log` DISABLE KEYS */;
|
||||
REPLACE INTO `django_admin_log` (`id`, `action_time`, `object_id`, `object_repr`, `action_flag`, `change_message`, `content_type_id`, `user_id`) VALUES
|
||||
|
30
data/db/update_1_0_36.sql
Normal file
30
data/db/update_1_0_36.sql
Normal file
@ -0,0 +1,30 @@
|
||||
START TRANSACTION;
|
||||
|
||||
CREATE TABLE `description` (
|
||||
`description_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` CHAR(50) NOT NULL COLLATE 'utf8_hungarian_ci',
|
||||
`description` TEXT NOT NULL COLLATE 'utf8_hungarian_ci',
|
||||
`version` INT(3) NULL DEFAULT '0',
|
||||
`valid_from` DATETIME NULL DEFAULT NULL,
|
||||
`valid_to` DATETIME NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`description_id`) USING BTREE,
|
||||
INDEX `name` (`name`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8_hungarian_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
CREATE TABLE `description_translation` (
|
||||
`translation_id` INT(13) NOT NULL AUTO_INCREMENT,
|
||||
`description_id` INT(11) NOT NULL,
|
||||
`language_code` CHAR(2) NOT NULL DEFAULT 'en' COLLATE 'utf8mb4_general_ci',
|
||||
`description_translation` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
PRIMARY KEY (`translation_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
UPDATE configuration set config_value = "1.0.36", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
||||
|
||||
COMMIT;
|
@ -22,7 +22,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
private val exercisePlanTemplateRepository: ExercisePlanTemplateRepository,
|
||||
private val evaluationRepository: EvaluationRepository,
|
||||
private val sportRepository: SportRepository,
|
||||
private val tutorialRepository: TutorialRepository
|
||||
private val tutorialRepository: TutorialRepository,
|
||||
private val descriptionRepository: DescriptionRepository
|
||||
) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@ -67,6 +68,9 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
val listTutorials = tutorialRepository.findAll()
|
||||
val listTutorialJson: String = gson.toJson(listTutorials)
|
||||
|
||||
val listDescriptions = descriptionRepository.findAll()
|
||||
val listDescriptionJson: String = gson.toJson(listDescriptions)
|
||||
|
||||
val packageJson: String =
|
||||
getClassRecord(ExerciseDevice::class.simpleName, listDevicesJson) +
|
||||
"|||" + getClassRecord(Product::class.simpleName, listProductsJson) +
|
||||
@ -78,7 +82,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
"|||" + getClassRecord(ExercisePlanTemplate::class.simpleName, listPlanTemplateJson) +
|
||||
"|||" + getClassRecord(Evaluation::class.simpleName, listEvaluationJson) +
|
||||
"|||" + getClassRecord(Sport::class.simpleName, listSportsJson) +
|
||||
"|||" + getClassRecord(Tutorial::class.simpleName, listTutorialJson)
|
||||
"|||" + getClassRecord(Tutorial::class.simpleName, listTutorialJson) +
|
||||
"|||" + getClassRecord(Description::class.simpleName, listDescriptionJson)
|
||||
|
||||
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(packageJson)
|
||||
|
22
src/main/kotlin/com/aitrainer/api/model/Description.kt
Normal file
22
src/main/kotlin/com/aitrainer/api/model/Description.kt
Normal file
@ -0,0 +1,22 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.google.gson.annotations.Expose
|
||||
import org.hibernate.annotations.Fetch
|
||||
import org.hibernate.annotations.FetchMode
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
data class Description (
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var descriptionId: Long = 0,
|
||||
@Expose @get: NonNull var name: String,
|
||||
@Expose @get: NonNull var description: String,
|
||||
@Expose @get: NonNull var version: Int? = null,
|
||||
@Expose @get: NonNull var validFrom: String? = null,
|
||||
@Expose @get: NonNull var validTo: String? = null
|
||||
) {
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "mainDescription")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
@Expose val translations: List<DescriptionTranslation> = mutableListOf<DescriptionTranslation>().toList()
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.google.gson.annotations.Expose
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Entity
|
||||
data class DescriptionTranslation (
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var translationId: Long = 0,
|
||||
@Expose @get: NotBlank var languageCode: String? = "hu",
|
||||
@Expose @get: NonNull var descriptionTranslation: String? = null
|
||||
) {
|
||||
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||
@JoinColumn(name = "descriptionId", nullable = false)
|
||||
@JsonIgnore val mainDescription: Description? = null
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.Description
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface DescriptionRepository: JpaRepository<Description, Long> {
|
||||
}
|
@ -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.35
|
||||
application.version=1.0.36
|
||||
|
||||
jwt.secret=aitrainer
|
@ -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.35
|
||||
application.version=1.0.36
|
||||
|
||||
jwt.secret=aitrainer
|
@ -39,6 +39,8 @@ class AppPackageTest {
|
||||
private lateinit var sportRepository: SportRepository
|
||||
@Autowired
|
||||
private lateinit var tutorialRepository: TutorialRepository
|
||||
@Autowired
|
||||
private lateinit var descriptionRepository: DescriptionRepository
|
||||
|
||||
@Test
|
||||
fun testAppPackage() {
|
||||
@ -55,7 +57,8 @@ class AppPackageTest {
|
||||
exercisePlanTemplateRepository,
|
||||
evaluationRepository,
|
||||
sportRepository,
|
||||
tutorialRepository
|
||||
tutorialRepository,
|
||||
descriptionRepository
|
||||
)
|
||||
val response: ResponseEntity<*> = controller.getPackageData()
|
||||
|
||||
@ -68,7 +71,7 @@ class AppPackageTest {
|
||||
packages.forEach {
|
||||
val record = it.split("***")
|
||||
print(record[0] + "\n")
|
||||
if ( record[0] == ExerciseType::class.simpleName) {
|
||||
if (record[0] == ExerciseType::class.simpleName) {
|
||||
//print("List ExerciseType: " + record[1])
|
||||
val exerciseTypeJson: String = record[1]
|
||||
val type = object : TypeToken<List<ExerciseType?>?>() {}.type
|
||||
@ -128,20 +131,27 @@ class AppPackageTest {
|
||||
assertEquals(sports[2].name, "Footgolf")
|
||||
assertEquals(sports[2].translations[0].sportName, "Footgolf")
|
||||
assertEquals(sports[3].translations[0].sportName, "Tenisz")
|
||||
} else if (record[0] == Tutorial::class.simpleName) {
|
||||
print("List Tutorial: " + record[1])
|
||||
} else if (record[0] == Tutorial::class.simpleName) {
|
||||
val tutorialJson: String = record[1]
|
||||
val type = object : TypeToken<List<Tutorial?>?>() {}.type
|
||||
val tutorials: List<Tutorial> = gson.fromJson(tutorialJson, type)
|
||||
assertEquals(tutorials.size, 2)
|
||||
assertEquals(tutorials[0].name, "Basic")
|
||||
assertEquals(tutorials[0].steps.size, 9)
|
||||
assertEquals(tutorials[0].steps[2].condition, "{\"direction\":\"down\",\"top\":95,\"left\":-1,\"show_bubble\":false,\"bubble_x\":220,\"bubble_y\":220,\"bubble_width\":440,\"bubble_height\":440,\"show_check_text\":false,\"parent\":2}")
|
||||
assertEquals(
|
||||
tutorials[0].steps[2].condition,
|
||||
"{\"direction\":\"down\",\"top\":95,\"left\":-1,\"show_bubble\":false,\"bubble_x\":220,\"bubble_y\":220,\"bubble_width\":440,\"bubble_height\":440,\"show_check_text\":false,\"parent\":2}"
|
||||
)
|
||||
assertEquals(tutorials[0].steps[0].translations.size, 1)
|
||||
} else if (record[0] == Description::class.simpleName) {
|
||||
val descriptionJson: String = record[1]
|
||||
val type = object : TypeToken<List<Description?>?>() {}.type
|
||||
val descriptions: List<Description> = gson.fromJson(descriptionJson, type)
|
||||
assertEquals(descriptions.size, 2)
|
||||
assertEquals(descriptions[0].translations.size, 1)
|
||||
assertEquals(descriptions[0].name, "sales_page")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user