API 1.0.15 CustomerExerciseDevice

This commit is contained in:
Bossanyi Tibor
2020-11-23 18:15:46 +01:00
parent af2f5be1bf
commit 3a70bcd10f
20 changed files with 171 additions and 61 deletions
@@ -103,4 +103,10 @@ class ControllerAspect {
Singleton.checkDBUpdate(configurationRepository, properties)
}
@Before("execution(* com.aitrainer.api.controller.ExerciseDeviceController.*(..))")
fun exerciseDeviceControllerAspect(joinPoint: JoinPoint) {
println("exerciseDevice controller")
Singleton.checkDBUpdate(configurationRepository, properties)
}
}
@@ -2,6 +2,7 @@ package com.aitrainer.api.controller
import com.aitrainer.api.model.Customer
import com.aitrainer.api.model.User
import com.aitrainer.api.repository.CustomerExerciseDeviceRepository
import com.aitrainer.api.service.ServiceBeans
import com.aitrainer.api.repository.CustomerRepository
import org.slf4j.LoggerFactory
@@ -10,13 +11,13 @@ import org.springframework.http.HttpHeaders
import org.springframework.http.ResponseEntity
import org.springframework.security.access.annotation.Secured
import org.springframework.web.bind.annotation.*
import java.util.*
import javax.validation.Valid
@RestController
@RequestMapping("/api")
class CustomerController ( private val customerRepository: CustomerRepository ) {
class CustomerController ( private val customerRepository: CustomerRepository,
private val customerExerciseDeviceRepository: CustomerExerciseDeviceRepository ) {
private val logger = LoggerFactory.getLogger(javaClass)
@Autowired
@@ -35,15 +36,22 @@ class CustomerController ( private val customerRepository: CustomerRepository )
@Secured
@GetMapping("/customers/{id}")
fun getCustomerById(@PathVariable(value = "id") customerId: Long, @RequestHeader headers: HttpHeaders): ResponseEntity<Customer> {
return customerRepository.findById(customerId).map { customer ->
ResponseEntity.ok(customer)
}.orElse(ResponseEntity.notFound().build())
val customer: Customer? = customerRepository.findById(customerId).orElse(null)
if ( customer != null) {
val list = customerExerciseDeviceRepository.findByCustomerId(customer.customerId)
customer.exerciseDevices = list
}
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
}
@Secured
@GetMapping("/customers/find_by_firebaseuid/{uid}")
fun getCustomerByFirebaseUid(@PathVariable(value = "uid") firebaseUid: String): ResponseEntity<Customer> {
val customer: Customer? = customerRepository.findByFirebaseUid(firebaseUid)
if ( customer != null) {
val list = customerExerciseDeviceRepository.findByCustomerId(customer.customerId)
customer.exerciseDevices = list
}
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
}
@@ -51,6 +59,10 @@ class CustomerController ( private val customerRepository: CustomerRepository )
@GetMapping("/customers/find_by_email/{email}")
fun getCustomerByEmail(@PathVariable(value = "email") email: String): ResponseEntity<Customer> {
val customer: Customer? = customerRepository.findByEmail(email)
if ( customer != null) {
val list = customerExerciseDeviceRepository.findByCustomerId(customer.customerId)
customer.exerciseDevices = list
}
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
}
@@ -64,9 +76,9 @@ class CustomerController ( private val customerRepository: CustomerRepository )
@GetMapping("/customers/trainees/{id}")
fun getCustomerListByTrainerId(@PathVariable(value = "id") trainerId: Long, @RequestHeader headers: HttpHeaders):
ResponseEntity<List<Customer>> {
val list = customerRepository.findByTrainerId(trainerId)
val customerList: List<Customer> = customerRepository.findByTrainerId(trainerId)
return if (list.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(list)
return if (customerList.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customerList)
}
@Secured
@@ -101,8 +113,8 @@ class CustomerController ( private val customerRepository: CustomerRepository )
birthYear = newCustomer.birthYear,
fitnessLevel = newCustomer.fitnessLevel,
bodyType = newCustomer.bodyType,
goal = newCustomer.goal,
weight = newCustomer.weight
goal = newCustomer.goal
//weight = newCustomer.weight
)
} else {
updatedCustomer =
@@ -114,8 +126,8 @@ class CustomerController ( private val customerRepository: CustomerRepository )
birthYear = newCustomer.birthYear,
fitnessLevel = newCustomer.fitnessLevel,
bodyType = newCustomer.bodyType,
goal = newCustomer.goal,
weight = newCustomer.weight
goal = newCustomer.goal
//weight = newCustomer.weight
)
}