API 1.2.2 fix firebase string, customer login

This commit is contained in:
Tibor Bossanyi 2023-04-11 16:53:33 +02:00
parent bdbfe1cd48
commit 73d189a357
13 changed files with 49 additions and 14 deletions

View File

@ -11,7 +11,7 @@ plugins {
} }
group = "com.aitrainer" group = "com.aitrainer"
version = "1.2.1" version = "1.2.2"
java.sourceCompatibility = JavaVersion.VERSION_17 java.sourceCompatibility = JavaVersion.VERSION_17
repositories { repositories {

5
data/db/update_1_2_2.sql Normal file
View File

@ -0,0 +1,5 @@
START TRANSACTION;
UPDATE configuration set config_value = "1.2.2", date_change=CURRENT_DATE WHERE config_key = "db_version";
COMMIT;

View File

@ -1,4 +1,4 @@
#aitrainer server API v1.2 #aitrainer server API v1.2.2
connects the MYSQL Database connects the MYSQL Database
provide a RESTful API for the mobile app provide a RESTful API for the mobile app

View File

@ -155,7 +155,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
} }
@PostMapping("/club_registration") @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) val newUser: ClubUser = ClubUser().fromJson(json)

View File

@ -25,7 +25,7 @@ class DietCustomerController(private val dietUserRepository: DietUserRepository,
var serviceBeans: ServiceBeans? = null var serviceBeans: ServiceBeans? = null
@PostMapping("/diet_registration") @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) val newDietCustomer: DietCustomer = DietCustomer().fromJson(dietCustomerJson)
if ( newDietCustomer.email.isEmpty()) { if ( newDietCustomer.email.isEmpty()) {

View File

@ -61,7 +61,7 @@ class JwtSecurityConfig {
return object : WebMvcConfigurer { return object : WebMvcConfigurer {
override fun addCorsMappings(registry: CorsRegistry) { override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**") 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("*") //.allowedOrigins("*")
.allowedMethods("POST", "GET", "OPTIONS", "HEAD") .allowedMethods("POST", "GET", "OPTIONS", "HEAD")
.maxAge(3600) .maxAge(3600)

View File

@ -13,7 +13,7 @@ import java.nio.charset.StandardCharsets
import java.util.* import java.util.*
@Service @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" private val firebaseBaseUrl: String = "https://identitytoolkit.googleapis.com/v1/accounts"
var statusCode: Int = 0 var statusCode: Int = 0
var error: String = "" var error: String = ""

View File

@ -16,7 +16,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structure has been changed, increment this version number # if the database structure has been changed, increment this version number
application.version=1.2.1 application.version=1.2.2
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -14,11 +14,11 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structue has been changed, increment this version number # if the database structue has been changed, increment this version number
application.version=1.2.1 application.version=1.2.2
jwt.secret=aitrainer jwt.secret=aitrainer
firebase.key=AIzaSyCUXBWV3_qzvV__ZWZA1siHftrrJpjDKh4 firebase.key=AIzaSyBLn7Bz73Z1hB-OhqphBDsskOyGmpI7J8E
openai.key=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 openai.key=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
spring.mail.properties.mail.mime.charset=UTF-8 spring.mail.properties.mail.mime.charset=UTF-8

View File

@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structue has been changed, increment this version number # if the database structue has been changed, increment this version number
application.version=1.2.1 application.version=1.2.2
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structure has been changed, increment this version number # if the database structure has been changed, increment this version number
application.version=1.2.1 application.version=1.2.2
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -246,7 +246,7 @@ class CustomerTests {
} }
@Test @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 json = "{\"firstname\":\"Tib\", \"email\": \"mr@andio.biz\", \"goal\": \"shape\", \"fitnessLevel\": \"advanced\", \"weight\": 85}"
val controller = CustomerController(customerRepository) val controller = CustomerController(customerRepository)
val response: ResponseEntity<*> = controller.clubRegistration(json, apiKey) val response: ResponseEntity<*> = controller.clubRegistration(json, apiKey)
@ -329,7 +329,7 @@ class CustomerTests {
} }
@Test @Test
fun `insert recipes successfully`() { fun `get customer successfully`() {
authToken = Tokenizer.getToken() authToken = Tokenizer.getToken()
val customer = Customer( val customer = Customer(
@ -355,7 +355,37 @@ class CustomerTests {
val customerId = JSONObject(mvcResult.response.contentAsString).getInt("customerId") val customerId = JSONObject(mvcResult.response.contentAsString).getInt("customerId")
println("MockCustomer Id $customerId") println("MockCustomer Id $customerId")
assertTrue(customerId > 0) 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 { private fun toJson(obj: Any): String {
return Gson().toJson(obj) return Gson().toJson(obj)
} }

View File

@ -21,7 +21,7 @@ class FirebaseTest {
} }
@Test @Test
fun testAuth(@Value("\${firebase.key}") apiKey: String) { fun testAuth(@Value("\${firebase.key}") apiKey: java.lang.String) {
this.firebase = Firebase(apiKey) this.firebase = Firebase(apiKey)
val email = "user@exemple.com" val email = "user@exemple.com"
val password = "verystrictpassword1" val password = "verystrictpassword1"