ExerciseType extension with Images and Translations
DB 1.0.5
This commit is contained in:
@@ -39,10 +39,17 @@ class ExerciseTypeController ( private val exerciseTypeRepository: ExerciseTypeR
|
||||
/*
|
||||
@GetMapping("/exercise_type/name/{name}")
|
||||
fun getExerciseTypeByName(@PathVariable(value = "name") name: String): ResponseEntity<ExerciseType> {
|
||||
return exerciseTypeRepository.findByName(name).map { exerciseType ->
|
||||
return exerciseTypeRepository.findByName(name).map { exerciseType ->
|
||||
ResponseEntity.ok(exerciseType)
|
||||
}.orElse(ResponseEntity.notFound().build())
|
||||
}*/
|
||||
}*/
|
||||
|
||||
@GetMapping("exercise_type/active")
|
||||
fun getActiveExerciseType(): List<ExerciseType> {
|
||||
val list: List<ExerciseType> = exerciseTypeRepository.getActiveExerciseTypes()
|
||||
logger.info("-- Get Active Exercise Types with Images and Translation -- ")
|
||||
return list
|
||||
}
|
||||
|
||||
@PostMapping("/exercise_type/{id}")
|
||||
fun updateExerciseTypesById(@PathVariable(value = "id") exerciseTypeId: Long,
|
||||
@@ -52,7 +59,7 @@ class ExerciseTypeController ( private val exerciseTypeRepository: ExerciseTypeR
|
||||
val updatedExerciseType: ExerciseType = existingExerciseType
|
||||
.copy(name = newExerciseType.name,
|
||||
description = newExerciseType.description,
|
||||
video = newExerciseType.video)
|
||||
treeId = newExerciseType.treeId)
|
||||
ResponseEntity.ok().body(exerciseTypeRepository.save(updatedExerciseType))
|
||||
}.orElse(ResponseEntity.notFound().build())
|
||||
|
||||
|
||||
@@ -1,24 +1,32 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import org.hibernate.type.BinaryType
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.GenerationType
|
||||
import javax.persistence.Id
|
||||
import org.hibernate.annotations.FetchMode
|
||||
import org.hibernate.annotations.Fetch
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotBlank
|
||||
import javax.validation.constraints.Null
|
||||
|
||||
@Entity
|
||||
data class ExerciseType (
|
||||
|
||||
@get: NotBlank var name: String = "",
|
||||
data class ExerciseType(
|
||||
@get: NonNull var treeId: Int,
|
||||
@get: NotBlank var name: String = "",
|
||||
@get: NotBlank var description: String = "",
|
||||
@get: Null var video: BinaryType?,
|
||||
@get: Null var unit: String?,
|
||||
@get: Null var unitQuantity: String?,
|
||||
@get: Null var unitQuantityUnit: String?,
|
||||
@get: NonNull var active: Boolean?,
|
||||
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val exerciseTypeId: Long = 0
|
||||
val exerciseTypeId: Long = 0,
|
||||
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseType")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
val images: List<ExerciseTypeImage> = mutableListOf<ExerciseTypeImage>().toList(),
|
||||
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "exerciseType")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
val translations: List<ExerciseTypeTranslation> = mutableListOf<ExerciseTypeTranslation>().toList()
|
||||
|
||||
)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Entity
|
||||
data class ExerciseTypeImage (
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val imageId: Long = 0,
|
||||
|
||||
//@get: NonNull var exerciseTypeId: Integer?,
|
||||
@get: NotBlank var name: String = "",
|
||||
@get: NotBlank var type: String = "",
|
||||
@get: NotBlank var url: String = ""
|
||||
|
||||
) {
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||
@JoinColumn(name="exerciseTypeId", nullable=false)
|
||||
val exerciseType: ExerciseType? = null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Entity
|
||||
data class ExerciseTypeTranslation (
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val translationId: Long = 0,
|
||||
|
||||
//@get: NonNull var exerciseTypeId: Integer?,
|
||||
@get: NotBlank var languageCode: String?,
|
||||
@get: NotBlank var name: String = "",
|
||||
@get: NotBlank var description: String = ""
|
||||
) {
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||
@JoinColumn(name = "exerciseTypeId", nullable = false)
|
||||
val exerciseType: ExerciseType? = null
|
||||
}
|
||||
@@ -1,12 +1,25 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.ExerciseType
|
||||
import com.aitrainer.api.model.Exercises
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.query.Param
|
||||
import org.springframework.stereotype.Repository
|
||||
import javax.persistence.NamedQuery
|
||||
|
||||
@Repository
|
||||
interface ExerciseTypeRepository : JpaRepository<ExerciseType, Long>{
|
||||
|
||||
fun findByName(name: String): ExerciseType
|
||||
|
||||
@Query("FROM ExerciseType as e " +
|
||||
"LEFT JOIN ExerciseTypeImage as i ON e.exerciseTypeId = i.exerciseType " +
|
||||
"LEFT JOIN ExerciseTypeTranslation as t ON e.exerciseTypeId = t.exerciseType " +
|
||||
"WHERE e.active = 1 " +
|
||||
"AND t.languageCode = 'hu' " +
|
||||
"AND i.type = 'menu' " +
|
||||
"ORDER BY e.exerciseTypeId ")
|
||||
fun getActiveExerciseTypes(): List<ExerciseType>
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user