API 1.0.25 update CustomerProperty
This commit is contained in:
parent
bd0a078640
commit
59d09ed115
@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.aitrainer"
|
||||
version = "1.0.24"
|
||||
version = "1.0.25"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
repositories {
|
||||
|
@ -266,7 +266,9 @@ CREATE TABLE IF NOT EXISTS `customer_property` (
|
||||
`property_id` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`property_value` double unsigned NOT NULL DEFAULT 0,
|
||||
`date_add` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`customer_property_id`) USING BTREE
|
||||
PRIMARY KEY (`customer_property_id`) USING BTREE,
|
||||
INDEX `property_id` (`property_id`) USING BTREE,
|
||||
INDEX `customer_id` (`customer_id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci;
|
||||
|
||||
-- Tábla adatainak mentése aitrainer2.customer_property: ~7 rows (hozzávetőleg)
|
||||
|
10
data/db/update_1_0_25.sql
Normal file
10
data/db/update_1_0_25.sql
Normal file
@ -0,0 +1,10 @@
|
||||
START TRANSACTION;
|
||||
ALTER TABLE `customer_property`
|
||||
ADD INDEX `property_id` (`property_id`),
|
||||
ADD INDEX `customer_id` (`customer_id`);
|
||||
|
||||
|
||||
UPDATE configuration set config_value = "1.0.25", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
||||
|
||||
COMMIT;
|
||||
|
@ -1,11 +1,10 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.CustomerProperty
|
||||
import com.aitrainer.api.model.ExercisePlanDetail
|
||||
import com.aitrainer.api.model.Purchase
|
||||
import com.aitrainer.api.repository.CustomerPropertyRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.security.access.annotation.Secured
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import javax.validation.Valid
|
||||
|
||||
@ -20,6 +19,20 @@ class CustomerPropertyController(private val customerPropertyRepository: Custome
|
||||
return ResponseEntity.ok().body(customerPropertyRepository.save(customerProperty))
|
||||
}
|
||||
|
||||
@Secured
|
||||
@PostMapping("customer_property/update/{id}")
|
||||
fun updateCustomerProperty(@PathVariable(value = "id") propertyId: Long,
|
||||
@Valid @RequestBody propertyToUpdate: CustomerProperty): ResponseEntity<CustomerProperty> {
|
||||
val customerProperty = customerPropertyRepository.findById(propertyId).orElse(null)
|
||||
?: return ResponseEntity.notFound().build()
|
||||
|
||||
val updatedCustomerProperty = customerProperty.copy(
|
||||
propertyValue = propertyToUpdate.propertyValue,
|
||||
dateAdd = propertyToUpdate.dateAdd
|
||||
)
|
||||
return ResponseEntity.ok().body(customerPropertyRepository.save(updatedCustomerProperty))
|
||||
}
|
||||
|
||||
@GetMapping("/customer_property/{id}")
|
||||
fun getAllByCustomerId(@PathVariable(value = "id") customerId: Long): ResponseEntity<List<CustomerProperty>> {
|
||||
|
||||
|
@ -17,6 +17,6 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structure has been changed, increment this version number
|
||||
application.version=1.0.24
|
||||
application.version=1.0.25
|
||||
|
||||
jwt.secret=aitrainer
|
@ -17,6 +17,6 @@ logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
||||
|
||||
# if the database structure has been changed, increment this version number
|
||||
application.version=1.0.24
|
||||
application.version=1.0.25
|
||||
|
||||
jwt.secret=aitrainer
|
@ -92,8 +92,8 @@ class AppCustomerPackageTest {
|
||||
val type = object : TypeToken<List<CustomerProperty?>?>() {}.type
|
||||
val propertyList: List<CustomerProperty> = gson.fromJson(propertyJson, type)
|
||||
assertTrue(propertyList.isNotEmpty())
|
||||
assertEquals(propertyList[1].propertyId,4)
|
||||
assertEquals(propertyList[1].propertyValue,37.0)
|
||||
assertEquals(propertyList[2].propertyId,4)
|
||||
assertEquals(propertyList[2].propertyValue,37.0)
|
||||
} else if (record[0] == CustomerProperty::class.simpleName+"All") {
|
||||
val propertyJson: String = record[1]
|
||||
val type = object : TypeToken<List<CustomerProperty?>?>() {}.type
|
||||
|
@ -8,6 +8,7 @@ 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
|
||||
import org.springframework.http.HttpStatus
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@ -28,7 +29,7 @@ class CustomerPropertyTest {
|
||||
|
||||
assertTrue(properties is List)
|
||||
assertTrue(properties.isNotEmpty())
|
||||
assertEquals(properties.size, 5)
|
||||
assertEquals(properties.size, 8)
|
||||
assertEquals(properties[0].propertyValue, 81.0)
|
||||
assertEquals(properties[1].propertyValue, 82.0)
|
||||
assertEquals(properties[3].propertyId, 4)
|
||||
@ -42,9 +43,9 @@ class CustomerPropertyTest {
|
||||
val properties = response.body
|
||||
assertTrue(properties is List)
|
||||
assertTrue(properties.isNotEmpty())
|
||||
assertEquals(properties.size, 3)
|
||||
assertEquals(properties[2].propertyValue, 79.0)
|
||||
assertEquals(properties[0].propertyValue, 172.0)
|
||||
assertEquals(properties.size, 6)
|
||||
assertEquals(properties[2].propertyValue, 37.0)
|
||||
assertEquals(properties[0].propertyValue, 81.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -67,4 +68,34 @@ class CustomerPropertyTest {
|
||||
customerPropertyRepository.delete(customerProperty)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUpdate() {
|
||||
var customerProperty = CustomerProperty(
|
||||
customerPropertyId = 91,
|
||||
dateAdd = "2021-02-15",
|
||||
propertyValue = 42.0
|
||||
)
|
||||
val controller = CustomerPropertyController(customerPropertyRepository)
|
||||
|
||||
var response = controller.updateCustomerProperty(customerProperty.customerPropertyId, customerProperty)
|
||||
|
||||
assertTrue(response.body is CustomerProperty)
|
||||
val updated = response.body
|
||||
assertEquals(updated!!.propertyValue, 42.0)
|
||||
updated.propertyValue = 81.0
|
||||
controller.updateCustomerProperty(customerProperty.customerPropertyId, customerProperty)
|
||||
|
||||
//notFound
|
||||
customerProperty = CustomerProperty(
|
||||
customerPropertyId = 1000,
|
||||
dateAdd = "2021-02-15",
|
||||
propertyValue = 83.0
|
||||
)
|
||||
response = controller.updateCustomerProperty(customerProperty.customerPropertyId, customerProperty)
|
||||
assertEquals(response.statusCode, HttpStatus.NOT_FOUND)
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -26,7 +26,7 @@ class PropertyTest {
|
||||
|
||||
assertTrue(properties is List)
|
||||
assertTrue(properties.isNotEmpty())
|
||||
assertEquals(properties.size, 4)
|
||||
assertEquals(properties.size, 7)
|
||||
assertEquals(properties[0].propertyName, "Weight")
|
||||
assertEquals(properties[0].translations[0].propertyName, "Tömeg")
|
||||
assertEquals(properties[1].propertyName, "Height")
|
||||
|
Loading…
Reference in New Issue
Block a user