diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt index d511400..b1d6520 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt @@ -41,12 +41,19 @@ class CustomerController ( private val customerRepository: CustomerRepository ) } @Secured - @GetMapping("/customers/firebase/{uid}") + @GetMapping("/customers/find_by_firebaseuid/{uid}") fun getCustomerByFirebaseUid(@PathVariable(value = "uid") firebaseUid: String): ResponseEntity { val customer: Customer? = customerRepository.findByFirebaseUid(firebaseUid) return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer) } + @Secured + @GetMapping("/customers/find_by_email/{email}") + fun getCustomerByEmail(@PathVariable(value = "email") email: String): ResponseEntity { + val customer: Customer? = customerRepository.findByEmail(email) + return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer) + } + @Secured @GetMapping("/customers/real") diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt index 4bcbc6f..0c2fd1a 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt @@ -206,6 +206,19 @@ class CustomerTests { } + @Test + fun testGetCustomerByEmail() { + val email = "sw2@andio.biz" + val customerController = CustomerController(customerRepository) + val response: ResponseEntity<*> = customerController.getCustomerByEmail(email) + assertEquals(response.statusCode, HttpStatus.OK) + val newCustomer: Customer? = response.body as Customer + assertEquals(newCustomer!!.name, "Bos") + assertEquals(newCustomer.email, "sw2@andio.biz") + assertEquals(newCustomer.firebaseUid, "3FirebaseU1d") + + } + /*@Test fun _testLogin() { val json = "{\"username\":\"bosi2@example.com\",\"password\":\"94333385\"}" val user: User = User().fromJson(json)