Pruduct, Purchase, Producttest
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.Product
|
||||
import com.aitrainer.api.repository.ProductRepository
|
||||
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 ProductController(private val productRepository: ProductRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/product")
|
||||
fun getAllProducts(): ResponseEntity<List<Product>> {
|
||||
|
||||
val products = productRepository.findAll()
|
||||
logger.info("Get all products")
|
||||
|
||||
return if(products.isNotEmpty())
|
||||
ResponseEntity.ok().body(products) else
|
||||
ResponseEntity.notFound().build()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.ProductTest
|
||||
import com.aitrainer.api.repository.ProductTestRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import javax.validation.Valid
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class ProductTestController(private val productTestRepository: ProductTestRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/product_test/customer/{id}")
|
||||
fun getAllByCustomerId(@PathVariable(value = "id") customerId: Long): ResponseEntity<List<ProductTest>> {
|
||||
|
||||
val productTestList = productTestRepository.findByCustomerId(customerId)
|
||||
logger.info("Get all productTest by customerId $productTestList")
|
||||
|
||||
return if(productTestList.isNotEmpty())
|
||||
ResponseEntity.ok().body(productTestList) else
|
||||
ResponseEntity.notFound().build()
|
||||
}
|
||||
|
||||
@PostMapping("/product_test")
|
||||
fun insertProductTest(@Valid @RequestBody productTest: ProductTest): ResponseEntity<ProductTest> {
|
||||
val newProductTest = productTestRepository.save(productTest)
|
||||
logger.info("Create new productTest: $newProductTest")
|
||||
return ResponseEntity.ok().body(newProductTest)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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,32 @@
|
||||
package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.Purchase
|
||||
import com.aitrainer.api.repository.PurchaseRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import javax.validation.Valid
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class PurchaseController(private val purchaseRepository: PurchaseRepository) {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/purchase/customer/{id}")
|
||||
fun getAllByCustomerId(@PathVariable(value = "id") customerId: Long): ResponseEntity<List<Purchase>> {
|
||||
|
||||
val purchaseList = purchaseRepository.findByCustomerId(customerId)
|
||||
logger.info("Get all purchase by customerId")
|
||||
|
||||
return if(purchaseList.isNotEmpty())
|
||||
ResponseEntity.ok().body(purchaseList) else
|
||||
ResponseEntity.notFound().build()
|
||||
}
|
||||
|
||||
@PostMapping("/purchase")
|
||||
fun insertPurchase(@Valid @RequestBody purchase: Purchase): ResponseEntity<Purchase> {
|
||||
val newPurchase = purchaseRepository.save(purchase)
|
||||
logger.info("Create new purchase: $newPurchase")
|
||||
return ResponseEntity.ok().body(newPurchase)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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,24 @@
|
||||
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
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
/*enum class ProductType(val type: String) {
|
||||
SUBSCRIPTION("subscription"),
|
||||
IN_APP_CURR("in-app-currency")
|
||||
|
||||
}*/
|
||||
|
||||
@Entity
|
||||
data class Product (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var productId: Int,
|
||||
@get: NotBlank var name: String = "",
|
||||
@get: NotBlank var description: String = "",
|
||||
@get: NonNull var type: String? = null,
|
||||
@get: NonNull var validFrom: String? = null,
|
||||
@get: NonNull var validTo: String? = null
|
||||
)
|
||||
@@ -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 ProductTest (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var productTestId: Int = 0,
|
||||
@get: NonNull var customerId: Long = 0,
|
||||
@get: NonNull var productId: Int = 0,
|
||||
@get: NonNull var dateView: String? = null,
|
||||
@get: NonNull var purchaseClick: Boolean = false
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
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
|
||||
import javax.validation.constraints.NotBlank
|
||||
|
||||
@Entity
|
||||
data class Purchase (
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var purchaseId: Long = 0,
|
||||
@get: NonNull var customerId: Long = 0,
|
||||
@get: NonNull var productId: Int = 0,
|
||||
@get: NonNull var purchaseSum: Double? = null,
|
||||
@get: NonNull var dateAdd: String? = null,
|
||||
@get: NotBlank var currency: String = ""
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.Product
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface ProductRepository : JpaRepository<Product, Long> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.ProductTest
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface ProductTestRepository : JpaRepository<ProductTest, Long> {
|
||||
fun findByCustomerId(customerId: Long): List<ProductTest>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.aitrainer.api.repository
|
||||
|
||||
import com.aitrainer.api.model.Purchase
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface PurchaseRepository : JpaRepository<Purchase, Long> {
|
||||
fun findByCustomerId(customerId: Long): List<Purchase>
|
||||
}
|
||||
@@ -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.10
|
||||
application.version=1.0.11
|
||||
|
||||
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.10
|
||||
application.version=1.0.11
|
||||
|
||||
jwt.secret=aitrainer
|
||||
Reference in New Issue
Block a user