API 1.0.31 sports
This commit is contained in:
@@ -111,6 +111,12 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
if (newCustomer.dataPolicyAllowed != null) {
|
||||
updatedCustomer.dataPolicyAllowed = newCustomer.dataPolicyAllowed
|
||||
}
|
||||
if (newCustomer.sportId != null) {
|
||||
updatedCustomer.sportId = newCustomer.sportId
|
||||
}
|
||||
if (newCustomer.emailSubscription != null) {
|
||||
updatedCustomer.emailSubscription = newCustomer.emailSubscription
|
||||
}
|
||||
updatedCustomer.sex = newCustomer.sex
|
||||
updatedCustomer.birthYear = newCustomer.birthYear
|
||||
updatedCustomer.fitnessLevel = newCustomer.fitnessLevel
|
||||
|
||||
@@ -20,7 +20,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
private val exerciseDeviceRepository: ExerciseDeviceRepository,
|
||||
private val exerciseTreeParentsRepository: ExerciseTreeParentsRepository,
|
||||
private val exercisePlanTemplateRepository: ExercisePlanTemplateRepository,
|
||||
private val evaluationRepository: EvaluationRepository
|
||||
private val evaluationRepository: EvaluationRepository,
|
||||
private val sportRepository: SportRepository
|
||||
) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@@ -59,6 +60,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
val listEvaluations = evaluationRepository.findAll()
|
||||
val listEvaluationJson: String = gson.toJson(listEvaluations)
|
||||
|
||||
val listSports = sportRepository.getSports()
|
||||
val listSportsJson: String = gson.toJson((listSports))
|
||||
|
||||
val packageJson: String =
|
||||
getClassRecord(ExerciseDevice::class.simpleName, listDevicesJson) +
|
||||
@@ -69,7 +72,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe
|
||||
"|||" + getClassRecord(ExerciseAbility::class.simpleName, listExerciseAbilityJson) +
|
||||
"|||" + getClassRecord(ExerciseTreeParents::class.simpleName, listExerciseTreeParentsJson) +
|
||||
"|||" + getClassRecord(ExercisePlanTemplate::class.simpleName, listPlanTemplateJson) +
|
||||
"|||" + getClassRecord(Evaluation::class.simpleName, listEvaluationJson)
|
||||
"|||" + getClassRecord(Evaluation::class.simpleName, listEvaluationJson) +
|
||||
"|||" + getClassRecord(Sport::class.simpleName, listSportsJson)
|
||||
|
||||
return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(packageJson)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.Sport
|
||||
import com.aitrainer.api.repository.SportRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
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 SportController(private val sportRepository: SportRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/sports")
|
||||
fun getSportsWithTranslation(): ResponseEntity<List<Sport>> {
|
||||
val list = sportRepository.getSports()
|
||||
|
||||
logger.info(" -- Get All sports $list")
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ data class Customer (
|
||||
@Expose var fitnessLevel: String = "beginner",
|
||||
@Expose var bodyType: String? = null,
|
||||
@Expose var firebaseUid: String? = null,
|
||||
@Expose var sportId: Int? = null,
|
||||
@Expose var emailSubscription: Int? = 0,
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose var customerId: Long = 0
|
||||
)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
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 Sport (
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var sportId: Long = 0,
|
||||
@Expose @get: NonNull var name: String = "",
|
||||
) {
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "sport")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
@Expose val translations: List<SportTranslation> = mutableListOf<SportTranslation>().toList()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.google.gson.annotations.Expose
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Entity
|
||||
data class SportTranslation (
|
||||
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val translationId: Long = 0,
|
||||
|
||||
@Expose @get: NotBlank var languageCode: String?,
|
||||
@Expose @get: NotBlank var sportName: String = "",
|
||||
|
||||
) {
|
||||
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||
@JoinColumn(name = "sportId", nullable = false)
|
||||
@JsonIgnore
|
||||
val sport: Sport? = null
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.Sport
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface SportRepository: JpaRepository<Sport, Long> {
|
||||
@Query("FROM Sport as e " +
|
||||
"LEFT JOIN SportTranslation as t ON e.sportId = t.sport AND t.languageCode = 'hu' "+
|
||||
"ORDER BY name")
|
||||
fun getSports(): List<Sport>
|
||||
}
|
||||
@@ -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.30
|
||||
application.version=1.0.31
|
||||
|
||||
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.30
|
||||
application.version=1.0.31
|
||||
|
||||
jwt.secret=aitrainer
|
||||
Reference in New Issue
Block a user