From c04f0cbbc47257dab532b412be8389e2f49f4725 Mon Sep 17 00:00:00 2001 From: Bossanyi Tibor Date: Sun, 25 Oct 2020 12:13:30 +0100 Subject: [PATCH] Customer.firebaseUid --- build.gradle.kts | 2 +- data/db/install.sql | 35 +++++++------- data/db/update_1_0_10.sql | 7 +++ .../api/controller/CustomerController.kt | 22 +++++++++ .../com/aitrainer/api/model/Customer.kt | 1 + .../kotlin/com/aitrainer/api/model/User.kt | 3 +- .../api/repository/CustomerRepository.kt | 2 + .../resources/application-prod.properties | 2 +- src/main/resources/application.properties | 2 +- .../com/aitrainer/api/test/CustomerTests.kt | 48 ++++++++++++++++--- 10 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 data/db/update_1_0_10.sql diff --git a/build.gradle.kts b/build.gradle.kts index 2752341..aafc279 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.aitrainer" -version = "1.0.9" +version = "1.0.10" java.sourceCompatibility = JavaVersion.VERSION_1_8 repositories { diff --git a/data/db/install.sql b/data/db/install.sql index 3740ed7..6239da0 100644 --- a/data/db/install.sql +++ b/data/db/install.sql @@ -49,28 +49,29 @@ CREATE TABLE IF NOT EXISTS `customer` ( `goal` CHAR(20) NULL DEFAULT '' COLLATE 'utf8_hungarian_ci', `fitness_level` ENUM('beginner','intermediate','advanced','professional') NOT NULL DEFAULT 'beginner' COLLATE 'utf8_hungarian_ci', `body_type` ENUM('ectomorph','mesomorph','endomorph') NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci', + `firebase_uid` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci', PRIMARY KEY (`customer_id`) ) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci; -- 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`, `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); +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`) VALUES (1, 'Átlag 13 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', 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`) VALUES (2, 'Átlag 14 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (3, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (4, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', 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`) VALUES (5, 'Átlag 16 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (6, 'Átlag 17 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (7, 'Átlag 18 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (8, 'Átlag 13 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (9, 'Átlag 14 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (10, 'Átlag 15 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (11, 'Átlag 16 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (12, 'Átlag 17 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (13, 'Átlag 18 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (54, 'Dummy User', '', 'bosi', '$2a$10$thOc8jS750c7xe9U9Qq3GuSPs/H0Pt2Ads05yzUlyzQBIj.Rk9QCy', 'm', 0, 'N', NULL, NULL, 1, 1, 0, 0, 0, 0, '', 'beginner', 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`) VALUES (90, 'Bossi', 'Tib', 'sw@andio.biz', '123456789', 'm', 0, 'Y', NULL, NULL, 1, 1, 0, 137, 1972, 79, NULL, 'advanced', 'endomorph', 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`) VALUES (103, 'Bos', 'Kakadu', 'sw2@andio.biz', 'blabal', 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 1972, 79, NULL, 'intermediate', NULL, "3FirebaseU1d"); +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`) VALUES (137, 'Robert', '', NULL, NULL, 'm', NULL, 'N', NULL, NULL, 1, 0, 1, 0, 0, 0, '', 'beginner', NULL, NULL); /*!40000 ALTER TABLE `customer` ENABLE KEYS */; diff --git a/data/db/update_1_0_10.sql b/data/db/update_1_0_10.sql new file mode 100644 index 0000000..8208c7a --- /dev/null +++ b/data/db/update_1_0_10.sql @@ -0,0 +1,7 @@ +ALTER TABLE `customer` + ADD COLUMN `firebase_uid` CHAR(50) NULL DEFAULT NULL AFTER `body_type`; + +ALTER TABLE `customer` + ADD UNIQUE INDEX `firebase_uid` (`firebase_uid`); + +UPDATE configuration set config_value = "1.0.10", 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/CustomerController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt index 4a92d9a..d511400 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt @@ -4,6 +4,7 @@ import com.aitrainer.api.model.Customer import com.aitrainer.api.model.User import com.aitrainer.api.service.ServiceBeans import com.aitrainer.api.repository.CustomerRepository +import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.HttpHeaders import org.springframework.http.ResponseEntity @@ -16,6 +17,7 @@ import javax.validation.Valid @RestController @RequestMapping("/api") class CustomerController ( private val customerRepository: CustomerRepository ) { + private val logger = LoggerFactory.getLogger(javaClass) @Autowired var serviceBeans: ServiceBeans? = null @@ -38,6 +40,13 @@ class CustomerController ( private val customerRepository: CustomerRepository ) }.orElse(ResponseEntity.notFound().build()) } + @Secured + @GetMapping("/customers/firebase/{uid}") + fun getCustomerByFirebaseUid(@PathVariable(value = "uid") firebaseUid: String): ResponseEntity { + val customer: Customer? = customerRepository.findByFirebaseUid(firebaseUid) + return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer) + } + @Secured @GetMapping("/customers/real") @@ -53,6 +62,18 @@ class CustomerController ( private val customerRepository: CustomerRepository ) return if (list.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(list) } + @Secured + @PostMapping("customers/update_firebase_uid/{id}") + fun updateCustomerFirebaseUidById(@PathVariable(value = "id") customerId: Long, @Valid @RequestBody firebaseUid: String) + : ResponseEntity { + logger.info("Get customer id: $customerId uid: $firebaseUid") + val returnCustomer: Customer = customerRepository.findById(customerId).orElse(null) + ?: return ResponseEntity.notFound().build() + + returnCustomer.firebaseUid = firebaseUid; + return ResponseEntity.ok().body(customerRepository.save(returnCustomer)) + } + @Secured @PostMapping("/customers/{id}") fun updateCustomerById(@PathVariable(value = "id") customerId: Long, @@ -103,6 +124,7 @@ class CustomerController ( private val customerRepository: CustomerRepository ) with (customer) { email = newUser.username password = serviceBeans!!.passwordEncoder().encode(newUser.password) + firebaseUid = newUser.firebaseUid } val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let { diff --git a/src/main/kotlin/com/aitrainer/api/model/Customer.kt b/src/main/kotlin/com/aitrainer/api/model/Customer.kt index 7533870..4043db4 100644 --- a/src/main/kotlin/com/aitrainer/api/model/Customer.kt +++ b/src/main/kotlin/com/aitrainer/api/model/Customer.kt @@ -25,6 +25,7 @@ data class Customer ( var goal: String? = null, var fitnessLevel: String = "beginner", var bodyType: String? = null, + var firebaseUid: String? = null, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var customerId: Long = 0 diff --git a/src/main/kotlin/com/aitrainer/api/model/User.kt b/src/main/kotlin/com/aitrainer/api/model/User.kt index f1f4ce3..d2462ac 100644 --- a/src/main/kotlin/com/aitrainer/api/model/User.kt +++ b/src/main/kotlin/com/aitrainer/api/model/User.kt @@ -6,7 +6,8 @@ import kotlinx.serialization.json.* @Serializable data class User ( var username: String = "", - var password: String = "" + var password: String = "", + var firebaseUid: String = "" ) { @OptIn(UnstableDefault::class) fun fromJson(json: String): User { diff --git a/src/main/kotlin/com/aitrainer/api/repository/CustomerRepository.kt b/src/main/kotlin/com/aitrainer/api/repository/CustomerRepository.kt index 9be285c..f3d7395 100644 --- a/src/main/kotlin/com/aitrainer/api/repository/CustomerRepository.kt +++ b/src/main/kotlin/com/aitrainer/api/repository/CustomerRepository.kt @@ -11,4 +11,6 @@ interface CustomerRepository : JpaRepository { fun findByEmail(email: String?): Customer? fun findByTrainerId( trainerId: Long ): List + + fun findByFirebaseUid(firebaseUid: String?): Customer? } diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 5d9a222..968d6ff 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.9 +application.version=1.0.10 jwt.secret=aitrainer \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ba5114e..9f01487 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.9 +application.version=1.0.10 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 4faa686..4bcbc6f 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt @@ -42,7 +42,7 @@ class CustomerTests { @Test fun testTrainer() { val id: Long = 137 - val customers: List = customerRepository.findByTrainerId( id ); + val customers: List = customerRepository.findByTrainerId( id ) assertEquals(customers.count(), 3) assertEquals( customers[0].name, "Átlag 13 éves fiú") } @@ -119,6 +119,7 @@ class CustomerTests { val customerController = CustomerController(customerRepository) var response: ResponseEntity<*> = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) ) + print ("body " + response.body) var newCustomer: Customer? = response.body as Customer assertEquals(response.statusCode, HttpStatus.OK) assertEquals(newCustomer?.weight, 79) @@ -147,21 +148,24 @@ class CustomerTests { @Test fun testRegistration() { - val json = "{\"username\":\"bosi@example.com\",\"password\":\"94385\"}" + val json = "{\"username\":\"bosi2@example.com\",\"password\":\"94385\",\"firebaseUid\":\"3Firebase8Uid\"}" val user: User = User().fromJson(json) - assertEquals(user.username, "bosi@example.com") + assertEquals(user.username, "bosi2@example.com") val customer = Customer() with(customer) { email = user.username password = user.password + firebaseUid = user.firebaseUid } val customerController = CustomerController(customerRepository) customerController.serviceBeans = serviceBean var 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") - val json2 = "{\"username\":\"bosi@example.com\",\"password\":\"934345\"}" + val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid\"}" response = customerController.registration(json2) assertEquals(response.statusCode, HttpStatus.BAD_REQUEST) @@ -170,7 +174,39 @@ class CustomerTests { } } - @Test fun testLogin() { + @Test + fun testUpdateFirebaseUid() { + val newCustomer = Customer("Bossanyi2", "Tibor", "", 48, "m") + val savedCustomer: Customer = customerRepository.save(newCustomer) + assertEquals(savedCustomer.age, 48) + + insertedId = savedCustomer.customerId + + val customerController = CustomerController(customerRepository) + val response: ResponseEntity<*> = customerController.updateCustomerFirebaseUidById(insertedId!!, "3FirebusaeId4") + val newCustomer2: Customer? = response.body as Customer + assertEquals(response.statusCode, HttpStatus.OK) + assertEquals(newCustomer2!!.firebaseUid, "3FirebusaeId4") + assertEquals(newCustomer2.firstname, "Tibor") + assertEquals(newCustomer2.name, "Bossanyi2") + assertEquals(newCustomer2.age, 48) + + customerRepository.delete(newCustomer) + } + + @Test + fun testGetCustomerByFirebaseUid() { + val uid = "3FirebaseU1d" + val customerController = CustomerController(customerRepository) + val response: ResponseEntity<*> = customerController.getCustomerByFirebaseUid(uid) + assertEquals(response.statusCode, HttpStatus.OK) + val newCustomer: Customer? = response.body as Customer + assertEquals(newCustomer!!.name, "Bos") + assertEquals(newCustomer.email, "sw2@andio.biz") + + } + + /*@Test fun _testLogin() { val json = "{\"username\":\"bosi2@example.com\",\"password\":\"94333385\"}" val user: User = User().fromJson(json) val customer = Customer() @@ -196,5 +232,5 @@ class CustomerTests { if ( newCustomer != null) { customerRepository.delete(newCustomer) } - } + }*/ } \ No newline at end of file