From f1aee3904f4f46c82a690e1f91bebf2736006af0 Mon Sep 17 00:00:00 2001 From: Bossanyi Tibor Date: Wed, 14 Apr 2021 21:54:09 +0200 Subject: [PATCH] API 1.0.30 CustomerActivity, Sort ExercisePlanTemplateDetail.sort --- build.gradle.kts | 4 +- data/db/install.sql | 12 +++ data/db/update_1_0_30.sql | 22 +++++ .../api/controller/ControllerAspect.kt | 6 -- .../controller/CustomerActivityController.kt | 21 ++++ .../api/controller/CustomerController.kt | 56 +++++------ .../CustomerInformationController.kt | 21 ---- .../controller/CustomerPackageController.kt | 9 +- .../com/aitrainer/api/model/Customer.kt | 23 ++--- .../aitrainer/api/model/CustomerActivity.kt | 17 ++++ .../api/model/CustomerInformation.kt | 21 ---- .../api/model/ExercisePlanTemplateDetail.kt | 3 +- .../repository/CustomerActivityRepository.kt | 15 +++ .../CustomerInformationRepository.kt | 11 --- .../api/test/AppCustomerPackageTest.kt | 99 +++++++++++-------- .../com/aitrainer/api/test/AppPackageTest.kt | 3 +- .../api/test/CustomerActivityTest.kt | 50 ++++++++++ .../api/test/CustomerInformationTest.kt | 24 ----- .../com/aitrainer/api/test/CustomerTests.kt | 98 ++++++------------ .../com/aitrainer/api/test/EvaluationTest.kt | 2 +- 20 files changed, 281 insertions(+), 236 deletions(-) create mode 100644 data/db/update_1_0_30.sql create mode 100644 src/main/kotlin/com/aitrainer/api/controller/CustomerActivityController.kt delete mode 100644 src/main/kotlin/com/aitrainer/api/controller/CustomerInformationController.kt create mode 100644 src/main/kotlin/com/aitrainer/api/model/CustomerActivity.kt delete mode 100644 src/main/kotlin/com/aitrainer/api/model/CustomerInformation.kt create mode 100644 src/main/kotlin/com/aitrainer/api/repository/CustomerActivityRepository.kt delete mode 100644 src/main/kotlin/com/aitrainer/api/repository/CustomerInformationRepository.kt create mode 100644 src/test/kotlin/com/aitrainer/api/test/CustomerActivityTest.kt delete mode 100644 src/test/kotlin/com/aitrainer/api/test/CustomerInformationTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index 70e832a..66807c2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.aitrainer" -version = "1.0.29" +version = "1.0.30" java.sourceCompatibility = JavaVersion.VERSION_1_8 repositories { @@ -27,7 +27,6 @@ dependencies { implementation("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.4.4") implementation("org.springframework.security.oauth:spring-security-oauth2:2.5.0.RELEASE") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") - implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.apache.logging.log4j:log4j-core:2.14.0") implementation("org.apache.logging.log4j:log4j-api:2.14.0") @@ -37,6 +36,7 @@ dependencies { implementation("org.yaml:snakeyaml:1.27") implementation("com.google.code.gson:gson:2.8.6") implementation("org.projectlombok:lombok:1.18.16") + implementation("org.jetbrains.kotlin:kotlin-reflect:1.4.32") runtimeOnly("mysql:mysql-connector-java") testImplementation("org.springframework.boot:spring-boot-starter-test") { diff --git a/data/db/install.sql b/data/db/install.sql index c187ce3..23558ee 100644 --- a/data/db/install.sql +++ b/data/db/install.sql @@ -966,6 +966,7 @@ CREATE TABLE `exercise_plan_template_detail` ( `quantity_unit_quantity` DOUBLE NULL DEFAULT '0', `serie` INT(11) NULL DEFAULT '0', `resting_time` TIME NULL DEFAULT '00:00:00', + `sort` TINYINT(2) NULL DEFAULT NULL, PRIMARY KEY (`exercise_plan_template_detail_id`) USING BTREE, INDEX `exercise_type_id` (`exercise_type_id`) USING BTREE, INDEX `exercise_plan_template_id` (`exercise_plan_template_id`) USING BTREE @@ -1030,6 +1031,17 @@ INSERT INTO `evaluation_attribute` (`evaluation_attr_id`, `evaluation_id`, `name INSERT INTO `evaluation_attribute` (`evaluation_attr_id`, `evaluation_id`, `name`, `age_min`, `age_max`, `value_min`, `value_max`, `sex`, `evaluation_text`, `suggestion`) VALUES (9, 1, 'Fekvőtámasz_ffi_17-19_elite', 17, 19, 100, 100000, 'm', 'excellent', NULL); INSERT INTO `evaluation_attribute` (`evaluation_attr_id`, `evaluation_id`, `name`, `age_min`, `age_max`, `value_min`, `value_max`, `sex`, `evaluation_text`, `suggestion`) VALUES (10, 1, 'Fekvőtámasz_ffi_20-29_very_poor', 20, 29, 0, 4, 'm', 'very_poor', NULL); +CREATE TABLE `customer_activity` ( + `activity_id` INT(11) NOT NULL AUTO_INCREMENT, + `customer_id` INT(14) NOT NULL DEFAULT '0', + `type` CHAR(50) NOT NULL COLLATE 'utf8_hungarian_ci', + `date_add` DATETIME NOT NULL, + `skipped` TINYINT(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`activity_id`) USING BTREE +) +COLLATE='utf8_hungarian_ci' +ENGINE=InnoDB +; /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; diff --git a/data/db/update_1_0_30.sql b/data/db/update_1_0_30.sql new file mode 100644 index 0000000..4ca9c77 --- /dev/null +++ b/data/db/update_1_0_30.sql @@ -0,0 +1,22 @@ +START TRANSACTION; + +ALTER TABLE `exercise_plan_template_detail` + ADD COLUMN `sort` TINYINT(2) NULL DEFAULT NULL AFTER `resting_time`; + +CREATE TABLE `customer_activity` ( + `activity_id` INT(11) NOT NULL AUTO_INCREMENT, + `customer_id` INT(14) NOT NULL DEFAULT '0', + `type` CHAR(50) NOT NULL COLLATE 'utf8_hungarian_ci', + `date_add` DATETIME NOT NULL, + `skipped` TINYINT(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`activity_id`) USING BTREE +) +COLLATE='utf8_hungarian_ci' +ENGINE=InnoDB +; + + +UPDATE configuration set config_value = "1.0.30", date_change=CURRENT_DATE WHERE config_key = "db_version"; + +COMMIT; + diff --git a/src/main/kotlin/com/aitrainer/api/controller/ControllerAspect.kt b/src/main/kotlin/com/aitrainer/api/controller/ControllerAspect.kt index 4f6c1a3..024f051 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/ControllerAspect.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/ControllerAspect.kt @@ -28,12 +28,6 @@ class ControllerAspect { 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") diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerActivityController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerActivityController.kt new file mode 100644 index 0000000..be2bd47 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerActivityController.kt @@ -0,0 +1,21 @@ +package com.aitrainer.api.controller + +import com.aitrainer.api.model.CustomerActivity +import com.aitrainer.api.repository.CustomerActivityRepository +import org.slf4j.LoggerFactory +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.* +import javax.validation.Valid + +@RestController +@RequestMapping("/api") +class CustomerActivityController(private val customerActivityRepository: CustomerActivityRepository) { + private val logger = LoggerFactory.getLogger(javaClass) + + @PostMapping("/customer_activity") + fun insertActivity(@Valid @RequestBody customerActivity: CustomerActivity): ResponseEntity { + val newActivity = customerActivityRepository.save(customerActivity) + logger.info("Create new activity: $newActivity") + return ResponseEntity.ok().body(newActivity) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt index 855bf18..605e0a6 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt @@ -92,34 +92,31 @@ class CustomerController ( private val customerRepository: CustomerRepository) { val returnCustomer: Customer = customerRepository.findById(customerId).orElse(null) ?: return ResponseEntity.notFound().build() - val password: String? = newCustomer.password - val updatedCustomer: Customer - if ( password == null || password.isEmpty() ) { - updatedCustomer = - returnCustomer.copy( - name = newCustomer.name, - firstname = newCustomer.firstname, - sex = newCustomer.sex, - birthYear = newCustomer.birthYear, - fitnessLevel = newCustomer.fitnessLevel, - bodyType = newCustomer.bodyType, - goal = newCustomer.goal, - dateChange = newCustomer.dateChange - ) - } else { - updatedCustomer = - returnCustomer.copy( - name = newCustomer.name, - firstname = newCustomer.firstname, - password = newCustomer.password, - sex = newCustomer.sex, - birthYear = newCustomer.birthYear, - fitnessLevel = newCustomer.fitnessLevel, - bodyType = newCustomer.bodyType, - goal = newCustomer.goal, - dateChange = newCustomer.dateChange - ) - } + val updatedCustomer = returnCustomer.copy() + if (newCustomer.email != null) { + updatedCustomer.email = newCustomer.email + } + if (newCustomer.name != null) { + updatedCustomer.name = newCustomer.name + } + if (newCustomer.firstname != null) { + updatedCustomer.firstname = newCustomer.firstname + } + if (newCustomer.goal != null) { + updatedCustomer.goal = newCustomer.goal + } + if (newCustomer.dateChange != null) { + updatedCustomer.dateChange = newCustomer.dateChange + } + if (newCustomer.dataPolicyAllowed != null) { + updatedCustomer.dataPolicyAllowed = newCustomer.dataPolicyAllowed + } + updatedCustomer.sex = newCustomer.sex + updatedCustomer.birthYear = newCustomer.birthYear + updatedCustomer.fitnessLevel = newCustomer.fitnessLevel + + + return ResponseEntity.ok().body(customerRepository.save(updatedCustomer)) } @@ -139,6 +136,9 @@ class CustomerController ( private val customerRepository: CustomerRepository) { password = serviceBeans!!.passwordEncoder().encode(newUser.password) firebaseUid = newUser.firebaseUid dateAdd = nowFormatted + firstname = "" + name = "" + email = "" } val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let { diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerInformationController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerInformationController.kt deleted file mode 100644 index a5d9882..0000000 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerInformationController.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.aitrainer.api.controller - -import com.aitrainer.api.model.CustomerInformation -import com.aitrainer.api.repository.CustomerInformationRepository -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController -import java.time.LocalDateTime - -@RestController -@RequestMapping("/api") -class CustomerInformationController( private val customerInformationRepository: CustomerInformationRepository ) { - - @GetMapping("/customer_information") - fun getCustomerInformation(): List { - val dateTime: String = LocalDateTime.now().toString() - return customerInformationRepository.findByDisplayBeginLessThanAndDisplayEndGreaterThan(dateTime, dateTime ) - } - - -} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerPackageController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerPackageController.kt index 7c4e9ef..6f5770f 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerPackageController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerPackageController.kt @@ -17,7 +17,8 @@ class CustomerPackageController( private val customerRepository: CustomerReposit private val productTestRepository: ProductTestRepository, private val purchaseRepository: PurchaseRepository, private val customerPropertyRepository: CustomerPropertyRepository, - private val exerciseResultRepository: ExerciseResultRepository) { + private val exerciseResultRepository: ExerciseResultRepository, + private val customerActivityRepository: CustomerActivityRepository) { @GetMapping("/app_customer_package/{id}") fun getCustomerPackageData(@PathVariable(value = "id") customerId: Long): ResponseEntity { @@ -56,6 +57,9 @@ class CustomerPackageController( private val customerRepository: CustomerReposit val listExerciseResult = exerciseResultRepository.getAllByCustomerId(customerId) val listExerciseResultJson = gson.toJson(listExerciseResult) + val listActivityResult = customerActivityRepository.findByCustomerId(customerId) + val listActivityJson = gson.toJson(listActivityResult) + val packageJson: String = getClassRecord(Customer::class.simpleName, customerJson) + "|||" + getClassRecord(CustomerExerciseDevice::class.simpleName, listCustomerExerciseDeviceJson) + @@ -64,7 +68,8 @@ class CustomerPackageController( private val customerRepository: CustomerReposit "|||" + getClassRecord(Purchase::class.simpleName, listPurchaseJson) + "|||" + getClassRecord(CustomerProperty::class.simpleName+"All", listCustomerPropertyAllJson) + "|||" + getClassRecord(CustomerProperty::class.simpleName, listCustomerPropertyJson) + - "|||" + getClassRecord(ExerciseResult::class.simpleName, listExerciseResultJson) + "|||" + getClassRecord(ExerciseResult::class.simpleName, listExerciseResultJson+ + "|||" + getClassRecord(CustomerActivity::class.simpleName, listActivityJson)) return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(packageJson) diff --git a/src/main/kotlin/com/aitrainer/api/model/Customer.kt b/src/main/kotlin/com/aitrainer/api/model/Customer.kt index d426e58..13dfab5 100644 --- a/src/main/kotlin/com/aitrainer/api/model/Customer.kt +++ b/src/main/kotlin/com/aitrainer/api/model/Customer.kt @@ -1,29 +1,30 @@ package com.aitrainer.api.model import com.google.gson.annotations.Expose +import org.hibernate.annotations.Fetch +import org.hibernate.annotations.FetchMode import javax.persistence.* @Entity data class Customer ( - @Expose var name: String = "", - @Expose var firstname: String = "", - @Expose var email: String = "", + @Expose var name: String? = null, + @Expose var firstname: String? = null, + @Expose var email: String? = null, @Expose var age: Int? = 0, @Expose var sex: String = "m", - @Expose var active: String = "N", + @Expose var active: String = "Y", @Expose var dateAdd: String? = null, @Expose var dateChange: String? = null, - @Expose var dataPolicyAllowed: Int = 0, - @Expose var admin: Int = 0, - @Expose var trainer: Int = 0, - @Expose var trainerId: Long = 0, - @Expose var password: String? = "", + @Expose var dataPolicyAllowed: Int? = 1, + @Expose var admin: Boolean? = null, + @Expose var trainer: Boolean? = null, + @Expose var trainerId: Long? = null, + @Expose var password: String? = null, @Expose var birthYear:Int = 0, @Expose var goal: String? = null, @Expose var fitnessLevel: String = "beginner", @Expose var bodyType: String? = null, @Expose var firebaseUid: String? = null, - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Expose var customerId: Long = 0 + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose var customerId: Long = 0 ) diff --git a/src/main/kotlin/com/aitrainer/api/model/CustomerActivity.kt b/src/main/kotlin/com/aitrainer/api/model/CustomerActivity.kt new file mode 100644 index 0000000..cdc365f --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/CustomerActivity.kt @@ -0,0 +1,17 @@ +package com.aitrainer.api.model + +import com.fasterxml.jackson.annotation.JsonIgnore +import com.google.gson.annotations.Expose +import javax.persistence.* +import javax.validation.constraints.NotNull + +@Entity +data class CustomerActivity ( + @Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var activityId: Long = 0, + @Expose @get: NotNull var customerId: Long?, + @Expose @get: NotNull var type: String? = null, + @Expose @get: NotNull var dateAdd: String? = null, + @Expose @get: NotNull var skipped: Boolean? + +) + diff --git a/src/main/kotlin/com/aitrainer/api/model/CustomerInformation.kt b/src/main/kotlin/com/aitrainer/api/model/CustomerInformation.kt deleted file mode 100644 index 493ada5..0000000 --- a/src/main/kotlin/com/aitrainer/api/model/CustomerInformation.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.aitrainer.api.model - -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.GenerationType -import javax.persistence.Id -import javax.validation.constraints.NotBlank - -@Entity -class CustomerInformation ( - @get: NotBlank var title: String = "", - var description: String = "", - - var dateAdd: String? = null, - var displayBegin: String? = null, - var displayEnd: String? = null, - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - val customerInformationId: Long = 0 -) \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/ExercisePlanTemplateDetail.kt b/src/main/kotlin/com/aitrainer/api/model/ExercisePlanTemplateDetail.kt index cae2058..493c103 100644 --- a/src/main/kotlin/com/aitrainer/api/model/ExercisePlanTemplateDetail.kt +++ b/src/main/kotlin/com/aitrainer/api/model/ExercisePlanTemplateDetail.kt @@ -13,7 +13,8 @@ data class ExercisePlanTemplateDetail ( @Expose @get: Null var serie: Int? = 0, @Expose @get: Null var quantity: Double? = 0.0, @Expose @get: Null var quantityUnitQuantity: Double? = 0.0, - @Expose @get: NonNull var restingTime: String? = null + @Expose @get: NonNull var restingTime: String? = null, + @Expose @get: Null var sort: Int? = 0, ) { diff --git a/src/main/kotlin/com/aitrainer/api/repository/CustomerActivityRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/CustomerActivityRepository.kt new file mode 100644 index 0000000..1d79ae5 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/repository/CustomerActivityRepository.kt @@ -0,0 +1,15 @@ +package com.aitrainer.api.repository + +import com.aitrainer.api.model.CustomerActivity +import com.aitrainer.api.model.CustomerExerciseDevice +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query +import org.springframework.stereotype.Repository + +@Repository +interface CustomerActivityRepository: JpaRepository { + @Query(" FROM CustomerActivity " + + " WHERE customerId = :customerId" + ) + fun findByCustomerId(customerId: Long): List +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/repository/CustomerInformationRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/CustomerInformationRepository.kt deleted file mode 100644 index 3e3f87f..0000000 --- a/src/main/kotlin/com/aitrainer/api/repository/CustomerInformationRepository.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.aitrainer.api.repository - -import com.aitrainer.api.model.CustomerInformation -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.stereotype.Repository - -@Repository -interface CustomerInformationRepository: JpaRepository { - fun findByDisplayBeginLessThanAndDisplayEndGreaterThan( dateTimeBegin: String, dateTimeEnd: String ): - List -} \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/AppCustomerPackageTest.kt b/src/test/kotlin/com/aitrainer/api/test/AppCustomerPackageTest.kt index 77442f3..7862b14 100644 --- a/src/test/kotlin/com/aitrainer/api/test/AppCustomerPackageTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/AppCustomerPackageTest.kt @@ -39,13 +39,16 @@ class AppCustomerPackageTest { @Autowired private lateinit var exerciseResultRepository: ExerciseResultRepository + @Autowired + private lateinit var customerActivityRepository: CustomerActivityRepository + @Test fun customerPackageTest() { val gson = Gson() val controller = CustomerPackageController(customerRepository, customerExerciseDeviceRepository, exercisesRepository, productTestRepository, purchaseRepository, customerPropertyRepository, - exerciseResultRepository) + exerciseResultRepository, customerActivityRepository ) var response: ResponseEntity<*> = controller.getCustomerPackageData(91) assertEquals(response.statusCode, HttpStatus.NOT_FOUND) @@ -61,46 +64,60 @@ class AppCustomerPackageTest { packages.forEach { val record = it.split("***") print(record[0] + "\n") - if (record[0] == Customer::class.simpleName) { - val customerJson: String = record[1] - val type = object : TypeToken() {}.type - val customer: Customer = gson.fromJson(customerJson, type) - assertEquals(customer.email, "sw@andio.biz") - assertEquals(customer.birthYear, 1972) - } else if (record[0] == Exercises::class.simpleName) { - val exercisesJson: String = record[1] - val type = object : TypeToken?>() {}.type - val exerciseList: List = gson.fromJson(exercisesJson, type) - assertTrue(exerciseList.isNotEmpty()) - assertEquals(exerciseList[0].exerciseTypeId, 2) - assertEquals(exerciseList[0].quantity, 34.0) - } else if (record[0] == CustomerExerciseDevice::class.simpleName) { - val exerciseDeviceJson: String = record[1] - val type = object : TypeToken?>() {}.type - val customerExerciseDeviceList: List = gson.fromJson(exerciseDeviceJson, type) - assertTrue(customerExerciseDeviceList.isNotEmpty()) - assertEquals(customerExerciseDeviceList[1].exerciseDeviceId,2) - } else if (record[0] == ProductTest::class.simpleName) { - val productTestJson: String = record[1] - val type = object : TypeToken?>() {}.type - val productTestList: List = gson.fromJson(productTestJson, type) - assertTrue(productTestList.isNotEmpty()) - assertEquals(productTestList[0].productId,1) - } else if (record[0] == CustomerProperty::class.simpleName) { - //actual values - val propertyJson: String = record[1] - val type = object : TypeToken?>() {}.type - val propertyList: List = gson.fromJson(propertyJson, type) - assertTrue(propertyList.isNotEmpty()) - assertEquals(propertyList[2].propertyId,4) - assertEquals(propertyList[2].propertyValue,37.0) - } else if (record[0] == CustomerProperty::class.simpleName+"All") { - val propertyJson: String = record[1] - val type = object : TypeToken?>() {}.type - val propertyList: List = gson.fromJson(propertyJson, type) - assertTrue(propertyList.isNotEmpty()) - assertEquals(propertyList[1].propertyId,1) - assertEquals(propertyList[1].propertyValue,82.0) + when { + record[0] == Customer::class.simpleName -> { + val customerJson: String = record[1] + val type = object : TypeToken(){}.type + val customer: Customer = gson.fromJson(customerJson, type) + assertEquals(customer.email, "sw@andio.biz") + assertEquals(customer.birthYear, 1972) + } + record[0] == Exercises::class.simpleName -> { + val exercisesJson: String = record[1] + val type = object : TypeToken?>() {}.type + val exerciseList: List = gson.fromJson(exercisesJson, type) + assertTrue(exerciseList.isNotEmpty()) + assertEquals(exerciseList[0].exerciseTypeId, 2) + assertEquals(exerciseList[0].quantity, 34.0) + } + record[0] == CustomerExerciseDevice::class.simpleName -> { + val exerciseDeviceJson: String = record[1] + val type = object : TypeToken?>() {}.type + val customerExerciseDeviceList: List = gson.fromJson(exerciseDeviceJson, type) + assertTrue(customerExerciseDeviceList.isNotEmpty()) + assertEquals(customerExerciseDeviceList[1].exerciseDeviceId,2) + } + record[0] == ProductTest::class.simpleName -> { + val productTestJson: String = record[1] + val type = object : TypeToken?>() {}.type + val productTestList: List = gson.fromJson(productTestJson, type) + assertTrue(productTestList.isNotEmpty()) + assertEquals(productTestList[0].productId,1) + } + record[0] == CustomerProperty::class.simpleName -> { + //actual values + val propertyJson: String = record[1] + val type = object : TypeToken?>() {}.type + val propertyList: List = gson.fromJson(propertyJson, type) + assertTrue(propertyList.isNotEmpty()) + assertEquals(propertyList[2].propertyId,4) + assertEquals(propertyList[2].propertyValue,37.0) + } + record[0] == CustomerProperty::class.simpleName+"All" -> { + val propertyJson: String = record[1] + val type = object : TypeToken?>() {}.type + val propertyList: List = gson.fromJson(propertyJson, type) + assertTrue(propertyList.isNotEmpty()) + assertEquals(propertyList[1].propertyId,1) + assertEquals(propertyList[1].propertyValue,82.0) + } + record[0] == CustomerActivity::class.simpleName+"All" -> { + val activityJson: String = record[1] + val type = object : TypeToken?>() {}.type + val activityList: List = gson.fromJson(activityJson, type) + assertTrue(activityList.isNotEmpty()) + assertEquals(activityList[0].type,"basic_tutorial") + } } } diff --git a/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt b/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt index 4d56545..ef36900 100644 --- a/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt @@ -102,6 +102,7 @@ class AppPackageTest { assertEquals(listTemplate[0].translations[0].name, "Saját testes tesztek") assertEquals(listTemplate[0].details[0].exerciseTypeId, 2) assertEquals(listTemplate[1].details[1].exerciseTypeId, 33) + assertEquals(listTemplate[1].details[1].sort, 2) } else if (record[0] == Evaluation::class.simpleName) { val evaluationJson: String = record[1] val type = object : TypeToken?>() {}.type @@ -109,7 +110,7 @@ class AppPackageTest { assertTrue(evaluations.isNotEmpty()) assertEquals(evaluations.size, 2) assertEquals(evaluations[0].name, "PushUps") - assertEquals(evaluations[0].attributes.size, 10) + assertEquals(evaluations[0].attributes.size, 18) assertEquals(evaluations[0].attributes[1].name, "Fekvőtámasz_ffi_17-19_fair") } } diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerActivityTest.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerActivityTest.kt new file mode 100644 index 0000000..dcbedf6 --- /dev/null +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerActivityTest.kt @@ -0,0 +1,50 @@ +package com.aitrainer.api.test + +import com.aitrainer.api.controller.CustomerActivityController +import com.aitrainer.api.controller.CustomerExerciseDeviceController +import com.aitrainer.api.controller.PurchaseController +import com.aitrainer.api.model.Customer +import com.aitrainer.api.model.CustomerActivity +import com.aitrainer.api.model.CustomerExerciseDevice +import com.aitrainer.api.repository.CustomerActivityRepository +import com.aitrainer.api.repository.CustomerExerciseDeviceRepository +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 org.springframework.http.HttpStatus +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +@SpringBootTest +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class CustomerActivityTest { + + @Autowired + private lateinit var customerActivityRepository: CustomerActivityRepository + + + @Test + fun testActivityInsert() { + val customerActivity = CustomerActivity( + customerId = 90, + skipped = false, + dateAdd = "2021-04-13 04:32:00", + type = "compact_test_tutorial" + ) + + + val controller = CustomerActivityController(customerActivityRepository) + val response = controller.insertActivity(customerActivity) + + val newActivity = response.body + + assertEquals(newActivity!!.customerId, 90) + assertEquals(newActivity.skipped, false) + assertEquals(newActivity.type, "compact_test_tutorial") + + customerActivityRepository.delete(newActivity) + } + + +} \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerInformationTest.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerInformationTest.kt deleted file mode 100644 index 0666d40..0000000 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerInformationTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.aitrainer.api.test - -import com.aitrainer.api.model.CustomerInformation -import com.aitrainer.api.repository.CustomerInformationRepository -import org.junit.jupiter.api.Test -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import kotlin.test.assertEquals - -@SpringBootTest -class CustomerInformationTest { - - @Autowired - private lateinit var customerInformationRepository: CustomerInformationRepository - - @Test - fun getActiveCustomerInformation() { - val dateTime = "2020-06-01 09:00:00" - val info: List = this.customerInformationRepository. - findByDisplayBeginLessThanAndDisplayEndGreaterThan(dateTime, dateTime ) - assertEquals(info.size, 2) - assertEquals(info.first().title, "Fekvőtámasz világcsúcs") - } -} \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt index ff6a9a2..403ef56 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt @@ -51,6 +51,7 @@ class CustomerTests { assertNotNull (customer2) assertEquals(customer2.email, "sw@andio.biz") + assertEquals(customer2.dataPolicyAllowed, 1) } @Test @@ -101,7 +102,7 @@ class CustomerTests { customer.customerId = id customer.firstname = "Tib" customer.name = "Bossi" - customer.admin = 1 + customer.admin = true customer.active = "Y" customer.sex = "m" @@ -110,12 +111,21 @@ class CustomerTests { customer.dataPolicyAllowed = 1 customer.fitnessLevel = "advanced" customer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) + customer.email = "mr@aitrainer.app" - val updatedCustomer = customerRepository.save(customer) + + var updatedCustomer = customerRepository.save(customer) assertEquals(updatedCustomer.customerId, 90) assertEquals(updatedCustomer.birthYear, 1972) assertEquals(updatedCustomer.fitnessLevel, "advanced") assertTrue(customer.dateChange != null) + assertEquals(updatedCustomer.email, "mr@aitrainer.app") + assertEquals(updatedCustomer.dataPolicyAllowed, 1) + + + customer.email = "sw@andio.biz" + updatedCustomer = customerRepository.save(customer) + assertEquals(updatedCustomer.email, "sw@andio.biz") } @Test @@ -129,7 +139,7 @@ class CustomerTests { customer.password = null customer.firstname = "Tib" customer.name = "Bossi" - customer.admin = 1 + customer.admin = true customer.sex = "m" customer.fitnessLevel = "intermediate" //customer.weight = 79 @@ -142,9 +152,9 @@ class CustomerTests { var newCustomer: Customer? = response.body as Customer assertEquals(response.statusCode, HttpStatus.OK) //assertEquals(newCustomer?.weight, 79) - assertEquals(newCustomer!!.password, "123456789") - assertEquals(newCustomer.firstname, "Tib") + assertEquals(newCustomer!!.firstname, "Tib") assertTrue(newCustomer.dateChange != null) + assertEquals(newCustomer.email, "sw@andio.biz") // test not found id = 1000 @@ -154,21 +164,30 @@ class CustomerTests { // update Password id = 103 - customer.password = "blabal" + // customer.password = "blabal" customer.firstname = "Kakadu" customer.name = "Bos" + customer.email = "mr@aitrainer.app" response = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) ) assertEquals(response.statusCode, HttpStatus.OK) newCustomer = response.body as Customer - assertEquals(newCustomer.password, "blabal") + //assertEquals(newCustomer.password, "blabal") assertEquals(newCustomer.firstname, "Kakadu") assertEquals(newCustomer.name, "Bos") + assertEquals(newCustomer.email, "mr@aitrainer.app") + assertEquals(newCustomer.dataPolicyAllowed, 1) + + val customer2 = newCustomer.copy() + customer2.email = "sw2@andio.biz" + customer2.customerId = 103 + val updatedCustomer = customerRepository.save(customer2) + assertEquals(updatedCustomer.email, "sw2@andio.biz") } @Test fun testRegistration() { - val json = "{\"username\":\"bosi2@example.com\",\"password\":\"94385\",\"firebaseUid\":\"3Firebase8Uid\"}" + val json = "{\"username\":\"bosi2@example.com\",\"password\":\"94385\",\"firebaseUid\":\"3Firebase8Uid1\"}" val user: User = User().fromJson(json) assertEquals(user.username, "bosi2@example.com") val customer = Customer() @@ -179,16 +198,16 @@ class CustomerTests { } val customerController = CustomerController(customerRepository) customerController.serviceBeans = serviceBean - var response: ResponseEntity<*> = customerController.registration(json) + val response: ResponseEntity<*> = customerController.registration(json) print("body " + response.body) val newCustomer: Customer = response.body as Customer assertEquals(response.statusCode, HttpStatus.OK) - assertEquals(newCustomer.firebaseUid, "3Firebase8Uid") + assertEquals(newCustomer.firebaseUid, "3Firebase8Uid1") assertTrue(newCustomer.dateAdd != null) - val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid\"}" +/* val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid3\"}" response = customerController.registration(json2) - assertEquals(response.statusCode, HttpStatus.BAD_REQUEST) + assertEquals(response.statusCode, HttpStatus.BAD_REQUEST)*/ customerRepository.delete(newCustomer) } @@ -210,7 +229,7 @@ class CustomerTests { assertEquals(newCustomer2.name, "Bossanyi2") assertEquals(newCustomer2.age, 48) - customerRepository.delete(newCustomer) + customerRepository.delete(newCustomer2) } @Test @@ -240,57 +259,4 @@ class CustomerTests { } - /*@Test - fun testAddCustomerExerciseDevice() { - val customer: Customer = customerRepository.findById(103) .orElse(null) - val customerExerciseDevice = CustomerExerciseDevice( - exerciseDeviceId = 1, - favourite = false, - dateAdd = "2020-11-23 20:00" - ) - customerExerciseDevice.customer = customer - val listDevice : List = listOf(customerExerciseDevice) - - customer.exerciseDevices = listDevice - val newCustomer: Customer = customerRepository.save(customer) - - assertEquals(newCustomer.email, "sw2@andio.biz") - assertEquals(newCustomer.exerciseDevices.size, 1) - assertEquals(newCustomer.exerciseDevices[0].exerciseDeviceId, 1) - - val deletedList: List = listOf() - customer.exerciseDevices = deletedList - val newCustomer2 = customerRepository.save(customer) - assertEquals(newCustomer2.email, "sw2@andio.biz") - assertEquals(newCustomer2.exerciseDevices.size, 0) - - } -*/ - /*@Test fun _testLogin() { - val json = "{\"username\":\"bosi2@example.com\",\"password\":\"94333385\"}" - val user: User = User().fromJson(json) - val customer = Customer() - with(customer) { - email = user.username - password = user.password - } - val customerController = CustomerController(customerRepository) - customerController.serviceBeans = serviceBean - var response: ResponseEntity<*> = customerController.registration(json) - val newCustomer: Customer? = response.body as Customer - assertEquals(response.statusCode, HttpStatus.OK) - - response = customerController.login(json) - val loginedCustomer: Customer? = response.body as Customer - assertEquals(response.statusCode, HttpStatus.OK) - if ( loginedCustomer != null ) { - assertEquals(loginedCustomer.email, ("bosi2@example.com") ) - } else { - assert(true) - } - - if ( newCustomer != null) { - customerRepository.delete(newCustomer) - } - }*/ } \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/EvaluationTest.kt b/src/test/kotlin/com/aitrainer/api/test/EvaluationTest.kt index 2d8e986..b2492e2 100644 --- a/src/test/kotlin/com/aitrainer/api/test/EvaluationTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/EvaluationTest.kt @@ -30,7 +30,7 @@ class EvaluationTest { assertTrue(evaluations.isNotEmpty()) assertEquals(evaluations.size, 2) assertEquals(evaluations[0].name, "PushUps") - assertEquals(evaluations[0].attributes.size, 10) + assertEquals(evaluations[0].attributes.size, 18) assertEquals(evaluations[0].attributes[0].name, "Fekvőtámasz_ffi_17-19_very_poor") }