From 7ddb724ccc4399d57d393c6822d76a1a4cb0b29c Mon Sep 17 00:00:00 2001 From: Bossanyi Tibor Date: Fri, 19 Feb 2021 17:56:42 +0100 Subject: [PATCH] API 1.0.25+2 customer.dateAdd dateChange --- .../api/controller/CustomerController.kt | 16 ++++++++++++---- .../aitrainer/api/test/CustomerPropertyTest.kt | 1 - .../com/aitrainer/api/test/CustomerTests.kt | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt index 0d2bcad..855bf18 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt @@ -10,6 +10,9 @@ 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.time.LocalDateTime +import java.time.format.DateTimeFormatter +import java.util.* import javax.validation.Valid @@ -100,8 +103,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, + dateChange = newCustomer.dateChange ) } else { updatedCustomer = @@ -113,8 +116,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, + dateChange = newCustomer.dateChange ) } @@ -126,11 +129,16 @@ class CustomerController ( private val customerRepository: CustomerRepository) { fun registration(@Valid @RequestBody json: String): ResponseEntity<*> { val customer = Customer() + val current = LocalDateTime.now() + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS") + val nowFormatted = current.format(formatter) + val newUser: User = User().fromJson(json) with (customer) { email = newUser.username password = serviceBeans!!.passwordEncoder().encode(newUser.password) firebaseUid = newUser.firebaseUid + dateAdd = nowFormatted } val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let { diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerPropertyTest.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerPropertyTest.kt index 537e2a1..21a629a 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerPropertyTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerPropertyTest.kt @@ -4,7 +4,6 @@ import com.aitrainer.api.controller.CustomerPropertyController import com.aitrainer.api.model.CustomerProperty import com.aitrainer.api.repository.CustomerPropertyRepository import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestFactory import org.junit.jupiter.api.TestInstance import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt index f66182d..ff6a9a2 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt @@ -13,8 +13,11 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.HttpHeaders import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter import kotlin.test.assertEquals import kotlin.test.assertNotNull +import kotlin.test.assertTrue @SpringBootTest @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -80,9 +83,11 @@ class CustomerTests { assertNotNull(updatedCustomer) updatedCustomer.firstname ="Tiborka" + updatedCustomer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) val customer: Customer = customerRepository.save( updatedCustomer ) assertEquals( customer.firstname, "Tiborka") + assertTrue(customer.dateChange != null) customerRepository.delete(updatedCustomer) } @@ -104,11 +109,13 @@ class CustomerTests { customer.bodyType = "endomorph" customer.dataPolicyAllowed = 1 customer.fitnessLevel = "advanced" + customer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) val updatedCustomer = customerRepository.save(customer) assertEquals(updatedCustomer.customerId, 90) assertEquals(updatedCustomer.birthYear, 1972) assertEquals(updatedCustomer.fitnessLevel, "advanced") + assertTrue(customer.dateChange != null) } @Test @@ -127,6 +134,7 @@ class CustomerTests { customer.fitnessLevel = "intermediate" //customer.weight = 79 customer.birthYear = 1972 + customer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) val customerController = CustomerController(customerRepository) var response: ResponseEntity<*> = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) ) @@ -134,8 +142,9 @@ class CustomerTests { var newCustomer: Customer? = response.body as Customer assertEquals(response.statusCode, HttpStatus.OK) //assertEquals(newCustomer?.weight, 79) - assertEquals(newCustomer?.password, "123456789") - assertEquals(newCustomer?.firstname, "Tib") + assertEquals(newCustomer!!.password, "123456789") + assertEquals(newCustomer.firstname, "Tib") + assertTrue(newCustomer.dateChange != null) // test not found id = 1000 @@ -175,6 +184,7 @@ class CustomerTests { val newCustomer: Customer = response.body as Customer assertEquals(response.statusCode, HttpStatus.OK) assertEquals(newCustomer.firebaseUid, "3Firebase8Uid") + assertTrue(newCustomer.dateAdd != null) val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid\"}" response = customerController.registration(json2)