|
|
|
@@ -4,6 +4,7 @@ import com.aitrainer.api.model.Customer
|
|
|
|
|
import com.aitrainer.api.model.User
|
|
|
|
|
import com.aitrainer.api.service.ServiceBeans
|
|
|
|
|
import com.aitrainer.api.repository.CustomerRepository
|
|
|
|
|
import org.slf4j.LoggerFactory
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
|
|
|
import org.springframework.http.HttpHeaders
|
|
|
|
|
import org.springframework.http.ResponseEntity
|
|
|
|
@@ -16,6 +17,7 @@ import javax.validation.Valid
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api")
|
|
|
|
|
class CustomerController ( private val customerRepository: CustomerRepository ) {
|
|
|
|
|
private val logger = LoggerFactory.getLogger(javaClass)
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
var serviceBeans: ServiceBeans? = null
|
|
|
|
@@ -38,6 +40,13 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
|
|
|
|
}.orElse(ResponseEntity.notFound().build())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Secured
|
|
|
|
|
@GetMapping("/customers/firebase/{uid}")
|
|
|
|
|
fun getCustomerByFirebaseUid(@PathVariable(value = "uid") firebaseUid: String): ResponseEntity<Customer> {
|
|
|
|
|
val customer: Customer? = customerRepository.findByFirebaseUid(firebaseUid)
|
|
|
|
|
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Secured
|
|
|
|
|
@GetMapping("/customers/real")
|
|
|
|
@@ -53,6 +62,18 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
|
|
|
|
return if (list.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(list)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Secured
|
|
|
|
|
@PostMapping("customers/update_firebase_uid/{id}")
|
|
|
|
|
fun updateCustomerFirebaseUidById(@PathVariable(value = "id") customerId: Long, @Valid @RequestBody firebaseUid: String)
|
|
|
|
|
: ResponseEntity<Customer> {
|
|
|
|
|
logger.info("Get customer id: $customerId uid: $firebaseUid")
|
|
|
|
|
val returnCustomer: Customer = customerRepository.findById(customerId).orElse(null)
|
|
|
|
|
?: return ResponseEntity.notFound().build()
|
|
|
|
|
|
|
|
|
|
returnCustomer.firebaseUid = firebaseUid;
|
|
|
|
|
return ResponseEntity.ok().body(customerRepository.save(returnCustomer))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Secured
|
|
|
|
|
@PostMapping("/customers/{id}")
|
|
|
|
|
fun updateCustomerById(@PathVariable(value = "id") customerId: Long,
|
|
|
|
@@ -103,6 +124,7 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
|
|
|
|
with (customer) {
|
|
|
|
|
email = newUser.username
|
|
|
|
|
password = serviceBeans!!.passwordEncoder().encode(newUser.password)
|
|
|
|
|
firebaseUid = newUser.firebaseUid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let {
|
|
|
|
|