diff --git a/build.gradle.kts b/build.gradle.kts index aafc279..d33fb83 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.aitrainer" -version = "1.0.10" +version = "1.0.11" java.sourceCompatibility = JavaVersion.VERSION_1_8 repositories { diff --git a/data/db/install.sql b/data/db/install.sql index 6239da0..6dac830 100644 --- a/data/db/install.sql +++ b/data/db/install.sql @@ -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 */; diff --git a/data/db/update_1_0_11.sql b/data/db/update_1_0_11.sql new file mode 100644 index 0000000..81a9195 --- /dev/null +++ b/data/db/update_1_0_11.sql @@ -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"; \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/ProductController.kt b/src/main/kotlin/com/aitrainer/api/controller/ProductController.kt new file mode 100644 index 0000000..64b6b86 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/controller/ProductController.kt @@ -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> { + + val products = productRepository.findAll() + logger.info("Get all products") + + return if(products.isNotEmpty()) + ResponseEntity.ok().body(products) else + ResponseEntity.notFound().build() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/ProductControllerAspect.kt b/src/main/kotlin/com/aitrainer/api/controller/ProductControllerAspect.kt new file mode 100644 index 0000000..04014b7 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/controller/ProductControllerAspect.kt @@ -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) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/ProductTestController.kt b/src/main/kotlin/com/aitrainer/api/controller/ProductTestController.kt new file mode 100644 index 0000000..6dc02ac --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/controller/ProductTestController.kt @@ -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> { + + 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 { + val newProductTest = productTestRepository.save(productTest) + logger.info("Create new productTest: $newProductTest") + return ResponseEntity.ok().body(newProductTest) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/ProductTestControllerAspect.kt b/src/main/kotlin/com/aitrainer/api/controller/ProductTestControllerAspect.kt new file mode 100644 index 0000000..03fe875 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/controller/ProductTestControllerAspect.kt @@ -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) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/PurchaseController.kt b/src/main/kotlin/com/aitrainer/api/controller/PurchaseController.kt new file mode 100644 index 0000000..13e671e --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/controller/PurchaseController.kt @@ -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> { + + 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 { + val newPurchase = purchaseRepository.save(purchase) + logger.info("Create new purchase: $newPurchase") + return ResponseEntity.ok().body(newPurchase) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/PurchaseControllerAspect.kt b/src/main/kotlin/com/aitrainer/api/controller/PurchaseControllerAspect.kt new file mode 100644 index 0000000..fca8066 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/controller/PurchaseControllerAspect.kt @@ -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) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/Product.kt b/src/main/kotlin/com/aitrainer/api/model/Product.kt new file mode 100644 index 0000000..cc6b66f --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/Product.kt @@ -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 +) \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/ProductTest.kt b/src/main/kotlin/com/aitrainer/api/model/ProductTest.kt new file mode 100644 index 0000000..fc2e0d1 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/ProductTest.kt @@ -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 +) \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/Purchase.kt b/src/main/kotlin/com/aitrainer/api/model/Purchase.kt new file mode 100644 index 0000000..a09db4b --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/Purchase.kt @@ -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 = "" +) \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/repository/ProductRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/ProductRepository.kt new file mode 100644 index 0000000..d3e07e1 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/repository/ProductRepository.kt @@ -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 { +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/repository/ProductTestRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/ProductTestRepository.kt new file mode 100644 index 0000000..69a0896 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/repository/ProductTestRepository.kt @@ -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 { + fun findByCustomerId(customerId: Long): List +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/repository/PurchaseRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/PurchaseRepository.kt new file mode 100644 index 0000000..43e0220 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/repository/PurchaseRepository.kt @@ -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 { + fun findByCustomerId(customerId: Long): List +} \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 968d6ff..367e1a2 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -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 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9f01487..9799eb1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/ProductTestTest.kt b/src/test/kotlin/com/aitrainer/api/test/ProductTestTest.kt new file mode 100644 index 0000000..bbdadaa --- /dev/null +++ b/src/test/kotlin/com/aitrainer/api/test/ProductTestTest.kt @@ -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) + + } + +} \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/ProductTesting.kt b/src/test/kotlin/com/aitrainer/api/test/ProductTesting.kt new file mode 100644 index 0000000..5d86846 --- /dev/null +++ b/src/test/kotlin/com/aitrainer/api/test/ProductTesting.kt @@ -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") + + } + +} \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/PurchaseTest.kt b/src/test/kotlin/com/aitrainer/api/test/PurchaseTest.kt new file mode 100644 index 0000000..146acc0 --- /dev/null +++ b/src/test/kotlin/com/aitrainer/api/test/PurchaseTest.kt @@ -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) + + } + +} \ No newline at end of file