Fix errors in api calls, move base url to gradle properties

This commit is contained in:
Reimar 2025-04-30 12:31:54 +02:00
parent 0f791cc642
commit dfa9abc4b9
Signed by: Reimar
GPG Key ID: 93549FA07F0AE268
5 changed files with 11 additions and 3 deletions

View File

@ -19,7 +19,7 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "API_BASE_URL", gradleLocalProperties(projectDir, providers).getProperty("API_BASE_URL"))
buildConfigField("String", "API_BASE_URL", project.property("API_BASE_URL").toString())
}
buildTypes {

View File

@ -0,0 +1 @@
API_BASE_URL="https://easyeat.mercantec.tech"

View File

@ -31,7 +31,10 @@ class RegisterActivity : AppCompatActivity() {
try {
register(email, username, password)
} catch (e: ApiRequestException) {
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
runOnUiThread {
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
}
return@thread
}

View File

@ -59,6 +59,8 @@ inline fun <reified Req, reified Res> requestJson(method: String, path: String,
throw ApiRequestException(error.message, null)
} catch (e: SerializationException) {
if (e.message != null)
Log.e("EasyEat", e.message!!)
Log.e("EasyEat", response.body)
throw ApiRequestException("Request failed with HTTP status code ${response.code}", e)
@ -68,6 +70,8 @@ inline fun <reified Req, reified Res> requestJson(method: String, path: String,
try {
return Json.decodeFromString<Res>(response.body)
} catch (e: SerializationException) {
if (e.message != null)
Log.e("EasyEat", e.message!!)
Log.e("EasyEat", response.body)
throw ApiRequestException("Failed to parse response: $response", e)

View File

@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable
data class LoginRequest(val emailUsr: String, val password: String)
@Serializable
data class LoginResponse(val token: String, val username: String, val id: Int, val refreshToken: String)
data class LoginResponse(val token: String, val userName: String, val id: Int, val refreshToken: String)
fun login(email: String, password: String) {
val request = LoginRequest(email, password)