ExerciseTree getActiveMenu items
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
}
|
||||
Reference in New Issue
Block a user