Skip to content

Commit

Permalink
Resolve conflict on user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
alperenDagi committed Dec 23, 2023
1 parent 3dbb8b4 commit ad94bde
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand All @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +23,7 @@ import retrofit2.http.*
import java.time.LocalDate
import java.time.format.DateTimeParseException


interface CategoryTreeNodeService {
@GET("categorytreenode/getMainCategories")
suspend fun getMainCategories(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -143,7 +150,7 @@ class ResqService(appContext: Context) {
return needService.createNeed(
userId = userId,
jwtToken = "Bearer $token",
role = "VICTIM",
role = "ROLE_VICTIM",
requestBody = request
)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -253,7 +262,7 @@ class ResqService(appContext: Context) {
userId = userId,
requestedRole = requestedRole,
jwtToken = "Bearer $token",
role = requestedRole
role = role
)

return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -727,15 +729,22 @@ 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
.fillMaxWidth()
.padding(4.dp)
) {
ProfileButton(
color = MyTasksColor,
text = "My Tasks",
color = RequestColor,
text = "My Request",
route = "",
navController = navController
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ class ResourceViewModel : ViewModel() {
private suspend fun getCreateResourceResponse(quantity: String, appContext: Context): Result<Int> {
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)
Expand Down

0 comments on commit ad94bde

Please sign in to comment.