Merge branch 'tibor' into 'master'
API 1.0.25+2 customer.dateAdd dateChange See merge request bossanyit/aitrainer_server!40
This commit is contained in:
commit
51773bc7e2
@ -10,6 +10,9 @@ import org.springframework.http.HttpHeaders
|
|||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
import org.springframework.security.access.annotation.Secured
|
import org.springframework.security.access.annotation.Secured
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
import java.util.*
|
||||||
import javax.validation.Valid
|
import javax.validation.Valid
|
||||||
|
|
||||||
|
|
||||||
@ -101,7 +104,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
|||||||
fitnessLevel = newCustomer.fitnessLevel,
|
fitnessLevel = newCustomer.fitnessLevel,
|
||||||
bodyType = newCustomer.bodyType,
|
bodyType = newCustomer.bodyType,
|
||||||
goal = newCustomer.goal,
|
goal = newCustomer.goal,
|
||||||
dataPolicyAllowed = newCustomer.dataPolicyAllowed
|
dateChange = newCustomer.dateChange
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
updatedCustomer =
|
updatedCustomer =
|
||||||
@ -114,7 +117,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
|||||||
fitnessLevel = newCustomer.fitnessLevel,
|
fitnessLevel = newCustomer.fitnessLevel,
|
||||||
bodyType = newCustomer.bodyType,
|
bodyType = newCustomer.bodyType,
|
||||||
goal = newCustomer.goal,
|
goal = newCustomer.goal,
|
||||||
dataPolicyAllowed = newCustomer.dataPolicyAllowed
|
dateChange = newCustomer.dateChange
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +129,16 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
|||||||
fun registration(@Valid @RequestBody json: String): ResponseEntity<*> {
|
fun registration(@Valid @RequestBody json: String): ResponseEntity<*> {
|
||||||
val customer = Customer()
|
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)
|
val newUser: User = User().fromJson(json)
|
||||||
with (customer) {
|
with (customer) {
|
||||||
email = newUser.username
|
email = newUser.username
|
||||||
password = serviceBeans!!.passwordEncoder().encode(newUser.password)
|
password = serviceBeans!!.passwordEncoder().encode(newUser.password)
|
||||||
firebaseUid = newUser.firebaseUid
|
firebaseUid = newUser.firebaseUid
|
||||||
|
dateAdd = nowFormatted
|
||||||
}
|
}
|
||||||
|
|
||||||
val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let {
|
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.model.CustomerProperty
|
||||||
import com.aitrainer.api.repository.CustomerPropertyRepository
|
import com.aitrainer.api.repository.CustomerPropertyRepository
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.TestFactory
|
|
||||||
import org.junit.jupiter.api.TestInstance
|
import org.junit.jupiter.api.TestInstance
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
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.HttpHeaders
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
@ -80,11 +83,11 @@ class CustomerTests {
|
|||||||
|
|
||||||
assertNotNull(updatedCustomer)
|
assertNotNull(updatedCustomer)
|
||||||
updatedCustomer.firstname ="Tiborka"
|
updatedCustomer.firstname ="Tiborka"
|
||||||
updatedCustomer.dataPolicyAllowed = 1;
|
updatedCustomer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))
|
||||||
|
|
||||||
val customer: Customer = customerRepository.save( updatedCustomer )
|
val customer: Customer = customerRepository.save( updatedCustomer )
|
||||||
assertEquals( customer.firstname, "Tiborka")
|
assertEquals( customer.firstname, "Tiborka")
|
||||||
assertEquals(customer.dataPolicyAllowed, 1)
|
assertTrue(customer.dateChange != null)
|
||||||
|
|
||||||
customerRepository.delete(updatedCustomer)
|
customerRepository.delete(updatedCustomer)
|
||||||
}
|
}
|
||||||
@ -106,11 +109,13 @@ class CustomerTests {
|
|||||||
customer.bodyType = "endomorph"
|
customer.bodyType = "endomorph"
|
||||||
customer.dataPolicyAllowed = 1
|
customer.dataPolicyAllowed = 1
|
||||||
customer.fitnessLevel = "advanced"
|
customer.fitnessLevel = "advanced"
|
||||||
|
customer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))
|
||||||
|
|
||||||
val updatedCustomer = customerRepository.save(customer)
|
val updatedCustomer = customerRepository.save(customer)
|
||||||
assertEquals(updatedCustomer.customerId, 90)
|
assertEquals(updatedCustomer.customerId, 90)
|
||||||
assertEquals(updatedCustomer.birthYear, 1972)
|
assertEquals(updatedCustomer.birthYear, 1972)
|
||||||
assertEquals(updatedCustomer.fitnessLevel, "advanced")
|
assertEquals(updatedCustomer.fitnessLevel, "advanced")
|
||||||
|
assertTrue(customer.dateChange != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -129,6 +134,7 @@ class CustomerTests {
|
|||||||
customer.fitnessLevel = "intermediate"
|
customer.fitnessLevel = "intermediate"
|
||||||
//customer.weight = 79
|
//customer.weight = 79
|
||||||
customer.birthYear = 1972
|
customer.birthYear = 1972
|
||||||
|
customer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))
|
||||||
|
|
||||||
val customerController = CustomerController(customerRepository)
|
val customerController = CustomerController(customerRepository)
|
||||||
var response: ResponseEntity<*> = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) )
|
var response: ResponseEntity<*> = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) )
|
||||||
@ -136,8 +142,9 @@ class CustomerTests {
|
|||||||
var newCustomer: Customer? = response.body as Customer
|
var newCustomer: Customer? = response.body as Customer
|
||||||
assertEquals(response.statusCode, HttpStatus.OK)
|
assertEquals(response.statusCode, HttpStatus.OK)
|
||||||
//assertEquals(newCustomer?.weight, 79)
|
//assertEquals(newCustomer?.weight, 79)
|
||||||
assertEquals(newCustomer?.password, "123456789")
|
assertEquals(newCustomer!!.password, "123456789")
|
||||||
assertEquals(newCustomer?.firstname, "Tib")
|
assertEquals(newCustomer.firstname, "Tib")
|
||||||
|
assertTrue(newCustomer.dateChange != null)
|
||||||
|
|
||||||
// test not found
|
// test not found
|
||||||
id = 1000
|
id = 1000
|
||||||
@ -177,6 +184,7 @@ class CustomerTests {
|
|||||||
val newCustomer: Customer = response.body as Customer
|
val newCustomer: Customer = response.body as Customer
|
||||||
assertEquals(response.statusCode, HttpStatus.OK)
|
assertEquals(response.statusCode, HttpStatus.OK)
|
||||||
assertEquals(newCustomer.firebaseUid, "3Firebase8Uid")
|
assertEquals(newCustomer.firebaseUid, "3Firebase8Uid")
|
||||||
|
assertTrue(newCustomer.dateAdd != null)
|
||||||
|
|
||||||
val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid\"}"
|
val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid\"}"
|
||||||
response = customerController.registration(json2)
|
response = customerController.registration(json2)
|
||||||
|
Loading…
Reference in New Issue
Block a user