auth to server-V5
This commit is contained in:
parent
299e4c2d1d
commit
880db5b251
4 changed files with 37 additions and 13 deletions
|
|
@ -31,7 +31,7 @@ class MainActivity : ComponentActivity() {
|
||||||
val currentAppTheme by themeViewModel.currentTheme.collectAsState()
|
val currentAppTheme by themeViewModel.currentTheme.collectAsState()
|
||||||
|
|
||||||
Login_V3Theme(appTheme = currentAppTheme) {
|
Login_V3Theme(appTheme = currentAppTheme) {
|
||||||
Technologia()
|
HealthCheckScreen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package com.example.login_v3.auth
|
package com.example.login_v3.auth
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import com.example.login_v3.data.health.HealthCheckViewModel
|
import com.example.login_v3.data.health.HealthCheckViewModel
|
||||||
|
|
@ -27,17 +29,28 @@ fun HealthCheckScreen(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
//health
|
//health
|
||||||
Text(text = "API Health", style = MaterialTheme.typography.titleLarge)
|
Text(
|
||||||
|
text = "API Health",
|
||||||
|
style = MaterialTheme.typography.titleLarge,
|
||||||
|
color = Color.Gray
|
||||||
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
// 顯示狀態
|
// 顯示狀態
|
||||||
Text(text = "Status: $status", style = MaterialTheme.typography.bodyLarge)
|
Text(
|
||||||
|
text = "Status: $status",
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
color = Color.Gray
|
||||||
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
// 顯示詳細訊息
|
// 顯示詳細訊息
|
||||||
Text(text = detail, style = MaterialTheme.typography.bodyMedium)
|
Text(text = detail,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = Color.Gray
|
||||||
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(20.dp))
|
Spacer(modifier = Modifier.height(20.dp))
|
||||||
|
|
||||||
|
|
@ -48,16 +61,23 @@ fun HealthCheckScreen(
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
Button(onClick = { viewModel.checkApiHealth() }) {
|
Button(
|
||||||
|
onClick = { viewModel.checkApiHealth() },
|
||||||
|
modifier = Modifier
|
||||||
|
.background(color = Color.Gray)
|
||||||
|
) {
|
||||||
Text("Check Health")
|
Text("Check Health")
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
Spacer(modifier = Modifier.width(12.dp))
|
||||||
|
|
||||||
OutlinedButton(onClick = {
|
OutlinedButton(
|
||||||
// 若需要重置狀態,可在 ViewModel 加一個 reset 方法,或直接呼叫 repository 前先改狀態
|
onClick = {}
|
||||||
}) {
|
) {
|
||||||
Text("Reset")
|
Text(
|
||||||
|
text = "reset",
|
||||||
|
color = Color.Gray
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
package com.example.login_v3.data.api.api_class
|
package com.example.login_v3.data.api.api_class
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
data class LoginRequest(
|
data class LoginRequest(
|
||||||
val username: String,
|
val username: String,
|
||||||
val password: String
|
val password: String
|
||||||
)
|
)
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
data class LoginResponse(
|
data class LoginResponse(
|
||||||
val token: String,
|
val token: String,
|
||||||
val userId: String
|
val userId: String
|
||||||
|
|
@ -14,7 +15,7 @@ data class LoginResponse(
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class RegisterRequest(
|
data class RegisterRequest(
|
||||||
val display_name: String,
|
@Json(name = "display_name") val displayName: String, // 將 JSON 的底線對應到 Kotlin 的駝峰
|
||||||
val email: String,
|
val email: String,
|
||||||
val password: String,
|
val password: String,
|
||||||
val username: String
|
val username: String
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
package com.example.login_v3.data.api.api_class
|
package com.example.login_v3.data.api.api_class
|
||||||
|
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
data class FriendRequest(
|
data class FriendRequest(
|
||||||
val friendId: String
|
val friendId: String
|
||||||
)
|
)
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
data class ApiResponse(
|
data class ApiResponse(
|
||||||
val success: Boolean,
|
val success: Boolean,
|
||||||
val message: String
|
val message: String
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue