diff --git a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/data/models/Profile.kt b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/data/models/Profile.kt index bd81f655..9e3c28e8 100644 --- a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/data/models/Profile.kt +++ b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/data/models/Profile.kt @@ -3,7 +3,7 @@ package com.cmpe451.resq.data.models data class ProfileData( var name: String?, var surname: String?, - var birthdate: String?, + var birth_date: String?, var gender:String?, var bloodType: String?, var phoneNumber: String?, @@ -20,15 +20,15 @@ data class ProfileData( data class UserInfoRequest( var name: String?, var surname: String?, - var birthdate: String?, + var birth_date: String?, var gender:String?, var bloodType: String?, var phoneNumber: String?, - var country: String?, - var city: String?, - var state: String?, + var Country: String?, + var City: String?, + var State: String?, var weight: Int?, var height: Int?, - val emailConfirmed: Boolean? = false, - val privacyPolicyAccepted: Boolean? = false, + val isEmailConfirmed: Boolean? = false, + val isPrivacyPolicyAccepted: Boolean? = false, ) \ No newline at end of file diff --git a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/data/remote/ResqService.kt b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/data/remote/ResqService.kt index bceb198c..c06aeff9 100644 --- a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/data/remote/ResqService.kt +++ b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/data/remote/ResqService.kt @@ -14,6 +14,7 @@ import com.cmpe451.resq.data.models.Need import com.cmpe451.resq.data.models.ProfileData import com.cmpe451.resq.data.models.RegisterRequestBody import com.cmpe451.resq.data.models.UserInfoRequest +import com.google.gson.GsonBuilder import okhttp3.ResponseBody import retrofit2.Response import retrofit2.Retrofit @@ -22,6 +23,7 @@ import retrofit2.http.* import java.time.LocalDate import java.time.format.DateTimeParseException + interface CategoryTreeNodeService { @GET("categorytreenode/getMainCategories") suspend fun getMainCategories( @@ -95,9 +97,14 @@ interface ProfileService { } class ResqService(appContext: Context) { + + var gson = GsonBuilder() + .setLenient() + .create() + private val retrofit: Retrofit = Retrofit.Builder() .baseUrl(Constants.BACKEND_URL) - .addConverterFactory(GsonConverterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) .build() private val categoryTreeNodeService: CategoryTreeNodeService = retrofit.create(CategoryTreeNodeService::class.java) @@ -143,7 +150,7 @@ class ResqService(appContext: Context) { return needService.createNeed( userId = userId, jwtToken = "Bearer $token", - role = "VICTIM", + role = "ROLE_VICTIM", requestBody = request ) } @@ -214,7 +221,7 @@ class ResqService(appContext: Context) { state = response.body()?.state, emailConfirmed = response.body()?.emailConfirmed, privacyPolicyAccepted = response.body()?.privacyPolicyAccepted, - birthdate = response.body()?.birthdate.toString(), + birth_date = response.body()?.birth_date.toString(), ) } @RequiresApi(Build.VERSION_CODES.O) @@ -226,15 +233,17 @@ class ResqService(appContext: Context) { val request = UserInfoRequest( name = profileData.name ?: "", surname = profileData.surname ?: "", - birthdate = null, - country = profileData.country ?: "", - city = profileData.city ?: "", - state = profileData.state ?: "", + birth_date = null, + Country = profileData.country ?: "", + City = profileData.city ?: "", + State = profileData.state ?: "", bloodType = profileData.bloodType ?: "", height = profileData.height, weight = profileData.weight, gender = profileData.gender ?: "", phoneNumber = profileData.phoneNumber ?: "", + isEmailConfirmed = true, + isPrivacyPolicyAccepted = true ) return profileService.updateProfile( userId = userId, @@ -253,7 +262,7 @@ class ResqService(appContext: Context) { userId = userId, requestedRole = requestedRole, jwtToken = "Bearer $token", - role = requestedRole + role = role ) return response diff --git a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/ui/views/screens/ProfileScreen.kt b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/ui/views/screens/ProfileScreen.kt index 84660f1e..19cdaeb8 100644 --- a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/ui/views/screens/ProfileScreen.kt +++ b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/ui/views/screens/ProfileScreen.kt @@ -271,6 +271,9 @@ fun Profile(profileData:ProfileData, navController: NavController, availableRole val modalBottomSheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden) + LaunchedEffect(Unit) { + viewModel.getUserData(appContext) + } ModalBottomSheetLayout( sheetContent = { BottomSheetContent( @@ -554,20 +557,19 @@ fun Profile(profileData:ProfileData, navController: NavController, availableRole verticalArrangement = Arrangement.spacedBy(8.dp), ) { - when (UserSessionManager.getInstance(appContext).getSelectedRole()) { - "VICTIM" -> { - VictimProfileButtons(navController = navController) + when { + UserSessionManager.getInstance(appContext).getUserRoles().contains("FACILITATOR") -> { + FacilitatorProfileButtons(navController = navController) } - "RESPONDER" -> { + UserSessionManager.getInstance(appContext).getUserRoles().contains("RESPONDER") -> { ResponderProfileButtons(navController = navController) } - "FACILITATOR" -> { - FacilitatorProfileButtons(navController = navController) + UserSessionManager.getInstance(appContext).getUserRoles().contains("VICTIM") -> { + VictimProfileButtons(navController = navController) } } - Spacer(modifier = Modifier.height(20.dp)) Row( modifier = Modifier.align(Alignment.Start) @@ -595,7 +597,7 @@ fun Profile(profileData:ProfileData, navController: NavController, availableRole height = height.takeIf { it.isNotEmpty() }?.toInt(), weight = weight.takeIf { it.isNotEmpty() }?.toInt(), phoneNumber = phoneNumber, - birthdate = null + birth_date = null )) if (viewModel.updateMessage.value != null) { message = "Details saved successfully." @@ -727,6 +729,13 @@ fun ResponderProfileButtons(navController: NavController) { route = "", navController = navController ) + Spacer(modifier = Modifier.width(30.dp)) + ProfileButton( + color = MyTasksColor, + text = "My Tasks", + route = "", + navController = navController + ) } Row( modifier = Modifier @@ -734,8 +743,8 @@ fun ResponderProfileButtons(navController: NavController) { .padding(4.dp) ) { ProfileButton( - color = MyTasksColor, - text = "My Tasks", + color = RequestColor, + text = "My Request", route = "", navController = navController ) diff --git a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/viewmodels/ProfileViewModel.kt b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/viewmodels/ProfileViewModel.kt index 5aeed2f4..639fa5a4 100644 --- a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/viewmodels/ProfileViewModel.kt +++ b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/viewmodels/ProfileViewModel.kt @@ -46,7 +46,7 @@ class ProfileViewModel() : ViewModel() { val api = ResqService(appContext) viewModelScope.launch { try { - Log.d("Update DATA", "") + val response = api.updateUserData(profileData) if (response.isSuccessful) { diff --git a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/viewmodels/ResourceViewModel.kt b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/viewmodels/ResourceViewModel.kt index 37b34fea..9d687bf2 100644 --- a/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/viewmodels/ResourceViewModel.kt +++ b/resq/mobile/ResQ/app/src/main/java/com/cmpe451/resq/viewmodels/ResourceViewModel.kt @@ -89,14 +89,13 @@ class ResourceViewModel : ViewModel() { private suspend fun getCreateResourceResponse(quantity: String, appContext: Context): Result { val api = ResqService(appContext) val categoryId = _selectedItem.value?.id?.toString() ?: _selectedType.value?.id?.toString() ?: "" - if (categoryId.isNotEmpty()) { val requestBody = CreateResourceRequestBody( senderId = null, categoryTreeId = categoryId, quantity = quantity.toIntOrNull() ?: 0, - latitude = 0.0, - longitude = 0.0, + latitude = 41.086571, + longitude = 29.046109, gender = "FEMALE" ) val response = api.createResource(requestBody)