From 2efb3cb18f1b1f8fdf5376ad860e4edc1f80a996 Mon Sep 17 00:00:00 2001 From: Bossanyi Tibor Date: Fri, 4 Sep 2020 15:58:30 +0200 Subject: [PATCH] Customer: trainer, trainerId --- data/db/install.sql | 34 +++++++++++-------- data/db/update_1_0_6.sql | 5 +++ .../api/controller/CustomerController.kt | 5 +++ .../com/aitrainer/api/model/Customer.kt | 2 ++ .../api/repository/CustomerRepository.kt | 2 ++ .../resources/application-prod.properties | 2 +- .../resources/application-prodtest.properties | 2 +- src/main/resources/application.properties | 4 +-- .../com/aitrainer/api/test/CustomerTests.kt | 8 +++++ 9 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 data/db/update_1_0_6.sql diff --git a/data/db/install.sql b/data/db/install.sql index 12753ca..2a27b44 100644 --- a/data/db/install.sql +++ b/data/db/install.sql @@ -42,6 +42,8 @@ CREATE TABLE IF NOT EXISTS `customer` ( `date_change` datetime DEFAULT NULL, `data_policy_allowed` tinyint(4) DEFAULT 1, `admin` tinyint(4) DEFAULT 0, + `trainer` tinyint(4) DEFAULT 0, + `trainer_id` INT(11) NULL DEFAULT '0', `birth_year` int(4) DEFAULT 0, `weight` INT(3) NULL DEFAULT '0', `goal` CHAR(20) NULL DEFAULT '' COLLATE 'utf8_hungarian_ci', @@ -52,21 +54,23 @@ CREATE TABLE IF NOT EXISTS `customer` ( -- Tábla adatainak mentése aitrainer.customer: ~13 rows (hozzávetőleg) /*!40000 ALTER TABLE `customer` DISABLE KEYS */; -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (1, 'Átlag 13 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (2, 'Átlag 14 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (3, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (4, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (5, 'Átlag 16 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (6, 'Átlag 17 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (7, 'Átlag 18 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (8, 'Átlag 13 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (9, 'Átlag 14 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (10, 'Átlag 15 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (11, 'Átlag 16 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (12, 'Átlag 17 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (13, 'Átlag 18 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (54, 'Dummy User', '', 'bosi', '$2a$10$thOc8jS750c7xe9U9Qq3GuSPs/H0Pt2Ads05yzUlyzQBIj.Rk9QCy', 'm', 0, 'N', NULL, NULL, 1, 1, 0, 0, '', 'beginner', NULL); -INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (90, 'Bossi', 'Tib', 'sw@andio.biz', '', 'm', 0, 'Y', NULL, NULL, 1, 1, 0, 0, '', 'beginner', 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`) VALUES (1, 'Átlag 13 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', 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`) VALUES (2, 'Átlag 14 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (3, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (4, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', 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`) VALUES (5, 'Átlag 16 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (6, 'Átlag 17 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (7, 'Átlag 18 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (8, 'Átlag 13 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (9, 'Átlag 14 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (10, 'Átlag 15 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (11, 'Átlag 16 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (12, 'Átlag 17 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (13, 'Átlag 18 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (54, 'Dummy User', '', 'bosi', '$2a$10$thOc8jS750c7xe9U9Qq3GuSPs/H0Pt2Ads05yzUlyzQBIj.Rk9QCy', 'm', 0, 'N', NULL, NULL, 1, 1, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (90, 'Bossi', 'Tib', 'sw@andio.biz', '123456789', 'm', 0, 'Y', NULL, NULL, 1, 1, 0, 137, 1972, 79, NULL, 'advanced', 'endomorph'); +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`) VALUES (103, 'Bos', 'Kakadu', 'sw2@andio.biz', 'blabal', 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 1972, 79, NULL, 'intermediate', 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`) VALUES (137, 'Robert', '', NULL, NULL, 'm', NULL, 'N', NULL, NULL, 1, 0, 1, 0, 0, 0, '', 'beginner', NULL); /*!40000 ALTER TABLE `customer` ENABLE KEYS */; diff --git a/data/db/update_1_0_6.sql b/data/db/update_1_0_6.sql new file mode 100644 index 0000000..7638cc6 --- /dev/null +++ b/data/db/update_1_0_6.sql @@ -0,0 +1,5 @@ +ALTER TABLE `customer` + ADD COLUMN `trainer` TINYINT(4) NULL DEFAULT '0' AFTER `admin`, + ADD COLUMN `trainer_id` INT(11) NULL DEFAULT '0' AFTER `trainer`; + +UPDATE configuration set config_value = "1.0.6" WHERE config_key = "db_version"; diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt index 78e9ada..a8d7034 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt @@ -44,6 +44,11 @@ class CustomerController ( private val customerRepository: CustomerRepository ) fun getRealCustomers(active: String, @RequestHeader headers: HttpHeaders): List = customerRepository.findByActive(active) + @Secured + @GetMapping("/customers/trainees/{id}") + fun getCustomerListByTrainerId(@PathVariable(value = "id") trainerId: Long, @RequestHeader headers: HttpHeaders): List = + customerRepository.findByTrainerId(trainerId) + @Secured @PostMapping("/customers/{id}") fun updateCustomerById(@PathVariable(value = "id") customerId: Long, diff --git a/src/main/kotlin/com/aitrainer/api/model/Customer.kt b/src/main/kotlin/com/aitrainer/api/model/Customer.kt index 4f69c16..7533870 100644 --- a/src/main/kotlin/com/aitrainer/api/model/Customer.kt +++ b/src/main/kotlin/com/aitrainer/api/model/Customer.kt @@ -17,6 +17,8 @@ data class Customer ( var dateChange: String? = null, var dataPolicyAllowed: Int = 0, var admin: Int = 0, + var trainer: Int = 0, + var trainerId: Long = 0, var password: String? = "", var birthYear:Int = 0, var weight: Int = 0, diff --git a/src/main/kotlin/com/aitrainer/api/repository/CustomerRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/CustomerRepository.kt index 4e6c10b..9be285c 100644 --- a/src/main/kotlin/com/aitrainer/api/repository/CustomerRepository.kt +++ b/src/main/kotlin/com/aitrainer/api/repository/CustomerRepository.kt @@ -9,4 +9,6 @@ interface CustomerRepository : JpaRepository { fun findByActive( active: String? ): List fun findByEmail(email: String?): Customer? + + fun findByTrainerId( trainerId: Long ): List } diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 0ad3655..cc45e71 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.5 +application.version=1.0.6 jwt.secret=aitrainer \ No newline at end of file diff --git a/src/main/resources/application-prodtest.properties b/src/main/resources/application-prodtest.properties index bc0c571..ed184c4 100644 --- a/src/main/resources/application-prodtest.properties +++ b/src/main/resources/application-prodtest.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.5application-prod.properties +application.version=1.0.6 jwt.secret=aitrainer \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index da59a9d..4c5b9d6 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.profiles.active=dev,test,prod +spring.profiles.active=dev,test,prod,prodtest ## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) #spring.datasource.url = jdbc:mysql://localhost:3306/aitrainer?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false spring.datasource.url = jdbc:mysql://localhost:3306/aitrainer2?serverTimezone=CET&useSSL=false&characterEncoding=UTF-8&allowMultiQueries=true @@ -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.5 +application.version=1.0.6 jwt.secret=aitrainer \ 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 a9821cd..4faa686 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt @@ -39,6 +39,14 @@ class CustomerTests { assertEquals( customer.name, "Átlag 18 éves fiú") } + @Test + fun testTrainer() { + val id: Long = 137 + val customers: List = customerRepository.findByTrainerId( id ); + assertEquals(customers.count(), 3) + assertEquals( customers[0].name, "Átlag 13 éves fiú") + } + @Test fun testInsert() { val newCustomer = Customer("Bossanyi", "Tibor", "", 48, "m")