From 73d189a357150a58af29a86bf73494c5604565d4 Mon Sep 17 00:00:00 2001 From: Tibor Bossanyi Date: Tue, 11 Apr 2023 16:53:33 +0200 Subject: [PATCH] API 1.2.2 fix firebase string, customer login --- build.gradle.kts | 2 +- data/db/update_1_2_2.sql | 5 +++ readme.MD | 2 +- .../api/controller/CustomerController.kt | 2 +- .../controller/diet/DietCustomerController.kt | 2 +- .../api/security/JwtSecurityConfig.kt | 2 +- .../com/aitrainer/api/service/Firebase.kt | 2 +- .../resources/application-diet.properties | 2 +- .../resources/application-dietprod.properties | 4 +-- .../resources/application-prod.properties | 2 +- src/main/resources/application.properties | 2 +- .../com/aitrainer/api/test/CustomerTests.kt | 34 +++++++++++++++++-- .../com/aitrainer/api/test/FirebaseTest.kt | 2 +- 13 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 data/db/update_1_2_2.sql diff --git a/build.gradle.kts b/build.gradle.kts index 5dd02d7..e1db83c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "com.aitrainer" -version = "1.2.1" +version = "1.2.2" java.sourceCompatibility = JavaVersion.VERSION_17 repositories { diff --git a/data/db/update_1_2_2.sql b/data/db/update_1_2_2.sql new file mode 100644 index 0000000..956d00c --- /dev/null +++ b/data/db/update_1_2_2.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +UPDATE configuration set config_value = "1.2.2", date_change=CURRENT_DATE WHERE config_key = "db_version"; + +COMMIT; \ No newline at end of file diff --git a/readme.MD b/readme.MD index ae5b955..909bf8d 100644 --- a/readme.MD +++ b/readme.MD @@ -1,4 +1,4 @@ -#aitrainer server API v1.2 +#aitrainer server API v1.2.2 connects the MYSQL Database provide a RESTful API for the mobile app diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt index 1f7df54..13c688d 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt @@ -155,7 +155,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) { } @PostMapping("/club_registration") - fun clubRegistration(@Valid @RequestBody json: String, @Value("\${firebase.key}") apiKey: String): ResponseEntity<*> { + fun clubRegistration(@Valid @RequestBody json: String, @Value("\${firebase.key}") apiKey: java.lang.String): ResponseEntity<*> { val newUser: ClubUser = ClubUser().fromJson(json) diff --git a/src/main/kotlin/com/aitrainer/api/controller/diet/DietCustomerController.kt b/src/main/kotlin/com/aitrainer/api/controller/diet/DietCustomerController.kt index 4104394..c98fe89 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/diet/DietCustomerController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/diet/DietCustomerController.kt @@ -25,7 +25,7 @@ class DietCustomerController(private val dietUserRepository: DietUserRepository, var serviceBeans: ServiceBeans? = null @PostMapping("/diet_registration") - fun insert(@RequestBody dietCustomerJson: String, @Value("\${firebase.key}") apiKey: String): ResponseEntity<*> { + fun insert(@RequestBody dietCustomerJson: String, @Value("\${firebase.key}") apiKey: java.lang.String): ResponseEntity<*> { val newDietCustomer: DietCustomer = DietCustomer().fromJson(dietCustomerJson) if ( newDietCustomer.email.isEmpty()) { diff --git a/src/main/kotlin/com/aitrainer/api/security/JwtSecurityConfig.kt b/src/main/kotlin/com/aitrainer/api/security/JwtSecurityConfig.kt index e9f05b2..77d5b06 100644 --- a/src/main/kotlin/com/aitrainer/api/security/JwtSecurityConfig.kt +++ b/src/main/kotlin/com/aitrainer/api/security/JwtSecurityConfig.kt @@ -61,7 +61,7 @@ class JwtSecurityConfig { return object : WebMvcConfigurer { override fun addCorsMappings(registry: CorsRegistry) { registry.addMapping("/**") - .allowedOriginPatterns("https://*.diet4you.eu", "https://*.diet4you.hu", "https://*.workouttest.org", "http://localhost:[*]") + .allowedOriginPatterns("https://diet4you.hu", "https://diet4you.eu", "https://*.diet4you.eu", "https://*.diet4you.hu", "https://*.workouttest.org", "http://localhost:[*]") //.allowedOrigins("*") .allowedMethods("POST", "GET", "OPTIONS", "HEAD") .maxAge(3600) diff --git a/src/main/kotlin/com/aitrainer/api/service/Firebase.kt b/src/main/kotlin/com/aitrainer/api/service/Firebase.kt index 995e908..240b143 100644 --- a/src/main/kotlin/com/aitrainer/api/service/Firebase.kt +++ b/src/main/kotlin/com/aitrainer/api/service/Firebase.kt @@ -13,7 +13,7 @@ import java.nio.charset.StandardCharsets import java.util.* @Service -class Firebase(@Value("\${firebase.key}") private val apiKey: String) { +class Firebase(@Value("\${firebase.key}") private val apiKey: java.lang.String) { private val firebaseBaseUrl: String = "https://identitytoolkit.googleapis.com/v1/accounts" var statusCode: Int = 0 var error: String = "" diff --git a/src/main/resources/application-diet.properties b/src/main/resources/application-diet.properties index 3a03dde..e2dda90 100644 --- a/src/main/resources/application-diet.properties +++ b/src/main/resources/application-diet.properties @@ -16,7 +16,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structure has been changed, increment this version number -application.version=1.2.1 +application.version=1.2.2 jwt.secret=aitrainer diff --git a/src/main/resources/application-dietprod.properties b/src/main/resources/application-dietprod.properties index a055290..b3fcc55 100644 --- a/src/main/resources/application-dietprod.properties +++ b/src/main/resources/application-dietprod.properties @@ -14,11 +14,11 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structue has been changed, increment this version number -application.version=1.2.1 +application.version=1.2.2 jwt.secret=aitrainer -firebase.key=AIzaSyCUXBWV3_qzvV__ZWZA1siHftrrJpjDKh4 +firebase.key=AIzaSyBLn7Bz73Z1hB-OhqphBDsskOyGmpI7J8E openai.key=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 spring.mail.properties.mail.mime.charset=UTF-8 diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 32c5791..d7540d4 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structue has been changed, increment this version number -application.version=1.2.1 +application.version=1.2.2 jwt.secret=aitrainer diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ae65df9..9d96bca 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml logging.file=logs # if the database structure has been changed, increment this version number -application.version=1.2.1 +application.version=1.2.2 jwt.secret=aitrainer diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt index fea35b7..b76dad7 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt @@ -246,7 +246,7 @@ class CustomerTests { } @Test - fun testClubRegistration(@Value("\${firebase.key}") apiKey: String) { + fun testClubRegistration(@Value("\${firebase.key}") apiKey: java.lang.String) { val json = "{\"firstname\":\"Tib\", \"email\": \"mr@andio.biz\", \"goal\": \"shape\", \"fitnessLevel\": \"advanced\", \"weight\": 85}" val controller = CustomerController(customerRepository) val response: ResponseEntity<*> = controller.clubRegistration(json, apiKey) @@ -329,7 +329,7 @@ class CustomerTests { } @Test - fun `insert recipes successfully`() { + fun `get customer successfully`() { authToken = Tokenizer.getToken() val customer = Customer( @@ -355,7 +355,37 @@ class CustomerTests { val customerId = JSONObject(mvcResult.response.contentAsString).getInt("customerId") println("MockCustomer Id $customerId") assertTrue(customerId > 0) + + customerRepository.delete(customer) } + + @Test + fun `login successfully`() { + authToken = Tokenizer.getToken() + + val user = User( + username = "sw2@andio.biz", + password = "andio2009", + firebaseUid = "", + ) + + val mvcResult: MvcResult = mockMvc.perform( + MockMvcRequestBuilders.post("/api/login") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer $authToken") + .content(toJson(user)) + ) + .andExpect(MockMvcResultMatchers.status().isOk) + .andExpect(MockMvcResultMatchers.jsonPath("$.name").value("Bos")) + .andExpect(MockMvcResultMatchers.jsonPath("$.firstname").value("Kakadu")) + .andExpect(MockMvcResultMatchers.jsonPath("$.birthYear").value(1972)) + .andReturn() + + val customerId = JSONObject(mvcResult.response.contentAsString).getInt("customerId") + println("MockCustomer Id $customerId") + assertEquals(customerId, 103) + } + private fun toJson(obj: Any): String { return Gson().toJson(obj) } diff --git a/src/test/kotlin/com/aitrainer/api/test/FirebaseTest.kt b/src/test/kotlin/com/aitrainer/api/test/FirebaseTest.kt index e6bc1c1..1dd2dd4 100644 --- a/src/test/kotlin/com/aitrainer/api/test/FirebaseTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/FirebaseTest.kt @@ -21,7 +21,7 @@ class FirebaseTest { } @Test - fun testAuth(@Value("\${firebase.key}") apiKey: String) { + fun testAuth(@Value("\${firebase.key}") apiKey: java.lang.String) { this.firebase = Firebase(apiKey) val email = "user@exemple.com" val password = "verystrictpassword1"