diff --git a/build.gradle.kts b/build.gradle.kts index 66807c2..15907da 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.aitrainer" -version = "1.0.30" +version = "1.0.31" java.sourceCompatibility = JavaVersion.VERSION_1_8 repositories { diff --git a/data/db/install.sql b/data/db/install.sql index fb11921..9f280a9 100644 --- a/data/db/install.sql +++ b/data/db/install.sql @@ -279,31 +279,31 @@ CREATE TABLE IF NOT EXISTS `customer` ( `fitness_level` enum('beginner','intermediate','advanced','professional') COLLATE utf8_hungarian_ci NOT NULL DEFAULT 'beginner', `body_type` enum('ectomorph','mesomorph','endomorph') COLLATE utf8_hungarian_ci DEFAULT NULL, `firebase_uid` char(50) COLLATE utf8_hungarian_ci DEFAULT NULL, + `sport_id` INT(13) NULL DEFAULT NULL, + `email_subscription` TINYINT(1) NULL DEFAULT 0, PRIMARY KEY (`customer_id`), UNIQUE KEY `firebase_uid` (`firebase_uid`) -) ENGINE=InnoDB AUTO_INCREMENT=475 DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; +) ENGINE=InnoDB AUTO_INCREMENT=140 DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; -- Tábla adatainak mentése aitrainer2.customer: ~17 rows (hozzávetőleg) -/*!40000 ALTER TABLE `customer` DISABLE KEYS */; -REPLACE INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES - (1, 'Átlag 13 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', NULL, 'firebaseuid_customer_1'), - (2, 'Átlag 14 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (3, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (4, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', NULL, NULL), - (5, 'Átlag 16 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (6, 'Átlag 17 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (7, 'Átlag 18 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (8, 'Átlag 13 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (9, 'Átlag 14 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (10, 'Átlag 15 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (11, 'Átlag 16 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (12, 'Átlag 17 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (13, 'Átlag 18 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (54, 'Dummy User', '', 'bosi', '$2a$10$thOc8jS750c7xe9U9Qq3GuSPs/H0Pt2Ads05yzUlyzQBIj.Rk9QCy', 'm', 0, 'N', NULL, NULL, 1, 1, 0, 0, 0, 0, '', 'beginner', NULL, NULL), - (90, 'Bossi', 'Tib', 'sw@andio.biz', '123456', 'm', 0, 'Y', NULL, '2021-04-14 22:42:33', 1, 1, 0, 0, 1972, 79, NULL, 'advanced', 'endomorph', NULL), - (103, 'Bos', 'Kakadu', 'sw2@andio.biz', NULL, 'm', 0, 'Y', NULL, '2021-04-14 22:42:33', 1, 1, 0, 137, 1972, 79, NULL, 'intermediate', NULL, '3FirebaseU1d'), - (137, 'Robert', '', NULL, NULL, 'm', NULL, 'N', NULL, NULL, 1, 0, 1, 0, 0, 0, '', 'beginner', NULL, NULL); -/*!40000 ALTER TABLE `customer` ENABLE KEYS */; +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (1, 'Átlag 13 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', NULL, 'firebaseuid_customer_1', NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (2, 'Átlag 14 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (3, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (4, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (5, 'Átlag 16 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (6, 'Átlag 17 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (7, 'Átlag 18 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (8, 'Átlag 13 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (9, 'Átlag 14 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (10, 'Átlag 15 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (11, 'Átlag 16 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (12, 'Átlag 17 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (13, 'Átlag 18 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (54, 'Dummy User', '', 'bosi', '$2a$10$thOc8jS750c7xe9U9Qq3GuSPs/H0Pt2Ads05yzUlyzQBIj.Rk9QCy', 'm', 0, 'N', NULL, NULL, 1, 1, 0, 0, 0, 0, '', 'beginner', NULL, NULL, NULL, NULL); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (90, 'Bossi', 'Tib', 'sw@andio.biz', '123456', 'm', 0, 'Y', NULL, '2021-04-19 20:42:31', 1, 1, 0, 0, 1972, 79, NULL, 'advanced', 'endomorph', NULL, 2, 1); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (103, 'Bos', 'Kakadu', 'sw2@andio.biz', NULL, 'm', 0, 'Y', NULL, '2021-04-19 20:42:31', 1, 1, 0, 137, 1972, 79, NULL, 'intermediate', NULL, '3FirebaseU1d', 0, 0); +INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`, `sport_id`, `email_subscription`) VALUES (137, 'Robert', '', NULL, NULL, 'm', NULL, 'N', NULL, NULL, 1, 0, 1, 0, 0, 0, '', 'beginner', NULL, NULL, 0, 0); + -- Struktúra mentése tábla aitrainer2. customer_activity CREATE TABLE IF NOT EXISTS `customer_activity` ( @@ -339,26 +339,6 @@ REPLACE INTO `customer_exercise_device` (`customer_exercise_device_id`, `custome (21, 90, 5, NULL, NULL); /*!40000 ALTER TABLE `customer_exercise_device` ENABLE KEYS */; --- Struktúra mentése tábla aitrainer2. customer_information -CREATE TABLE IF NOT EXISTS `customer_information` ( - `customer_information_id` int(11) NOT NULL AUTO_INCREMENT, - `title` char(50) COLLATE utf8_hungarian_ci DEFAULT '', - `description` mediumtext COLLATE utf8_hungarian_ci DEFAULT NULL, - `date_add` datetime DEFAULT NULL, - `display_begin` datetime DEFAULT NULL, - `display_end` datetime DEFAULT NULL, - PRIMARY KEY (`customer_information_id`) USING BTREE, - KEY `title` (`title`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; - --- Tábla adatainak mentése aitrainer2.customer_information: ~3 rows (hozzávetőleg) -/*!40000 ALTER TABLE `customer_information` DISABLE KEYS */; -REPLACE INTO `customer_information` (`customer_information_id`, `title`, `description`, `date_add`, `display_begin`, `display_end`) VALUES - (1, 'Fekvőtámasz világcsúcs', 'Világcsúcs fekvőtámasz: KJ Joseph 1 perc alatt 82 szabályos fekvőtámaszt végzett', '2020-06-01 08:00:00', '2020-06-01 08:00:00', '2023-07-01 08:00:00'), - (2, 'Húzódszkodás csúcs', '24 órás csúcstartója Joonas Mäkipelto 5050 gyakorlattal', '2020-06-01 08:00:00', '2020-06-01 08:00:00', '2023-07-01 08:00:00'), - (3, 'Fekvenyomás', '2015-ben a fekvenyomó világbajnokságot Smulter Fredrik finn súlyemelő 401 Kg-al nyerte', '2020-06-01 08:00:00', '2020-05-01 00:00:00', '2020-06-01 08:00:01'); -/*!40000 ALTER TABLE `customer_information` ENABLE KEYS */; - -- Struktúra mentése tábla aitrainer2. customer_property CREATE TABLE IF NOT EXISTS `customer_property` ( `customer_property_id` int(10) unsigned NOT NULL AUTO_INCREMENT, @@ -1361,6 +1341,38 @@ CREATE TABLE IF NOT EXISTS `tracking` ( KEY `event` (`event`) ) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; + + +CREATE TABLE `sport` ( + `sport_id` INT(11) NOT NULL AUTO_INCREMENT, + `name` CHAR(50) NOT NULL COLLATE 'utf8_hungarian_ci', + PRIMARY KEY (`sport_id`) USING BTREE +) +COLLATE='utf8_hungarian_ci' +ENGINE=InnoDB +; + +INSERT INTO `sport` (`sport_id`, `name`) VALUES (3, 'Fitness / Body Building'); +INSERT INTO `sport` (`sport_id`, `name`) VALUES (1, 'Football'); +INSERT INTO `sport` (`sport_id`, `name`) VALUES (2, 'Footgolf'); +INSERT INTO `sport` (`sport_id`, `name`) VALUES (4, 'Tennis'); + + +CREATE TABLE IF NOT EXISTS `sport_translation` ( + `translation_id` int(13) NOT NULL AUTO_INCREMENT, + `language_code` char(2) NOT NULL DEFAULT 'en', + `sport_id` int(13) NOT NULL DEFAULT 0, + `sport_name` char(50) DEFAULT NULL, + PRIMARY KEY (`translation_id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4; + +INSERT INTO `sport_translation` (`translation_id`, `language_code`, `sport_id`, `sport_name`) VALUES (2, 'hu', 1, 'Labdarúgás'); +INSERT INTO `sport_translation` (`translation_id`, `language_code`, `sport_id`, `sport_name`) VALUES (3, 'hu', 2, 'Footgolf'); +INSERT INTO `sport_translation` (`translation_id`, `language_code`, `sport_id`, `sport_name`) VALUES (4, 'hu', 3, 'Fitnesz / Body Building'); +INSERT INTO `sport_translation` (`translation_id`, `language_code`, `sport_id`, `sport_name`) VALUES (5, 'hu', 4, 'Tenisz'); + + + -- Tábla adatainak mentése aitrainer2.tracking: ~0 rows (hozzávetőleg) /*!40000 ALTER TABLE `tracking` DISABLE KEYS */; /*!40000 ALTER TABLE `tracking` ENABLE KEYS */; diff --git a/data/db/update_1_0_31.sql b/data/db/update_1_0_31.sql new file mode 100644 index 0000000..3a19505 --- /dev/null +++ b/data/db/update_1_0_31.sql @@ -0,0 +1,30 @@ +START TRANSACTION; + +CREATE TABLE `sport` ( + `sport_id` INT(11) NOT NULL AUTO_INCREMENT, + `name` CHAR(50) NOT NULL COLLATE 'utf8_hungarian_ci', + PRIMARY KEY (`sport_id`) USING BTREE +) +COLLATE='utf8_hungarian_ci' +ENGINE=InnoDB +; + +CREATE TABLE IF NOT EXISTS `sport_translation` ( + `translation_id` int(13) NOT NULL AUTO_INCREMENT, + `language_code` char(2) NOT NULL DEFAULT 'en', + `sport_id` int(13) NOT NULL DEFAULT 0, + `sport_name` char(50) DEFAULT NULL, + PRIMARY KEY (`translation_id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4; + +ALTER TABLE `customer` + ADD COLUMN `sport_id` INT(13) NULL DEFAULT NULL AFTER `firebase_uid`; + +ALTER TABLE `customer` + ADD COLUMN `email_subscription` TINYINT(1) NULL DEFAULT 0 AFTER `sport_id`; + + +UPDATE configuration set config_value = "1.0.31", date_change=CURRENT_DATE WHERE config_key = "db_version"; + +COMMIT; + diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt index 605e0a6..a249fd0 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt @@ -111,6 +111,12 @@ class CustomerController ( private val customerRepository: CustomerRepository) { if (newCustomer.dataPolicyAllowed != null) { updatedCustomer.dataPolicyAllowed = newCustomer.dataPolicyAllowed } + if (newCustomer.sportId != null) { + updatedCustomer.sportId = newCustomer.sportId + } + if (newCustomer.emailSubscription != null) { + updatedCustomer.emailSubscription = newCustomer.emailSubscription + } updatedCustomer.sex = newCustomer.sex updatedCustomer.birthYear = newCustomer.birthYear updatedCustomer.fitnessLevel = newCustomer.fitnessLevel diff --git a/src/main/kotlin/com/aitrainer/api/controller/PackageController.kt b/src/main/kotlin/com/aitrainer/api/controller/PackageController.kt index e9af550..37b8963 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/PackageController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/PackageController.kt @@ -20,7 +20,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe private val exerciseDeviceRepository: ExerciseDeviceRepository, private val exerciseTreeParentsRepository: ExerciseTreeParentsRepository, private val exercisePlanTemplateRepository: ExercisePlanTemplateRepository, - private val evaluationRepository: EvaluationRepository + private val evaluationRepository: EvaluationRepository, + private val sportRepository: SportRepository ) { private val logger = LoggerFactory.getLogger(javaClass) @@ -59,6 +60,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe val listEvaluations = evaluationRepository.findAll() val listEvaluationJson: String = gson.toJson(listEvaluations) + val listSports = sportRepository.getSports() + val listSportsJson: String = gson.toJson((listSports)) val packageJson: String = getClassRecord(ExerciseDevice::class.simpleName, listDevicesJson) + @@ -69,7 +72,8 @@ class PackageController(private val exerciseAbilityRepository: ExerciseAbilityRe "|||" + getClassRecord(ExerciseAbility::class.simpleName, listExerciseAbilityJson) + "|||" + getClassRecord(ExerciseTreeParents::class.simpleName, listExerciseTreeParentsJson) + "|||" + getClassRecord(ExercisePlanTemplate::class.simpleName, listPlanTemplateJson) + - "|||" + getClassRecord(Evaluation::class.simpleName, listEvaluationJson) + "|||" + getClassRecord(Evaluation::class.simpleName, listEvaluationJson) + + "|||" + getClassRecord(Sport::class.simpleName, listSportsJson) return if (packageJson.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(packageJson) diff --git a/src/main/kotlin/com/aitrainer/api/controller/SportController.kt b/src/main/kotlin/com/aitrainer/api/controller/SportController.kt new file mode 100644 index 0000000..a593946 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/controller/SportController.kt @@ -0,0 +1,24 @@ +package com.aitrainer.api.controller + +import com.aitrainer.api.model.Sport +import com.aitrainer.api.repository.SportRepository +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 SportController(private val sportRepository: SportRepository) { + private val logger = LoggerFactory.getLogger(javaClass) + + @GetMapping("/sports") + fun getSportsWithTranslation(): ResponseEntity> { + val list = sportRepository.getSports() + + logger.info(" -- Get All sports $list") + return if (list.isEmpty()) ResponseEntity.notFound().build() else + ResponseEntity.ok().body(list) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/Customer.kt b/src/main/kotlin/com/aitrainer/api/model/Customer.kt index c8a9b30..6692302 100644 --- a/src/main/kotlin/com/aitrainer/api/model/Customer.kt +++ b/src/main/kotlin/com/aitrainer/api/model/Customer.kt @@ -25,6 +25,8 @@ data class Customer ( @Expose var fitnessLevel: String = "beginner", @Expose var bodyType: String? = null, @Expose var firebaseUid: String? = null, + @Expose var sportId: Int? = null, + @Expose var emailSubscription: Int? = 0, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose var customerId: Long = 0 ) diff --git a/src/main/kotlin/com/aitrainer/api/model/Sport.kt b/src/main/kotlin/com/aitrainer/api/model/Sport.kt new file mode 100644 index 0000000..6a56231 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/Sport.kt @@ -0,0 +1,18 @@ +package com.aitrainer.api.model + +import com.google.gson.annotations.Expose +import org.hibernate.annotations.Fetch +import org.hibernate.annotations.FetchMode +import org.springframework.lang.NonNull +import javax.persistence.* + +@Entity +data class Sport ( + @Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @get: NonNull var sportId: Long = 0, + @Expose @get: NonNull var name: String = "", +) { + @OneToMany(cascade = [(CascadeType.ALL)], fetch = FetchType.EAGER, mappedBy = "sport") + @Fetch(value = FetchMode.SUBSELECT) + @Expose val translations: List = mutableListOf().toList() + +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/model/SportTranslation.kt b/src/main/kotlin/com/aitrainer/api/model/SportTranslation.kt new file mode 100644 index 0000000..d3b6047 --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/model/SportTranslation.kt @@ -0,0 +1,20 @@ +package com.aitrainer.api.model + +import com.fasterxml.jackson.annotation.JsonIgnore +import com.google.gson.annotations.Expose +import javax.persistence.* +import javax.validation.constraints.NotBlank + +@Entity +data class SportTranslation ( + @Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val translationId: Long = 0, + + @Expose @get: NotBlank var languageCode: String?, + @Expose @get: NotBlank var sportName: String = "", + +) { + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "sportId", nullable = false) + @JsonIgnore + val sport: Sport? = null +} \ No newline at end of file diff --git a/src/main/kotlin/com/aitrainer/api/repository/SportRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/SportRepository.kt new file mode 100644 index 0000000..d63ffac --- /dev/null +++ b/src/main/kotlin/com/aitrainer/api/repository/SportRepository.kt @@ -0,0 +1,14 @@ +package com.aitrainer.api.repository + +import com.aitrainer.api.model.Sport +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query +import org.springframework.stereotype.Repository + +@Repository +interface SportRepository: JpaRepository { + @Query("FROM Sport as e " + + "LEFT JOIN SportTranslation as t ON e.sportId = t.sport AND t.languageCode = 'hu' "+ + "ORDER BY name") + fun getSports(): List +} \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 1577c2a..2972ffb 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -17,6 +17,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.30 +application.version=1.0.31 jwt.secret=aitrainer \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 062f08b..da7d01c 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -17,6 +17,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.30 +application.version=1.0.31 jwt.secret=aitrainer \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt b/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt index ef36900..7e1417b 100644 --- a/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/AppPackageTest.kt @@ -35,6 +35,8 @@ class AppPackageTest { private lateinit var exercisePlanTemplateRepository: ExercisePlanTemplateRepository @Autowired private lateinit var evaluationRepository: EvaluationRepository + @Autowired + private lateinit var sportRepository: SportRepository @Test fun testAppPackage() { @@ -49,7 +51,8 @@ class AppPackageTest { exerciseDeviceRepository, exerciseTreeParentsRepository, exercisePlanTemplateRepository, - evaluationRepository + evaluationRepository, + sportRepository ) val response: ResponseEntity<*> = controller.getPackageData() @@ -112,6 +115,16 @@ class AppPackageTest { assertEquals(evaluations[0].name, "PushUps") assertEquals(evaluations[0].attributes.size, 18) assertEquals(evaluations[0].attributes[1].name, "Fekvőtámasz_ffi_17-19_fair") + } else if (record[0] == Sport::class.simpleName) { + val sportJson: String = record[1] + val type = object : TypeToken?>() {}.type + val sports: List = gson.fromJson(sportJson, type) + assertEquals(sports.size, 4) + assertEquals(sports[1].name, "Football") + assertEquals(sports[1].translations[0].sportName, "Labdarúgás") + assertEquals(sports[2].name, "Footgolf") + assertEquals(sports[2].translations[0].sportName, "Footgolf") + assertEquals(sports[3].translations[0].sportName, "Tenisz") } } diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt index 0d0f3c1..2cc8759 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt @@ -112,6 +112,8 @@ class CustomerTests { customer.fitnessLevel = "advanced" customer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) customer.email = "mr@aitrainer.app" + customer.emailSubscription = 1 + customer.sportId = 2 var updatedCustomer = customerRepository.save(customer) @@ -121,6 +123,8 @@ class CustomerTests { assertTrue(customer.dateChange != null) assertEquals(updatedCustomer.email, "mr@aitrainer.app") assertEquals(updatedCustomer.dataPolicyAllowed, 1) + assertEquals(updatedCustomer.emailSubscription, 1) + assertEquals(updatedCustomer.sportId, 2) customer.email = "sw@andio.biz" @@ -168,6 +172,7 @@ class CustomerTests { customer.firstname = "Kakadu" customer.name = "Bos" customer.email = "mr@aitrainer.app" + customer.sportId = 4 response = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) ) assertEquals(response.statusCode, HttpStatus.OK) newCustomer = response.body as Customer @@ -176,10 +181,12 @@ class CustomerTests { assertEquals(newCustomer.name, "Bos") assertEquals(newCustomer.email, "mr@aitrainer.app") assertEquals(newCustomer.dataPolicyAllowed, 1) + assertEquals(newCustomer.sportId, 4) val customer2 = newCustomer.copy() customer2.email = "sw2@andio.biz" customer2.customerId = 103 + customer2.sportId = 0 val updatedCustomer = customerRepository.save(customer2) assertEquals(updatedCustomer.email, "sw2@andio.biz") diff --git a/src/test/kotlin/com/aitrainer/api/test/SportTest.kt b/src/test/kotlin/com/aitrainer/api/test/SportTest.kt new file mode 100644 index 0000000..99671da --- /dev/null +++ b/src/test/kotlin/com/aitrainer/api/test/SportTest.kt @@ -0,0 +1,37 @@ +package com.aitrainer.api.test + +import com.aitrainer.api.controller.SportController +import com.aitrainer.api.repository.SportRepository +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 SportTest { + + @Autowired + private lateinit var sportRepository: SportRepository + + + @Test + fun testGetSports() { + val controller = SportController(sportRepository ) + val response = controller.getSportsWithTranslation() + + val sports = response.body + + assertTrue(sports is List) + assertTrue(sports.isNotEmpty()) + assertEquals(sports.size, 4) + assertEquals(sports[1].name, "Football") + assertEquals(sports[1].translations[0].sportName, "Labdarúgás") + assertEquals(sports[2].name, "Footgolf") + assertEquals(sports[2].translations[0].sportName, "Footgolf") + assertEquals(sports[3].translations[0].sportName, "Tenisz") + } + +} \ No newline at end of file