Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merging from dev to my branch #502

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions resq/frontend/src/components/Resource/ResourceAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function CreateResourceForm() {
latitude: parseFloat(latitudeValue),
});
};

/*
const handleChange = (event) => {
const { name, value } = event.target;
setResource(prevState => ({
Expand All @@ -51,7 +51,7 @@ export default function CreateResourceForm() {
const handleSubmit = (event) => {
event.preventDefault();
console.log(resource);
};
};*/

return (
<ThemeProvider theme={customTheme}>
Expand Down
2 changes: 1 addition & 1 deletion resq/frontend/src/components/Resource/ResourceContext.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { createContext, useState, useContext } from 'react';

const ResourceContext = createContext();
export const ResourceContext = createContext({});

export const useResource = () => useContext(ResourceContext);

Expand Down
3 changes: 1 addition & 2 deletions resq/frontend/src/pages/ResourceCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import ResourceAddress from '../components/Resource/ResourceAddress';
import ResourceDetail1 from '../components/Resource/ResourceDetail1';
import ResourceDetail2 from '../components/Resource/ResourceDetail2';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import { ResourceProvider } from '../components/Resource/ResourceContext';
import { useResource } from './ResourceContext';
import {ResourceProvider, useResource} from '../components/Resource/ResourceContext';
import axios from 'axios';


Expand Down
1 change: 1 addition & 0 deletions resq/mobile/ResQ/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ dependencies {
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
implementation("io.coil-kt:coil-compose:2.4.0")
}

secrets{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,32 @@ 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 gender:String?,
var height: String?,
var year: String?,
var month: String?,
var day: 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>

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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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 @@ -69,12 +68,12 @@ 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 @@ -91,7 +90,7 @@ interface ProfileService {
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String,
@Body request: UserInfoRequest
): Response<ResponseBody>
): Response<String>

}

Expand Down Expand Up @@ -176,7 +175,7 @@ class ResqService(appContext: Context) {
return null
}

try {
return try {
val date = LocalDate.parse(birthDate)
val year = date.year.toString()
val month = date.monthValue.toString()
Expand All @@ -185,7 +184,7 @@ class ResqService(appContext: Context) {
return Triple(year, month, day)
} catch (e: DateTimeParseException) {
//TO DO Handle parsing error if needed
return null
null
}
}

Expand All @@ -202,53 +201,47 @@ 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 ?: "",
)
val response = profileService.updateProfile(
return profileService.updateProfile(
userId = userId,
jwtToken = "Bearer $token",
role = selectedRole,
request = request
)
return response



}

suspend fun selectRole(requestedRole: String): Response<String> {
Expand All @@ -265,4 +258,4 @@ class ResqService(appContext: Context) {

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 MyTasksColor = Color(0XFFE7A139)
val OngoingTasksColor = Color(0xFFE16834)
val BackgroundColor = Color(0xFFEFEFEF)
Loading
Loading