Property, CustomerProperty
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
@@ -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>
|
||||
}
|
||||
Reference in New Issue
Block a user