Merge branch 'tibor' into 'master'
Property, CustomerProperty See merge request bossanyit/aitrainer_server!22
This commit is contained in:
commit
08bfbf40b7
@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.aitrainer"
|
||||
version = "1.0.11"
|
||||
version = "1.0.12"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
repositories {
|
||||
|
@ -339,6 +339,48 @@ INSERT INTO `purchase` (`purchase_id`, `customer_id`, `product_id`, `date_add`,
|
||||
INSERT INTO `purchase` (`purchase_id`, `customer_id`, `product_id`, `date_add`, `purchase_sum`, `currency`) VALUES (2, 62, 1, '2020-11-05 15:45:08', 1000, 'HUF');
|
||||
INSERT INTO `purchase` (`purchase_id`, `customer_id`, `product_id`, `date_add`, `purchase_sum`, `currency`) VALUES (3, 2, 1, '2020-11-05 15:45:30', 1000, 'HUF');
|
||||
|
||||
CREATE TABLE `property` (
|
||||
`property_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`property_name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
||||
`property_unit` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
||||
PRIMARY KEY (`property_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8_hungarian_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
|
||||
INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES (1, 'Weight', 'kg');
|
||||
INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES (2, 'Height', 'cm');
|
||||
INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES (3, 'Chest', 'cm');
|
||||
INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES (4, 'Biceps', 'cm');
|
||||
|
||||
|
||||
CREATE TABLE `property_translation` (
|
||||
`translation_id` INT(13) NOT NULL AUTO_INCREMENT,
|
||||
`language_code` CHAR(2) NOT NULL DEFAULT 'en' COLLATE 'utf8mb4_general_ci',
|
||||
`property_id` INT(13) NOT NULL DEFAULT '0',
|
||||
`property_name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
PRIMARY KEY (`translation_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
ROW_FORMAT=DYNAMIC
|
||||
;
|
||||
|
||||
CREATE TABLE `customer_property` (
|
||||
`customer_property_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`customer_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
||||
`property_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
||||
`property_value` DOUBLE UNSIGNED NOT NULL DEFAULT '0',
|
||||
`date_add` DATETIME NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`customer_property_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8_hungarian_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*!40000 ALTER TABLE `exercise_type` ENABLE KEYS */;
|
||||
|
||||
|
41
data/db/update_1_0_12.sql
Normal file
41
data/db/update_1_0_12.sql
Normal file
@ -0,0 +1,41 @@
|
||||
CREATE TABLE `property` (
|
||||
`property_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`property_name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
||||
`property_unit` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
|
||||
PRIMARY KEY (`property_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8_hungarian_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
|
||||
INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES (1, 'Weight', 'kg');
|
||||
INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES (2, 'Height', 'cm');
|
||||
INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES (3, 'Chest', 'cm');
|
||||
INSERT INTO `property` (`property_id`, `property_name`, `property_unit`) VALUES (4, 'Biceps', 'cm');
|
||||
|
||||
|
||||
CREATE TABLE `property_translation` (
|
||||
`translation_id` INT(13) NOT NULL AUTO_INCREMENT,
|
||||
`language_code` CHAR(2) NOT NULL DEFAULT 'en' COLLATE 'utf8mb4_general_ci',
|
||||
`property_id` INT(13) NOT NULL DEFAULT '0',
|
||||
`property_name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
PRIMARY KEY (`translation_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
CREATE TABLE `customer_property` (
|
||||
`customer_property_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`customer_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
||||
`property_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
||||
`property_value` DOUBLE UNSIGNED NOT NULL DEFAULT '0',
|
||||
`date_add` DATETIME NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`customer_property_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8_hungarian_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
UPDATE configuration set config_value = "1.0.12", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
@ -16,5 +16,11 @@ provide a RESTful API for the mobile app
|
||||
* customer_information
|
||||
* exercise_plan
|
||||
* exercise_plan_detail
|
||||
* product
|
||||
* product_test
|
||||
* purchase
|
||||
* property
|
||||
* property_translation
|
||||
* customer_property
|
||||
|
||||
with automatic database update
|
||||
|
106
src/main/kotlin/com/aitrainer/api/controller/ControllerAspect.kt
Normal file
106
src/main/kotlin/com/aitrainer/api/controller/ControllerAspect.kt
Normal file
@ -0,0 +1,106 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.JoinPoint
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class ControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
/* @Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.*.*())")
|
||||
fun controllerAspect() {
|
||||
}
|
||||
|
||||
@Before("controllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}*/
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.CustomerController.*(..))")
|
||||
fun customerControllerAspect(joinPoint: JoinPoint) {
|
||||
println("customer controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.CustomerInformationController.*(..))")
|
||||
fun customerInformationControllerAspect(joinPoint: JoinPoint) {
|
||||
println("customer information controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.CustomerPropertyController.*(..))")
|
||||
fun customerPropertyControllerAspect(joinPoint: JoinPoint) {
|
||||
println("customer property controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.ExerciseController.*(..))")
|
||||
fun exerciseControllerAspect(joinPoint: JoinPoint) {
|
||||
println("exercise controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.ExercisePlanController.*(..))")
|
||||
fun exercisePlanControllerAspect(joinPoint: JoinPoint) {
|
||||
println("exercise plan controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.ExercisePlanDetailController.*(..))")
|
||||
fun exercisePlanDetailControllerAspect(joinPoint: JoinPoint) {
|
||||
println("exercise plan detail controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.ExerciseTreeController.*(..))")
|
||||
fun exerciseTreeControllerAspect(joinPoint: JoinPoint) {
|
||||
println("exercise tree controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.ExerciseTypeController.*(..))")
|
||||
fun exerciseTypeControllerAspect(joinPoint: JoinPoint) {
|
||||
println("exercise type controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.ProductController.*(..))")
|
||||
fun productControllerAspect(joinPoint: JoinPoint) {
|
||||
println("product controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.ProductTestController.*(..))")
|
||||
fun productTestControllerAspect(joinPoint: JoinPoint) {
|
||||
println("product test controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.PropertyController.*(..))")
|
||||
fun propertyControllerAspect(joinPoint: JoinPoint) {
|
||||
println("property controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.PurchaseController.*(..))")
|
||||
fun purchaseControllerAspect(joinPoint: JoinPoint) {
|
||||
println("purchase controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.JoinPoint
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class CustomerControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Before("execution(* com.aitrainer.api.controller.CustomerController.*(..))")
|
||||
fun customerControllerAspect(joinPoint: JoinPoint) {
|
||||
println("customer controller")
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,35 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Suppress("unused")
|
||||
class CustomerInformationControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.CustomerInformationController.*())")
|
||||
fun customerInformationAspect() {
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
@Before("customerInformationAspect()")
|
||||
fun dbCheckAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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.web.bind.annotation.*
|
||||
import javax.validation.Valid
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class CustomerPropertyController(private val customerPropertyRepository: CustomerPropertyRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@PostMapping("/customer_property")
|
||||
fun createNewCustomerProperty(@Valid @RequestBody customerProperty: CustomerProperty): ResponseEntity<CustomerProperty> {
|
||||
logger.info("Create customer property: $customerProperty")
|
||||
return ResponseEntity.ok().body(customerPropertyRepository.save(customerProperty))
|
||||
}
|
||||
|
||||
@GetMapping("/customer_property/{id}")
|
||||
fun getAllByCustomerId(@PathVariable(value = "id") customerId: Long): ResponseEntity<List<CustomerProperty>> {
|
||||
|
||||
val propertyList: List<CustomerProperty> = customerPropertyRepository.findAllByCustomerId(customerId)
|
||||
logger.info("Get all customer_property by customerId")
|
||||
|
||||
return if(propertyList.isNotEmpty())
|
||||
ResponseEntity.ok().body(propertyList) else
|
||||
ResponseEntity.notFound().build()
|
||||
}
|
||||
|
||||
@GetMapping( "/customer_property/last/{id}")
|
||||
fun getLastPropertiesByCustomerId(@PathVariable(value = "id") customerId: Long): ResponseEntity<List<CustomerProperty>> {
|
||||
val propertyList = customerPropertyRepository.findLastPropertiesByCustomerId(customerId)
|
||||
logger.info("Get last customer_property by customerId $propertyList")
|
||||
|
||||
return if (propertyList.isNotEmpty())
|
||||
ResponseEntity.ok().body(propertyList) else
|
||||
ResponseEntity.notFound().build()
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
class ExerciseControllerAspect {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.ExerciseController.*())")
|
||||
fun exerciseControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("exerciseControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class ExercisePlanControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.ExercisePlanController.*())")
|
||||
fun exercisePlanControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("exercisePlanControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class ExercisePlanDetailControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.ExercisePlanDetailController.*())")
|
||||
fun exercisePlanDetailControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("exercisePlanDetailControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class ExerciseTreeControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.ExerciseTreeController.*())")
|
||||
fun exerciseTreeControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("exerciseTreeControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class ExerciseTypeControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.ExerciseTypeController.*())")
|
||||
fun exerciseTypeControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("exerciseTypeControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class ProductControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.ProductController.*())")
|
||||
fun productControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("productControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class ProductTestControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.ProductTestController.*())")
|
||||
fun productTestControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("productTestControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.Property
|
||||
import com.aitrainer.api.repository.PropertyRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class PropertyController(private val propertyRepository: PropertyRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/property")
|
||||
fun getPropertiesWithTranslation(): ResponseEntity<List<Property>> {
|
||||
val list = propertyRepository.getProperties()
|
||||
|
||||
logger.info(" -- Get All properties $list")
|
||||
return if (list.isEmpty()) ResponseEntity.notFound().build() else
|
||||
ResponseEntity.ok().body(list)
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.ApiApplication
|
||||
import com.aitrainer.api.repository.ConfigurationRepository
|
||||
import org.aspectj.lang.annotation.Aspect
|
||||
import org.aspectj.lang.annotation.Before
|
||||
import org.aspectj.lang.annotation.Pointcut
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Suppress("unused")
|
||||
@Aspect
|
||||
@Component
|
||||
class PurchaseControllerAspect {
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
|
||||
@Autowired
|
||||
private lateinit var configurationRepository: ConfigurationRepository
|
||||
@Autowired
|
||||
private lateinit var properties: ApplicationProperties
|
||||
|
||||
@Suppress("unused")
|
||||
@Pointcut("execution(* com.aitrainer.api.controller.PurchaseController.*())")
|
||||
fun purchaseControllerAspect() {
|
||||
}
|
||||
|
||||
@Before("purchaseControllerAspect()")
|
||||
fun loggingAop() {
|
||||
Singleton.checkDBUpdate(configurationRepository, properties)
|
||||
}
|
||||
|
||||
}
|
16
src/main/kotlin/com/aitrainer/api/model/CustomerProperty.kt
Normal file
16
src/main/kotlin/com/aitrainer/api/model/CustomerProperty.kt
Normal file
@ -0,0 +1,16 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.GenerationType
|
||||
import javax.persistence.Id
|
||||
|
||||
@Entity
|
||||
data class CustomerProperty (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var customerPropertyId: Long = 0,
|
||||
@get: NonNull var customerId: Long = 0,
|
||||
@get: NonNull var propertyId: Long = 0,
|
||||
@get: NonNull var propertyValue: Double? = null,
|
||||
@get: NonNull var dateAdd: String? = null
|
||||
)
|
19
src/main/kotlin/com/aitrainer/api/model/Property.kt
Normal file
19
src/main/kotlin/com/aitrainer/api/model/Property.kt
Normal file
@ -0,0 +1,19 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import org.hibernate.annotations.Fetch
|
||||
import org.hibernate.annotations.FetchMode
|
||||
import org.springframework.lang.NonNull
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Entity
|
||||
data class Property (
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var propertyId: Long = 0,
|
||||
@get: NotBlank var propertyName: String = "",
|
||||
@get: NotBlank var propertyUnit: String = ""
|
||||
) {
|
||||
@OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "property")
|
||||
@Fetch(value = FetchMode.SUBSELECT)
|
||||
val translations: List<PropertyTranslation> = mutableListOf<PropertyTranslation>().toList()
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import javax.persistence.*
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Entity
|
||||
data class PropertyTranslation (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) val translationId: Long = 0,
|
||||
|
||||
@get: NotBlank var languageCode: String?,
|
||||
@get: NotBlank var propertyName: String = ""
|
||||
|
||||
|
||||
) {
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false)
|
||||
@JoinColumn(name = "propertyId", nullable = false)
|
||||
@JsonIgnore
|
||||
val property: Property? = null
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.CustomerProperty
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface CustomerPropertyRepository: JpaRepository<CustomerProperty, Long> {
|
||||
|
||||
fun findAllByCustomerId(customerId: Long): List<CustomerProperty>
|
||||
|
||||
@Query(" FROM CustomerProperty a " +
|
||||
" WHERE customerId = :customerId" +
|
||||
" AND dateAdd in (select MAX(dateAdd) from CustomerProperty b " +
|
||||
" WHERE customerId = :customerId and a.propertyId = b.propertyId ) "
|
||||
)
|
||||
fun findLastPropertiesByCustomerId(customerId: Long): List<CustomerProperty>
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.Property
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface PropertyRepository: JpaRepository<Property, Long> {
|
||||
@Query("FROM Property as e " +
|
||||
"LEFT JOIN PropertyTranslation as t ON e.propertyId = t.property AND t.languageCode = 'hu' " +
|
||||
"ORDER BY e.propertyId ")
|
||||
fun getProperties(): List<Property>
|
||||
}
|
@ -16,6 +16,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.11
|
||||
application.version=1.0.12
|
||||
|
||||
jwt.secret=aitrainer
|
@ -16,6 +16,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.11
|
||||
application.version=1.0.12
|
||||
|
||||
jwt.secret=aitrainer
|
@ -0,0 +1,70 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
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
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class CustomerPropertyTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var customerPropertyRepository: CustomerPropertyRepository
|
||||
|
||||
|
||||
@Test
|
||||
fun testGetAllCustomerProperties() {
|
||||
val controller = CustomerPropertyController(customerPropertyRepository )
|
||||
val response = controller.getAllByCustomerId(90)
|
||||
|
||||
val properties = response.body
|
||||
|
||||
assertTrue(properties is List)
|
||||
assertTrue(properties.isNotEmpty())
|
||||
assertEquals(properties.size, 4)
|
||||
assertEquals(properties[0].propertyValue, 81.0)
|
||||
assertEquals(properties[1].propertyValue, 82.0)
|
||||
assertEquals(properties[3].propertyId, 4)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetLastCustomerProperties() {
|
||||
val controller = CustomerPropertyController(customerPropertyRepository)
|
||||
val response = controller.getLastPropertiesByCustomerId(90)
|
||||
|
||||
val properties = response.body
|
||||
assertTrue(properties is List)
|
||||
assertTrue(properties.isNotEmpty())
|
||||
assertEquals(properties.size, 3)
|
||||
assertEquals(properties[0].propertyValue, 82.0)
|
||||
assertEquals(properties[1].propertyValue, 172.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInsert() {
|
||||
val customerProperty = CustomerProperty(
|
||||
customerId = 90,
|
||||
propertyId = 1,
|
||||
dateAdd = "2020-11-10",
|
||||
propertyValue = 81.5
|
||||
)
|
||||
|
||||
val controller = CustomerPropertyController(customerPropertyRepository)
|
||||
val response = controller.createNewCustomerProperty(customerProperty)
|
||||
|
||||
val newCustomerProperty = response.body
|
||||
|
||||
assertTrue(newCustomerProperty is CustomerProperty)
|
||||
assertEquals(newCustomerProperty.propertyValue, 81.5)
|
||||
|
||||
customerPropertyRepository.delete(customerProperty)
|
||||
}
|
||||
|
||||
}
|
35
src/test/kotlin/com/aitrainer/api/test/PropertyTest.kt
Normal file
35
src/test/kotlin/com/aitrainer/api/test/PropertyTest.kt
Normal file
@ -0,0 +1,35 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import com.aitrainer.api.controller.PropertyController
|
||||
import com.aitrainer.api.repository.PropertyRepository
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class PropertyTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var propertyRepository: PropertyRepository
|
||||
|
||||
|
||||
@Test
|
||||
fun testGetProperties() {
|
||||
val controller = PropertyController(propertyRepository )
|
||||
val response = controller.getPropertiesWithTranslation()
|
||||
|
||||
val properties = response.body
|
||||
|
||||
assertTrue(properties is List)
|
||||
assertTrue(properties.isNotEmpty())
|
||||
assertEquals(properties.size, 4)
|
||||
assertEquals(properties[0].propertyName, "Weight")
|
||||
assertEquals(properties[0].translations[0].propertyName, "Tömeg")
|
||||
assertEquals(properties[1].propertyName, "Height")
|
||||
}
|
||||
|
||||
}
|
@ -50,7 +50,7 @@ class PurchaseTest {
|
||||
assertEquals(purchaseNew!!.productId, 2)
|
||||
assertEquals(purchaseNew.customerId, 1)
|
||||
|
||||
//purchaseRepository.delete(purchaseNew)
|
||||
purchaseRepository.delete(purchaseNew)
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user