Problem mit Problemen integer in Supabase aus der Kotlin -App aktualisierenAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Problem mit Problemen integer in Supabase aus der Kotlin -App aktualisieren

Post by Anonymous »

Ich versuche, ein INT4 -Feld auf Supabase zu aktualisieren, aber es passiert nichts, wenn der Code ausgeführt wird. Die Updates im When Block für Oncalldates, Gymcalldates und Leavedates funktionieren perfekt, selbst im sonstigen Block, bis ich < /p>

"Staff_ROLE" hinzufügen kann. Staff.Unit, < /p>
< /blockquote>
zur Karte. Ich habe alle Vorschläge von Deepseek und Chatgpt, die gleichen Ergebnisse ausprobiert. < /P>

Code: Select all

suspend fun editStaffData(context: Context, staff: StaffMember, imageBitmap: Bitmap?, fieldToEdit: String): Result {
return try {
// If a new imageUri is provided, upload it and update the staff's imageUrl.
val updatedStaff = if (imageBitmap != null) {
val imageUrl = uploadImage(context, imageBitmap, staff.id)
staff.copy(imageUrl = imageUrl)
} else {
staff
}

when(fieldToEdit) {
DatabaseField.OnCallDates.name -> {
val updatedCallDates = updatedStaff.onCallDates.ifEmpty {
emptyList()
}

withContext(Dispatchers.IO) {
val client = getSupabaseClient()
client.from("staff")
.update(mapOf("on_call_dates" to updatedCallDates)) {
filter {
eq("id", staff.id)
}
}
}
}

DatabaseField.GymCallDates.name -> {
val updatedGymDates = updatedStaff.gymCallDates.ifEmpty {
emptyList()
}

withContext(Dispatchers.IO) {
val client = getSupabaseClient()
client.from("staff")
.update(mapOf("gym_call_dates" to updatedGymDates)) {
filter {
eq("id", staff.id)
}
}
}
}

DatabaseField.LeaveDates.name -> {
val updatedLeaveDates = updatedStaff.leaveDates.ifEmpty {
emptyList()
}

withContext(Dispatchers.IO) {
val client = getSupabaseClient()
client.from("staff")
.update(mapOf("leave_dates" to updatedLeaveDates)) {
filter {
eq("id", staff.id)
}
}
}
}

else -> {
withContext(Dispatchers.IO) {
val client = getSupabaseClient()

val updatedStaffMap = if (imageBitmap != null) {
mapOf(
"first_name" to staff.firstName,
"last_name" to staff.lastName,
"phone" to staff.phone,
"image_url" to staff.imageUrl
)
} else{
mapOf(
"first_name" to staff.firstName,
"last_name" to staff.lastName,
"phone" to staff.phone
)
}

client.from("staff")
.update( updatedStaffMap
) {
filter { eq("id", staff.id) }
}
}
}
}

Result.success(Unit)
} catch (e: Exception) {
Result.failure(e)
}
}
< /code>
Ich brauche Hilfe, [url=viewtopic.php?t=14917]ich möchte[/url] den Datentyp nicht in Zeichenfolge ändern müssen.  Dies ist die DataClass: < /p>
    @Serializable
data class StaffMember(
@SerialName("id") val id: String = "",
@SerialName("first_name") val firstName: String,
@SerialName("last_name") val lastName: String,
@SerialName("staff_role") val staffRole: Int,
@SerialName("unit") val unit: Int,
@SerialName("on_call_dates") val onCallDates: List = emptyList(),
@SerialName("gym_call_dates") val gymCallDates: List = emptyList(),
@SerialName("leave_dates") val leaveDates: List = emptyList(),
@SerialName("phone") val phone: String,
@SerialName("image_url") val imageUrl: String = ""
)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post