Merge pull request 'tibor' (#16) from tibor into master
Reviewed-on: https://git.workouttest.org/bossanyit/aitrainer_server/pulls/16
This commit is contained in:
commit
7fac7ff821
@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.aitrainer"
|
||||
version = "1.2.1"
|
||||
version = "1.2.2"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
repositories {
|
||||
|
5
data/db/update_1_2_2.sql
Normal file
5
data/db/update_1_2_2.sql
Normal 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;
|
@ -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
|
||||
|
@ -17,6 +17,7 @@ import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.*
|
||||
import javax.validation.Valid
|
||||
import java.util.Base64
|
||||
|
||||
|
||||
@RestController
|
||||
@ -42,7 +43,6 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
|
||||
@Secured
|
||||
@GetMapping("/customers/{id}")
|
||||
@CrossOrigin(origins = ["http://localhost:48102"])
|
||||
fun getCustomerById(@PathVariable(value = "id") customerId: Long): ResponseEntity<Customer> {
|
||||
val customer: Customer? = customerRepository.findById(customerId).orElse(null)
|
||||
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
|
||||
@ -90,6 +90,17 @@ class CustomerController ( private val customerRepository: CustomerRepository) {
|
||||
return ResponseEntity.ok().body(customerRepository.save(returnCustomer))
|
||||
}
|
||||
|
||||
@Secured
|
||||
@PostMapping("customers/update_password/{id}")
|
||||
fun updateCustomerPasswordById(@PathVariable(value = "id") customerId: Long, @Valid @RequestBody passwordB64: String)
|
||||
: ResponseEntity<Customer> {
|
||||
val returnCustomer: Customer = customerRepository.findById(customerId).orElse(null)
|
||||
?: return ResponseEntity.notFound().build()
|
||||
|
||||
returnCustomer.password = serviceBeans!!.passwordEncoder().encode(String(Base64.getDecoder().decode(passwordB64)))
|
||||
return ResponseEntity.ok().body(customerRepository.save(returnCustomer))
|
||||
}
|
||||
|
||||
@Secured
|
||||
@PostMapping("customers/deactivate/{id}")
|
||||
fun deactivateCustomer(@PathVariable(value = "id") customerId: Long): ResponseEntity<Customer> {
|
||||
@ -155,7 +166,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)
|
||||
|
||||
|
@ -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()) {
|
||||
|
@ -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)
|
||||
|
@ -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 = ""
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -27,6 +27,7 @@ import java.time.format.DateTimeFormatter
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
import java.util.Base64
|
||||
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@ -246,7 +247,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 +330,7 @@ class CustomerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `insert recipes successfully`() {
|
||||
fun `get customer successfully`() {
|
||||
authToken = Tokenizer.getToken()
|
||||
|
||||
val customer = Customer(
|
||||
@ -355,7 +356,70 @@ 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)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `update password`() {
|
||||
authToken = Tokenizer.getToken()
|
||||
|
||||
val id = 103
|
||||
var password = Base64.getEncoder().encodeToString("andio20091".toByteArray())
|
||||
|
||||
val mvcResult: MvcResult = mockMvc.perform(
|
||||
MockMvcRequestBuilders.post("/api/customers/update_password/$id")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.content(password)
|
||||
)
|
||||
.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)
|
||||
|
||||
password = Base64.getEncoder().encodeToString("andio2009".toByteArray())
|
||||
mockMvc.perform(
|
||||
MockMvcRequestBuilders.post("/api/customers/update_password/$id")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer $authToken")
|
||||
.content(password)
|
||||
)
|
||||
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||
}
|
||||
|
||||
private fun toJson(obj: Any): String {
|
||||
return Gson().toJson(obj)
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user