Pruduct, Purchase, Producttest
This commit is contained in:
parent
83939110af
commit
6cf74d2738
@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.aitrainer"
|
||||
version = "1.0.10"
|
||||
version = "1.0.11"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
repositories {
|
||||
|
@ -282,6 +282,63 @@ COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
CREATE TABLE `product` (
|
||||
`product_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` CHAR(50) NOT NULL COLLATE 'utf8mb4_general_ci',
|
||||
`description` TEXT(65535) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
`type` ENUM('subscription','in-app-currency') NOT NULL DEFAULT 'subscription' COLLATE 'utf8mb4_general_ci',
|
||||
`valid_from` DATE NULL DEFAULT NULL,
|
||||
`valid_to` DATE NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`product_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (1, 'Subscription A', '700 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (2, 'Subscription B', '1000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (3, 'Subscription C', '1500 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (4, 'Subscription D', '2000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (5, 'Subscription E', '3000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (6, 'Subscription F', '5000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (7, 'Subscription A Yearly', '7000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (8, 'Subscription B Yearly', '10000', 'subscription', '2020-11-04', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (9, 'Subscription C Yearly', '15000', 'subscription', '2020-11-04', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (10, 'Subscription D Yearly', '20000', 'subscription', '2020-11-04', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (11, 'Subscription E Yearly', '30000', 'subscription', '2020-11-04', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (12, 'Subscription F Yearly', '50000', 'subscription', '2020-11-04', NULL);
|
||||
|
||||
CREATE TABLE `product_test` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`product_id` INT(11) NULL DEFAULT '0',
|
||||
`customer_id` INT(11) NULL DEFAULT '0',
|
||||
`date_view` DATETIME NULL DEFAULT NULL,
|
||||
`purchase_click` TINYINT(4) NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `customer_id` (`customer_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
CREATE TABLE `purchase` (
|
||||
`purchase_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`customer_id` INT(11) NOT NULL DEFAULT '0',
|
||||
`product_id` INT(11) NOT NULL DEFAULT '0',
|
||||
`date_add` DATETIME NULL DEFAULT NULL,
|
||||
`purchase_sum` DOUBLE(22,0) NULL DEFAULT NULL,
|
||||
`currency` CHAR(3) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
PRIMARY KEY (`purchase_id`) USING BTREE,
|
||||
INDEX `customer_id` (`customer_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
INSERT INTO `purchase` (`purchase_id`, `customer_id`, `product_id`, `date_add`, `purchase_sum`, `currency`) VALUES (1, 62, 1, '2020-10-03 00:00:00', 1000, 'HUF');
|
||||
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');
|
||||
|
||||
|
||||
/*!40000 ALTER TABLE `exercise_type` ENABLE KEYS */;
|
||||
|
||||
|
60
data/db/update_1_0_11.sql
Normal file
60
data/db/update_1_0_11.sql
Normal file
@ -0,0 +1,60 @@
|
||||
CREATE TABLE `product` (
|
||||
`product_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` CHAR(50) NOT NULL COLLATE 'utf8mb4_general_ci',
|
||||
`description` TEXT(65535) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
`type` ENUM('subscription','in-app-currency') NOT NULL DEFAULT 'subscription' COLLATE 'utf8mb4_general_ci',
|
||||
`valid_from` DATE NULL DEFAULT NULL,
|
||||
`valid_to` DATE NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`product_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (1, 'Subscription A', '700 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (2, 'Subscription B', '1000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (3, 'Subscription C', '1500 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (4, 'Subscription D', '2000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (5, 'Subscription E', '3000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (6, 'Subscription F', '5000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (7, 'Subscription A Yearly', '7000 Ft', 'subscription', '2020-11-01', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (8, 'Subscription B Yearly', '10000', 'subscription', '2020-11-04', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (9, 'Subscription C Yearly', '15000', 'subscription', '2020-11-04', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (10, 'Subscription D Yearly', '20000', 'subscription', '2020-11-04', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (11, 'Subscription E Yearly', '30000', 'subscription', '2020-11-04', NULL);
|
||||
INSERT INTO `product` (`product_id`, `name`, `description`, `type`, `valid_from`, `valid_to`) VALUES (12, 'Subscription F Yearly', '50000', 'subscription', '2020-11-04', NULL);
|
||||
|
||||
CREATE TABLE `product_test` (
|
||||
`product_test_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`product_id` INT(11) NULL DEFAULT '0',
|
||||
`customer_id` INT(11) NULL DEFAULT '0',
|
||||
`date_view` DATETIME NULL DEFAULT NULL,
|
||||
`purchase_click` TINYINT(4) NULL DEFAULT '0',
|
||||
PRIMARY KEY (`product_test_id`) USING BTREE,
|
||||
INDEX `customer_id` (`customer_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
CREATE TABLE `purchase` (
|
||||
`purchase_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`customer_id` INT(11) NOT NULL DEFAULT '0',
|
||||
`product_id` INT(11) NOT NULL DEFAULT '0',
|
||||
`date_add` DATETIME NULL DEFAULT NULL,
|
||||
`purchase_sum` DOUBLE(22,0) NULL DEFAULT NULL,
|
||||
`currency` CHAR(3) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
|
||||
PRIMARY KEY (`purchase_id`) USING BTREE,
|
||||
INDEX `customer_id` (`customer_id`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
|
||||
|
||||
INSERT INTO `purchase` (`purchase_id`, `customer_id`, `product_id`, `date_add`, `purchase_sum`, `currency`) VALUES (1, 62, 1, '2020-10-03 00:00:00', 1000, 'HUF');
|
||||
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');
|
||||
|
||||
|
||||
UPDATE configuration set config_value = "1.0.11", date_change=CURRENT_DATE WHERE config_key = "db_version";
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
24
src/main/kotlin/com/aitrainer/api/model/Product.kt
Normal file
24
src/main/kotlin/com/aitrainer/api/model/Product.kt
Normal file
@ -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
|
||||
)
|
16
src/main/kotlin/com/aitrainer/api/model/ProductTest.kt
Normal file
16
src/main/kotlin/com/aitrainer/api/model/ProductTest.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 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
|
||||
)
|
18
src/main/kotlin/com/aitrainer/api/model/Purchase.kt
Normal file
18
src/main/kotlin/com/aitrainer/api/model/Purchase.kt
Normal file
@ -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
|
64
src/test/kotlin/com/aitrainer/api/test/ProductTestTest.kt
Normal file
64
src/test/kotlin/com/aitrainer/api/test/ProductTestTest.kt
Normal file
@ -0,0 +1,64 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
|
||||
import com.aitrainer.api.controller.ProductTestController
|
||||
import com.aitrainer.api.repository.ProductTestRepository
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import com.aitrainer.api.model.ProductTest
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
|
||||
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class ProductTestTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var productTestRepository: ProductTestRepository
|
||||
|
||||
|
||||
@Test
|
||||
fun testGetProductTests() {
|
||||
val list = productTestRepository.findByCustomerId(1)
|
||||
print("List $list")
|
||||
|
||||
val controller = ProductTestController(productTestRepository)
|
||||
val response = controller.getAllByCustomerId(62)
|
||||
|
||||
val productTest = response.body
|
||||
|
||||
print ("resp $response.body" )
|
||||
|
||||
assertTrue(productTest is List)
|
||||
assertTrue(productTest.isNotEmpty())
|
||||
assertEquals(productTest.size, 2)
|
||||
assertEquals(productTest[0].productId, 2)
|
||||
assertEquals(productTest[0].dateView, "2020-10-01 12:00:00")
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInsertProductTest() {
|
||||
val productTest = ProductTest(
|
||||
customerId = 2,
|
||||
productId = 2,
|
||||
dateView = "2020-11-01 12:00:00",
|
||||
purchaseClick = false
|
||||
)
|
||||
val controller = ProductTestController(productTestRepository)
|
||||
val response = controller.insertProductTest(productTest)
|
||||
|
||||
val productTestNew = response.body
|
||||
|
||||
assertTrue(productTestNew is ProductTest)
|
||||
assertEquals(productTestNew.productId, 2)
|
||||
assertEquals(productTestNew.customerId, 2)
|
||||
|
||||
productTestRepository.delete(productTestNew)
|
||||
|
||||
}
|
||||
|
||||
}
|
34
src/test/kotlin/com/aitrainer/api/test/ProductTesting.kt
Normal file
34
src/test/kotlin/com/aitrainer/api/test/ProductTesting.kt
Normal file
@ -0,0 +1,34 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import com.aitrainer.api.controller.ProductController
|
||||
import com.aitrainer.api.repository.ProductRepository
|
||||
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 ProductTesting {
|
||||
|
||||
@Autowired
|
||||
private lateinit var productRepository: ProductRepository
|
||||
|
||||
|
||||
@Test
|
||||
fun testGetProducts() {
|
||||
val controller = ProductController(productRepository)
|
||||
val response = controller.getAllProducts()
|
||||
|
||||
val products = response.body
|
||||
|
||||
assertTrue(products is List)
|
||||
assertTrue(products.isNotEmpty())
|
||||
assertEquals(products.size, 12)
|
||||
assertEquals(products[0].name, "Subscription A")
|
||||
|
||||
}
|
||||
|
||||
}
|
57
src/test/kotlin/com/aitrainer/api/test/PurchaseTest.kt
Normal file
57
src/test/kotlin/com/aitrainer/api/test/PurchaseTest.kt
Normal file
@ -0,0 +1,57 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import com.aitrainer.api.controller.PurchaseController
|
||||
import com.aitrainer.api.model.Purchase
|
||||
import com.aitrainer.api.repository.PurchaseRepository
|
||||
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 PurchaseTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var purchaseRepository: PurchaseRepository
|
||||
|
||||
|
||||
@Test
|
||||
fun testGetPurchaseByCustomerId() {
|
||||
val controller = PurchaseController(purchaseRepository)
|
||||
val response = controller.getAllByCustomerId(62)
|
||||
|
||||
val purchases = response.body
|
||||
|
||||
assertTrue(purchases is List)
|
||||
assertTrue(purchases.isNotEmpty())
|
||||
assertEquals(purchases.size, 2)
|
||||
assertEquals(purchases[0].productId, 1)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPurchaseInsert() {
|
||||
val purchase = Purchase(
|
||||
productId = 2,
|
||||
dateAdd = "2020-11-05 12:00:00",
|
||||
customerId = 1,
|
||||
purchaseSum = 2000.0,
|
||||
currency = "HUF"
|
||||
)
|
||||
|
||||
val controller = PurchaseController(purchaseRepository)
|
||||
val response = controller.insertPurchase(purchase)
|
||||
|
||||
val purchaseNew = response.body
|
||||
|
||||
assertEquals(purchaseNew!!.productId, 2)
|
||||
assertEquals(purchaseNew.customerId, 1)
|
||||
|
||||
//purchaseRepository.delete(purchaseNew)
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user