ExerciseTree getActiveMenu items
This commit is contained in:
parent
1334104944
commit
af32c32a70
@ -198,7 +198,7 @@ ENGINE=InnoDB
|
|||||||
;
|
;
|
||||||
|
|
||||||
CREATE TABLE `exercise_tree` (
|
CREATE TABLE `exercise_tree` (
|
||||||
`item_id` INT(11) NOT NULL AUTO_INCREMENT,
|
`tree_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
`parent_id` INT(11) NOT NULL DEFAULT '0',
|
`parent_id` INT(11) NOT NULL DEFAULT '0',
|
||||||
`name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
`name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||||
`image_url` CHAR(200) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
`image_url` CHAR(200) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
ALTER TABLE `exercise_type`
|
ALTER TABLE `exercise_type`
|
||||||
ADD COLUMN `tree_id` INT(12) DEFAULT 0 AFTER `exercise_type_id`;
|
ADD COLUMN `tree_id` INT(12) DEFAULT 0 AFTER `exercise_type_id`;
|
||||||
|
ALTER TABLE `exercise_type`
|
||||||
ADD COLUMN `active` TINYINT(1) NULL DEFAULT NULL AFTER `unit_quantity_unit`;
|
ADD COLUMN `active` TINYINT(1) NULL DEFAULT NULL AFTER `unit_quantity_unit`;
|
||||||
ALTER TABLE `exercise_type`
|
ALTER TABLE `exercise_type`
|
||||||
DROP COLUMN `video`;
|
DROP COLUMN `video`;
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.aitrainer.api.controller
|
||||||
|
|
||||||
|
import com.aitrainer.api.model.ExerciseTree
|
||||||
|
import com.aitrainer.api.repository.ExerciseTreeRepository
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api")
|
||||||
|
class ExerciseTreeController (private val exerciseTreeRepository: ExerciseTreeRepository) {
|
||||||
|
private val logger = LoggerFactory.getLogger(javaClass)
|
||||||
|
|
||||||
|
@GetMapping("/exercise_tree")
|
||||||
|
fun getAllActiveMenu(): List<ExerciseTree> {
|
||||||
|
val list: List<ExerciseTree> = exerciseTreeRepository.getActiveMenu()
|
||||||
|
logger.info(" -- Get All active Exercise Tree menu..")
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
}
|
23
src/main/kotlin/com/aitrainer/api/model/ExerciseTree.kt
Normal file
23
src/main/kotlin/com/aitrainer/api/model/ExerciseTree.kt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package com.aitrainer.api.model
|
||||||
|
|
||||||
|
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 ExerciseTree (
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
val treeId: Long = 0,
|
||||||
|
|
||||||
|
@get: NonNull var parentId: Int,
|
||||||
|
@get: NotBlank var name: String = "",
|
||||||
|
@get: NotBlank var imageUrl: String = "",
|
||||||
|
@get: NonNull var active: Boolean?,
|
||||||
|
|
||||||
|
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseTree")
|
||||||
|
@Fetch(value = FetchMode.SUBSELECT)
|
||||||
|
val translations: List<ExerciseTreeTranslation> = mutableListOf<ExerciseTreeTranslation>().toList()
|
||||||
|
)
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.aitrainer.api.model
|
||||||
|
|
||||||
|
import javax.persistence.*
|
||||||
|
import javax.validation.constraints.NotBlank
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
data class ExerciseTreeTranslation (
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
val translationId: Long = 0,
|
||||||
|
|
||||||
|
@get: NotBlank var languageCode: String?,
|
||||||
|
@get: NotBlank var name: String = "",
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||||
|
@JoinColumn(name = "treeId", nullable = false)
|
||||||
|
val exerciseTree: ExerciseTree? = null
|
||||||
|
|
||||||
|
)
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.aitrainer.api.repository
|
||||||
|
|
||||||
|
import com.aitrainer.api.model.ExerciseTree
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
import org.springframework.data.jpa.repository.Query
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
interface ExerciseTreeRepository : JpaRepository<ExerciseTree, Long> {
|
||||||
|
|
||||||
|
@Query("FROM ExerciseTree as e " +
|
||||||
|
"LEFT JOIN ExerciseTreeTranslation as t ON e.treeId = t.exerciseTree AND t.languageCode = 'hu' " +
|
||||||
|
"WHERE e.active = 1 " +
|
||||||
|
"ORDER BY e.treeId ")
|
||||||
|
fun getActiveMenu(): List<ExerciseTree>
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
spring.profiles.active=prod
|
spring.profiles.active=prod
|
||||||
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
|
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
|
||||||
spring.datasource.url = jdbc:mysql://localhost:3306/aitrainer2?serverTimezone=CET&useSSL=false&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&allowMultiQueries=true
|
spring.datasource.url = jdbc:mysql://localhost:3306/aitrainer?serverTimezone=CET&useSSL=false&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&allowMultiQueries=true
|
||||||
spring.datasource.username = aitrainer
|
spring.datasource.username = aitrainer
|
||||||
spring.datasource.password = andio2009
|
spring.datasource.password = andio2009
|
||||||
|
|
||||||
@ -9,4 +9,13 @@ spring.datasource.password = andio2009
|
|||||||
|
|
||||||
|
|
||||||
# The SQL dialect makes Hibernate generate better SQL for the chosen database
|
# The SQL dialect makes Hibernate generate better SQL for the chosen database
|
||||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
|
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
|
||||||
|
|
||||||
|
|
||||||
|
logging.config=classpath:logback-spring.xml
|
||||||
|
logging.file=logs
|
||||||
|
|
||||||
|
# if the database structure has been changed, increment this version number
|
||||||
|
application.version=1.0.5
|
||||||
|
|
||||||
|
jwt.secret=aitrainer
|
29
src/test/kotlin/com/aitrainer/api/test/ExerciseTreeTest.kt
Normal file
29
src/test/kotlin/com/aitrainer/api/test/ExerciseTreeTest.kt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.aitrainer.api.test
|
||||||
|
|
||||||
|
|
||||||
|
import com.aitrainer.api.controller.ExerciseTreeController
|
||||||
|
import com.aitrainer.api.repository.ExerciseTreeRepository
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class ExerciseTreeTest {
|
||||||
|
private val logger = LoggerFactory.getLogger(javaClass)
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var exerciseTreeRepository: ExerciseTreeRepository
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testActiveExercises() {
|
||||||
|
val exerciseTreeController = ExerciseTreeController(exerciseTreeRepository)
|
||||||
|
val exerciseTree = exerciseTreeController.getAllActiveMenu()
|
||||||
|
|
||||||
|
val exerciseTreeItem = exerciseTree[0]
|
||||||
|
assertEquals(exerciseTreeItem.name, "Cardio")
|
||||||
|
assertEquals(exerciseTree[1].translations[0].name, "Erő")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user