Skip to content

Commit

Permalink
Revert "Feature/mobile 360 update user profiles"
Browse files Browse the repository at this point in the history
  • Loading branch information
alperenDagi authored Nov 27, 2023
1 parent 7b1d808 commit 02b6add
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 552 deletions.
9 changes: 1 addition & 8 deletions resq/mobile/ResQ/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,11 @@ dependencies {
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")

// Coil
implementation("io.coil-kt:coil-compose:2.4.0")

}

}

secrets{
propertiesFileName = "secrets.properties"

ignoreList.add("keyToIgnore") // Ignore the key "keyToIgnore"
ignoreList.add("sdk.*") // Ignore all keys matching the regexp "sdk.*"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,25 @@ package com.cmpe451.resq.data.models
data class ProfileData(
var name: String?,
var surname: String?,
var birthdate: String?,
var gender:String?,
var bloodType: String?,
var email: String?,
var roles: List<String>?,
var selectedRole: String?,
var phoneNumber: String?,
var country: String?,
var city: String?,
var state: String?,
var weight: Int?,
var height: Int?,
val emailConfirmed: Boolean? = false,
val privacyPolicyAccepted: Boolean? = false,
)


data class UserInfoRequest(
var name: String?,
var surname: String?,
var birthdate: String?,
var gender:String?,
var bloodType: String?,
var phoneNumber: String?,
var country: String?,
var city: String?,
var state: String?,
var weight: Int?,
var height: Int?,
val emailConfirmed: Boolean? = false,
val privacyPolicyAccepted: Boolean? = false,
var weight: String?,
var gender:String?,
var height: String?,
var year: String?,
var month: String?,
var day: String?
)

data class UserInfoResponse(
val name: String,
val surname: String,
val email: String,
val roles: List<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +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.cmpe451.resq.data.models.UserInfo
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.Retrofit
Expand Down Expand Up @@ -49,7 +49,6 @@ interface NeedService {
): Response<Int>



@GET("need/filterByDistance")
fun filterNeedByDistance(
@Query("latitude") latitude: Double,
Expand All @@ -70,15 +69,12 @@ interface AuthService {
}

interface ProfileService {
@GET("profile/getProfileInfo")
@GET("user/getUserInfo")
suspend fun getUserInfo(
@Query("userId") userId: Int,
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String

): Response<ProfileData>


): Response<UserInfoResponse>

@POST("user/requestRole")
suspend fun selectRole(
Expand All @@ -89,14 +85,14 @@ interface ProfileService {
): Response<String>



@POST("profile/updateProfile")
suspend fun updateProfile(
@Query("userId") userId: Int,
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String,
@Body request: UserInfoRequest
): Response<String>
): Response<ResponseBody>

}

class ResqService(appContext: Context) {
Expand Down Expand Up @@ -179,16 +175,17 @@ class ResqService(appContext: Context) {
if (birthDate.isNullOrBlank()) {
return null
}
return try {

try {
val date = LocalDate.parse(birthDate)
val year = date.year.toString()
val month = date.monthValue.toString()
val day = date.dayOfMonth.toString()

Triple(year, month, day)
return Triple(year, month, day)
} catch (e: DateTimeParseException) {
//TO DO Handle parsing error if needed
null
return null
}
}

Expand All @@ -205,57 +202,55 @@ class ResqService(appContext: Context) {
role = selectedRole
)

return ProfileData(
name = response.body()?.name,
surname = response.body()?.surname,
city = response.body()?.city,
country = response.body()?.country,
gender = response.body()?.gender,
bloodType = response.body()?.bloodType,
height = response.body()?.height,
weight = response.body()?.weight,
phoneNumber = response.body()?.phoneNumber,
state = response.body()?.state,
emailConfirmed = response.body()?.emailConfirmed,
privacyPolicyAccepted = response.body()?.privacyPolicyAccepted,
birthdate = response.body()?.birthdate.toString(),
val parsedDate = parseBirthDate(response.body()?.birth_date)
val (parsedYear, parsedMonth, parsedDay) = parsedDate ?: Triple("", "", "")
val profileData = ProfileData(
name = response.body()?.name, surname = response.body()?.surname,
email = response.body()?.email,
roles = response.body()?.roles, selectedRole = selectedRole,
year = parsedYear, month = parsedMonth, day = parsedDay,
city = response.body()?.city, country = response.body()?.country,
gender = response.body()?.gender, bloodType = response.body()?.bloodType, height = response.body()?.height.toString(), weight = response.body()?.weight.toString(),
phoneNumber = response.body()?.phoneNumber, state = response.body()?.state,
emailConfirmed = response.body()?.emailConfirmed, privacyPolicyAccepted = response.body()?.privacyPolicyAccepted

)
return profileData
}

@RequiresApi(Build.VERSION_CODES.O)
suspend fun updateUserData(profileData: ProfileData): Response<String> {
suspend fun updateUserData(profileData: ProfileData): Response<ResponseBody>{
val token = userSessionManager.getUserToken() ?: ""
val userId = userSessionManager.getUserId()
val selectedRole = userSessionManager.getSelectedRole() ?: ""

val formattedBirthDate = profileData.getFormattedBirthDate()
val request = UserInfoRequest(
name = profileData.name ?: "",
name = profileData.name ?: "",
surname = profileData.surname ?: "",
birthdate = null,
email = profileData.email ?: "",
roles = profileData.roles ?: listOf(),
birth_date = formattedBirthDate,
country = profileData.country ?: "",
city = profileData.city ?: "",
state = profileData.state ?: "",
bloodType = profileData.bloodType ?: "",
height = profileData.height,
weight = profileData.weight,
height = profileData.height?.toIntOrNull(),
weight = profileData.weight?.toIntOrNull(),
gender = profileData.gender ?: "",
phoneNumber = profileData.phoneNumber ?: "",
)
return profileService.updateProfile(
userId = userId,
jwtToken = "Bearer $token",
role = selectedRole,
request = request
)
val response = profileService.updateProfile(
userId = userId,
jwtToken = "Bearer $token",
role = selectedRole,
request = request
)
return response



}

suspend fun selectRole(requestedRole: String): Response<String> {
val userId = userSessionManager.getUserId()
val token = userSessionManager.getUserToken() ?: ""
Expand All @@ -267,6 +262,7 @@ class ResqService(appContext: Context) {
jwtToken = "Bearer $token",
role = requestedRole
)

return response
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ val LightGreen = Color(0xff20df7f)
val ResourceColor = Color(0xFF397FE7)
val RequestColor = Color(0xFFB356AF)

val MyTasksColor = Color(0XFFE7A139)
val OngoingTasksColor = Color(0xFFE16834)
val BackgroundColor = Color(0xFFEFEFEF)
val BackgroundColor = Color(0xFFEFEFEF)
Loading

0 comments on commit 02b6add

Please sign in to comment.