API 1.0.41 customer_training_plan details, exercises

This commit is contained in:
Bossanyi Tibor
2021-05-20 15:02:48 +02:00
parent aeb62acaa3
commit d02f6bd1f7
16 changed files with 203 additions and 17 deletions
@@ -19,7 +19,7 @@ class CustomerPackageController( private val customerRepository: CustomerReposit
private val customerPropertyRepository: CustomerPropertyRepository,
private val exerciseResultRepository: ExerciseResultRepository,
private val customerActivityRepository: CustomerActivityRepository,
private val customerTrainingPlanRepository: CustomerTrainingPlanRepository
private val customerTrainingPlanRepository: CustomerTrainingPlanRepository,
) {
@GetMapping("/app_customer_package/{id}")
@@ -1,8 +1,7 @@
package com.aitrainer.api.controller
import com.aitrainer.api.model.CustomerProperty
import com.aitrainer.api.model.CustomerTrainingPlan
import com.aitrainer.api.repository.CustomerPropertyRepository
import com.aitrainer.api.model.CustomerTrainingPlanExercise
import com.aitrainer.api.repository.CustomerTrainingPlanRepository
import org.slf4j.LoggerFactory
import org.springframework.http.ResponseEntity
@@ -17,7 +16,7 @@ class CustomerTrainingPlanController(private val customerTrainingPlanRepository:
@PostMapping("/customer_training_plan")
fun createNewCustomerTrainingPlan(@Valid @RequestBody customerTrainingPlan: CustomerTrainingPlan): ResponseEntity<CustomerTrainingPlan> {
logger.info("Create customer property: $customerTrainingPlan")
logger.info("Create customer training plan: $customerTrainingPlan")
return ResponseEntity.ok().body(customerTrainingPlanRepository.save(customerTrainingPlan))
}
@@ -0,0 +1,31 @@
package com.aitrainer.api.controller
import com.aitrainer.api.model.CustomerTrainingPlanExercise
import com.aitrainer.api.repository.CustomerTrainingPlanExerciseRepository
import org.slf4j.LoggerFactory
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import javax.validation.Valid
@RestController
@RequestMapping("/api")
class CustomerTrainingPlanExerciseController(private val customerTrainingPlanExerciseRepository: CustomerTrainingPlanExerciseRepository) {
private val logger = LoggerFactory.getLogger(javaClass)
@PostMapping("/customer_training_plan_exercise")
fun createNewCustomerTrainingPlanExercise(@Valid @RequestBody customerTrainingPlanExercise: CustomerTrainingPlanExercise): ResponseEntity<CustomerTrainingPlanExercise> {
logger.info("Create customer property: $customerTrainingPlanExercise")
return ResponseEntity.ok().body(customerTrainingPlanExerciseRepository.save(customerTrainingPlanExercise))
}
@GetMapping("/customer_training_plan_exercise/{id}")
fun getAllByCustomerId(@PathVariable(value = "id") customerId: Long): ResponseEntity<List<CustomerTrainingPlanExercise>> {
val exerciseList: List<CustomerTrainingPlanExercise> = customerTrainingPlanExerciseRepository.findAllByCustomerId(customerId)
logger.info("Get all training plan exercise list by customerId")
return if(exerciseList.isNotEmpty())
ResponseEntity.ok().body(exerciseList) else
ResponseEntity.notFound().build()
}
}
@@ -7,6 +7,7 @@ import javax.persistence.*
@Entity
data class Customer (
@Expose var name: String? = null,
@Expose var firstname: String? = null,
@Expose var email: String? = null,
@@ -27,6 +28,5 @@ data class Customer (
@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
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose var customerId: Long = 0,
)
@@ -1,16 +1,21 @@
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
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.*
@Entity
data class CustomerTrainingPlan (
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var customerTrainingPlanId: Long = 0,
@Expose @get: NonNull var customerId: Long = 0,
@Expose @get: NonNull var trainingPlanId: Long = 0,
@Expose @get: NonNull var dateAdd: String? = null
)
@Expose @get: NonNull var dateAdd: String? = null,
@Expose var active: Boolean?,
@Expose @get: NonNull var status: String? = null,
) {
@OneToMany(fetch = FetchType.EAGER, mappedBy = "customerTrainingPlan")
@Fetch(value = FetchMode.SUBSELECT)
@Expose val details: List<CustomerTrainingPlanDetails> = mutableListOf<CustomerTrainingPlanDetails>()
}
@@ -0,0 +1,22 @@
package com.aitrainer.api.model
import com.fasterxml.jackson.annotation.JsonIgnore
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 CustomerTrainingPlanDetails (
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var customerTrainingPlanDetailsId: Long = 0,
@Expose @get: NonNull var exerciseTypeId: Long = 0,
@Expose var set: Int?,
@Expose var repeats: Int?,
@Expose var weight: Double?,
) {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "customerTrainingPlanId", nullable = false)
@JsonIgnore
val customerTrainingPlan: CustomerTrainingPlan? = null
}
@@ -0,0 +1,15 @@
package com.aitrainer.api.model
import com.google.gson.annotations.Expose
import org.springframework.lang.NonNull
import javax.persistence.*
@Entity
data class CustomerTrainingPlanExercise (
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var customerTrainingPlanExerciseId: Long = 0,
@Expose @get: NonNull var customerTrainingPlanDetailsId: Long = 0,
@Expose @get: NonNull var customerId: Long = 0,
@Expose @get: NonNull var exerciseId: Long = 0,
@Expose var repeats: Int?,
@Expose var weight: Double?,
)
@@ -0,0 +1,10 @@
package com.aitrainer.api.repository
import com.aitrainer.api.model.CustomerTrainingPlanExercise
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface CustomerTrainingPlanExerciseRepository: JpaRepository<CustomerTrainingPlanExercise, Long> {
fun findAllByCustomerId(customerId: Long): List<CustomerTrainingPlanExercise>
}