Merge branch 'tibor' into 'master'

API 1.0.50 AppText Translations

See merge request bossanyit/aitrainer_server!73
This commit is contained in:
Bossányi Tibor 2021-09-08 14:40:39 +00:00
commit ff716146ea
10 changed files with 96 additions and 7 deletions

View File

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

View File

@ -2,7 +2,7 @@ START TRANSACTION;
ALTER TABLE `customer`
ADD COLUMN `firebase_reg_token` CHAR(100) NULL DEFAULT NULL AFTER `trial_date`;
ADD COLUMN `firebase_reg_token` CHAR(255) NULL DEFAULT NULL AFTER `trial_date`;
UPDATE configuration set config_value = "1.0.49", date_change=CURRENT_DATE WHERE config_key = "db_version";

27
data/db/update_1_0_50.sql Normal file
View File

@ -0,0 +1,27 @@
START TRANSACTION;
CREATE TABLE `app_text` (
`text_id` INT(13) NOT NULL AUTO_INCREMENT,
`text_key` MEDIUMTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
`screenshot_url` CHAR(200) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
`checked` TINYINT(1) NULL DEFAULT '0',
PRIMARY KEY (`text_id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;
CREATE TABLE `app_text_translation` (
`translation_id` INT(13) NOT NULL AUTO_INCREMENT,
`text_id` INT(11) NOT NULL,
`language_code` CHAR(2) NOT NULL DEFAULT 'en' COLLATE 'utf8mb4_general_ci',
`text` CHAR(50) 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.50", date_change=CURRENT_DATE WHERE config_key = "db_version";
COMMIT;

View File

@ -27,7 +27,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
private val faqRepository: FaqRepository,
private val trainingPlanRepository: TrainingPlanRepository,
private val splitTestsRepository: SplitTestsRepository,
private val trainingPlanDayRepository: TrainingPlanDayRepository
private val trainingPlanDayRepository: TrainingPlanDayRepository,
private val appTextRepository: AppTextRepository
) {
private val logger = LoggerFactory.getLogger(javaClass)
@ -87,6 +88,9 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
val listTrainingPlanDay = trainingPlanDayRepository.findAll()
val listTrainingPlanDayJson = gson.toJson(listTrainingPlanDay)
val listAppText = appTextRepository.findAll()
val listAppTextJson = gson.toJson(listAppText)
val packageJson: String =
getClassRecord(ExerciseDevice::class.simpleName, listDevicesJson) +
"|||" + getClassRecord(Product::class.simpleName, listProductsJson) +
@ -103,7 +107,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
"|||" + getClassRecord(Faq::class.simpleName, listFaqJson) +
"|||" + getClassRecord(TrainingPlan::class.simpleName, listTrainingPlanJson) +
"|||" + getClassRecord(SplitTests::class.simpleName, listSplitTestsJson) +
"|||" + getClassRecord(TrainingPlanDay::class.simpleName, listTrainingPlanDayJson)
"|||" + getClassRecord(TrainingPlanDay::class.simpleName, listTrainingPlanDayJson) +
"|||" + getClassRecord(AppText::class.simpleName, listAppTextJson)
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
ResponseEntity.ok().body(packageJson)

View File

@ -0,0 +1,20 @@
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 AppText (
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var textId: Long = 0,
@Expose @get: NonNull var textKey: String,
@Expose @get: NonNull var screenshotUrl: String,
@Expose @get: NonNull var checked: Boolean? = null,
) {
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "appText")
@Fetch(value = FetchMode.SUBSELECT)
@Expose val translations: List<AppTextTranslation> = mutableListOf<AppTextTranslation>().toList()
}

View File

@ -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 AppTextTranslation (
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var translationId: Long = 0,
@Expose @get: NotBlank var languageCode: String? = "hu",
@Expose @get: NonNull var text: String? = null
) {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "textId", nullable = false)
@JsonIgnore val appText: AppText? = null
}

View File

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

View File

@ -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.49
application.version=1.0.50
jwt.secret=aitrainer

View File

@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs
# if the database structure has been changed, increment this version number
application.version=1.0.49
application.version=1.0.50
jwt.secret=aitrainer
jasypt.encryptor.password=Tibor

View File

@ -49,6 +49,8 @@ class AppPackageTest {
private lateinit var splitTestsRepository: SplitTestsRepository
@Autowired
private lateinit var trainingPlanDayRepository: TrainingPlanDayRepository
@Autowired
private lateinit var appTextRepository: AppTextRepository
@Test
fun testAppPackage() {
@ -70,7 +72,8 @@ class AppPackageTest {
faqRepository,
trainingPlanRepository,
splitTestsRepository,
trainingPlanDayRepository
trainingPlanDayRepository,
appTextRepository
)
val response: ResponseEntity<*> = controller.getPackageData()
@ -201,6 +204,13 @@ class AppPackageTest {
assertEquals(days.size,3)
assertEquals(days[0].name, "Mo")
assertEquals(days[0].translations[0].nameTranslation, "H")
} else if (record[0] == AppText::class.simpleName) {
val appTextJson: String = record[1]
val type = object : TypeToken<List<AppText?>?>() {}.type
val texts: List<AppText> = gson.fromJson(appTextJson, type)
assertEquals(texts.size, 1)
assertEquals(texts[0].translations[0].text, "Done!")
assertEquals(texts[0].translations[1].text, "Kész!")
}
}
}