Customer.firebaseUid
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -25,6 +25,7 @@ data class Customer (
|
||||
var goal: String? = null,
|
||||
var fitnessLevel: String = "beginner",
|
||||
var bodyType: String? = null,
|
||||
var firebaseUid: String? = null,
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
var customerId: Long = 0
|
||||
|
||||
@@ -6,7 +6,8 @@ import kotlinx.serialization.json.*
|
||||
@Serializable
|
||||
data class User (
|
||||
var username: String = "",
|
||||
var password: String = ""
|
||||
var password: String = "",
|
||||
var firebaseUid: String = ""
|
||||
) {
|
||||
@OptIn(UnstableDefault::class)
|
||||
fun fromJson(json: String): User {
|
||||
|
||||
@@ -11,4 +11,6 @@ interface CustomerRepository : JpaRepository<Customer, Long> {
|
||||
fun findByEmail(email: String?): Customer?
|
||||
|
||||
fun findByTrainerId( trainerId: Long ): List<Customer>
|
||||
|
||||
fun findByFirebaseUid(firebaseUid: String?): Customer?
|
||||
}
|
||||
|
||||
@@ -16,6 +16,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.9
|
||||
application.version=1.0.10
|
||||
|
||||
jwt.secret=aitrainer
|
||||
@@ -16,6 +16,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.9
|
||||
application.version=1.0.10
|
||||
|
||||
jwt.secret=aitrainer
|
||||
Reference in New Issue
Block a user