API 1.0.25+2 customer.dateAdd dateChange
This commit is contained in:
parent
59d09ed115
commit
7ddb724ccc
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user