Skip to content

Commit

Permalink
Merge pull request #498 from bounswe/feature/mobile-360-update-user-p…
Browse files Browse the repository at this point in the history
…rofiles

Feature/mobile 360 update user profiles
  • Loading branch information
alperenDagi authored Nov 27, 2023
2 parents 53d2fd2 + 952d58e commit 8091bc5
Show file tree
Hide file tree
Showing 6 changed files with 552 additions and 378 deletions.
9 changes: 8 additions & 1 deletion resq/mobile/ResQ/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,18 @@ 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,25 +3,33 @@ package com.cmpe451.resq.data.models
data class ProfileData(
var name: String?,
var surname: String?,
var email: String?,
var roles: List<String>?,
var selectedRole: String?,
var birthdate: String?,
var gender:String?,
var bloodType: String?,
var phoneNumber: String?,
var country: String?,
var city: String?,
var state: String?,
var bloodType: String?,
var weight: 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 height: String?,
var year: String?,
var month: String?,
var day: 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,
)

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,6 +49,7 @@ interface NeedService {
): Response<Int>



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

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

): Response<ProfileData>



@POST("user/requestRole")
suspend fun selectRole(
Expand All @@ -85,14 +89,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<ResponseBody>

): Response<String>
}

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

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

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

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

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(
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(),
)
return profileData
}

@RequiresApi(Build.VERSION_CODES.O)
suspend fun updateUserData(profileData: ProfileData): Response<ResponseBody>{
suspend fun updateUserData(profileData: ProfileData): Response<String> {
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 ?: "",
email = profileData.email ?: "",
roles = profileData.roles ?: listOf(),
birth_date = formattedBirthDate,
birthdate = null,
country = profileData.country ?: "",
city = profileData.city ?: "",
state = profileData.state ?: "",
bloodType = profileData.bloodType ?: "",
height = profileData.height?.toIntOrNull(),
weight = profileData.weight?.toIntOrNull(),
height = profileData.height,
weight = profileData.weight,
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 @@ -262,7 +267,6 @@ class ResqService(appContext: Context) {
jwtToken = "Bearer $token",
role = requestedRole
)

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

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

0 comments on commit 8091bc5

Please sign in to comment.