API 1.0.57.3 get_user_by_email for deactivated: HTTP not found
This commit is contained in:
parent
839d3a85a5
commit
29415ba41f
@ -52,7 +52,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
@Secured
|
||||
@GetMapping("/customers/find_by_email/{email}")
|
||||
fun getCustomerByEmail(@PathVariable(value = "email") email: String): ResponseEntity<Customer> {
|
||||
val customer: Customer? = customerRepository.findByEmail(email)
|
||||
val customer: Customer? = customerRepository.findByEmailAndActive(email, "Y")
|
||||
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
email = newUser.username
|
||||
}
|
||||
|
||||
val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let {
|
||||
val returnCustomer: Customer? = customerRepository.findByEmailAndActive(newUser.username, "Y").let {
|
||||
if ( it == null) {
|
||||
customerRepository.save(customer)
|
||||
} else {
|
||||
@ -192,7 +192,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
email = newUser.username
|
||||
password = newUser.password
|
||||
}
|
||||
val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let {
|
||||
val returnCustomer: Customer? = customerRepository.findByEmailAndActive(newUser.username, "Y").let {
|
||||
if ( it == null) {
|
||||
null
|
||||
} else {
|
||||
|
@ -2,7 +2,6 @@ package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.Customer
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
@ -10,6 +9,7 @@ interface CustomerRepository : JpaRepository<Customer, Long> {
|
||||
fun findByActive( active: String? ): List<Customer>
|
||||
|
||||
fun findByEmail(email: String?): Customer?
|
||||
fun findByEmailAndActive(email: String, active: String): Customer?
|
||||
|
||||
fun findByTrainerId( trainerId: Long ): List<Customer>
|
||||
|
||||
|
@ -10,4 +10,7 @@ interface CustomerService {
|
||||
|
||||
@Query("FROM customer WHERE active = :active AND id = :customerId")
|
||||
fun findByCustomerIdAndActive(@Param("customerId") customerId: Long?, @Param("active") active: String? ): Customer
|
||||
|
||||
@Query("FROM customer WHERE active = :active AND email = :email")
|
||||
fun findByEmailAndActive(@Param("email") email: String, @Param("active") active: String ): Customer
|
||||
}
|
@ -97,7 +97,7 @@ class CustomerTests {
|
||||
fun testDeactivateCustomer() {
|
||||
val id: Long = 90
|
||||
|
||||
val controller: CustomerController = CustomerController(customerRepository)
|
||||
val controller = CustomerController(customerRepository)
|
||||
controller.deactivateCustomer(id)
|
||||
|
||||
val customer: Customer = customerRepository.findById(id).orElse(null)
|
||||
@ -112,6 +112,20 @@ class CustomerTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFindByEmail() {
|
||||
val controller = CustomerController(customerRepository)
|
||||
var response = controller.getCustomerByEmail("sw@andio.biz")
|
||||
|
||||
val customer = response.body
|
||||
assertNotNull(customer)
|
||||
assertEquals(customer.firstname, "Tib")
|
||||
|
||||
response = controller.getCustomerByEmail("mr@andio.biz")
|
||||
assertEquals(response.statusCode, HttpStatus.NOT_FOUND)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUpdateCustomer() {
|
||||
val id:Long = 90
|
||||
|
Loading…
Reference in New Issue
Block a user