-
Notifications
You must be signed in to change notification settings - Fork 0
Profile Page Implementation #105
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
Open
melissavelasquezz
wants to merge
8
commits into
main
Choose a base branch
from
melissa/workout-history-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7bb9c0a
Updated schema and User graphqls
melissavelasquezz 7aeedf9
Updated UI to match designs
melissavelasquezz 200d397
Implemented ProfileRepo and updated User model and repo
melissavelasquezz fc3d451
Implemented Profile VM, updates Login VM and network
melissavelasquezz 79e36f9
tested logworkout call for profile page testing, WIP
melissavelasquezz 07f6cab
Rebased and Addressed Copilot Comments
melissavelasquezz 2af071e
Adressing Comments
melissavelasquezz 80817e7
Rebased and Addressed comments
melissavelasquezz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/cornellappdev/uplift/data/models/ProfileData.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.cornellappdev.uplift.data.models | ||
|
|
||
| import android.net.Uri | ||
|
|
||
|
|
||
| data class ProfileData( | ||
| val name: String, | ||
| val netId: String, | ||
| val encodedImage: String?, | ||
| val totalGymDays: Int, | ||
| val activeStreak: Int, | ||
| val maxStreak: Int, | ||
| val streakStart: String?, | ||
| val workoutGoal: Int, | ||
| val workouts: List<WorkoutDomain>, | ||
| val weeklyWorkoutDays: List<String> | ||
| ) |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/cornellappdev/uplift/data/models/UserInfo.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| package com.cornellappdev.uplift.data.models | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
|
|
||
| @Serializable | ||
| data class UserInfo( | ||
| val id: String, | ||
| val email: String, | ||
| val name: String, | ||
| val netId: String, | ||
| val encodedImage: String?, | ||
| val activeStreak: Int?, | ||
| val maxStreak: Int?, | ||
| val streakStart: String?, | ||
| val workoutGoal: Int?, | ||
| val totalGymDays: Int | ||
| ) |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/cornellappdev/uplift/data/models/WorkoutDomain.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.cornellappdev.uplift.data.models | ||
|
|
||
| data class WorkoutDomain( | ||
| val gymName: String, | ||
| val timestamp: Long | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
app/src/main/java/com/cornellappdev/uplift/data/repositories/ProfileRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package com.cornellappdev.uplift.data.repositories | ||
|
|
||
| import android.util.Log | ||
| import com.apollographql.apollo.ApolloClient | ||
| import com.cornellappdev.uplift.GetUserByNetIdQuery | ||
| import com.cornellappdev.uplift.GetWeeklyWorkoutDaysQuery | ||
| import com.cornellappdev.uplift.GetWorkoutsByIdQuery | ||
| import com.cornellappdev.uplift.SetWorkoutGoalsMutation | ||
| import com.cornellappdev.uplift.data.models.ProfileData | ||
| import com.cornellappdev.uplift.data.models.WorkoutDomain | ||
| import kotlinx.coroutines.async | ||
| import kotlinx.coroutines.coroutineScope | ||
| import java.time.Instant | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
|
|
||
| @Singleton | ||
| class ProfileRepository @Inject constructor( | ||
| private val userInfoRepository: UserInfoRepository, | ||
| private val apolloClient: ApolloClient | ||
| ) { | ||
| suspend fun getProfile(): Result<ProfileData> = runCatching { | ||
| val netId = userInfoRepository.getNetIdFromDataStore() | ||
| ?: throw IllegalStateException("NetId missing") | ||
|
|
||
| val userResponse = apolloClient.query( | ||
| GetUserByNetIdQuery(netId) | ||
| ).execute() | ||
|
|
||
| if (userResponse.hasErrors()) { | ||
| Log.e("ProfileRepo", "User query errors: ${userResponse.errors}") | ||
| throw IllegalStateException("User query failed") | ||
| } | ||
|
|
||
| val user = userResponse.data?.getUserByNetId?.firstOrNull()?.userFields | ||
| ?: throw IllegalStateException("User not found") | ||
|
|
||
| val userId = user.id.toIntOrNull() | ||
| ?: throw IllegalStateException("Invalid user ID: ${user.id}") | ||
|
|
||
| coroutineScope { | ||
| val workoutDeferred = async { | ||
| apolloClient.query(GetWorkoutsByIdQuery(userId)).execute() | ||
| } | ||
| val weeklyDeferred = async { | ||
| apolloClient.query(GetWeeklyWorkoutDaysQuery(userId)).execute() | ||
| } | ||
|
|
||
| val workoutResponse = workoutDeferred.await() | ||
| if (workoutResponse.hasErrors()) { | ||
| Log.e("ProfileRepo", "Workout query errors: ${workoutResponse.errors}") | ||
| throw IllegalStateException("Workout query failed") | ||
| } | ||
|
|
||
| val workouts = workoutResponse.data?.getWorkoutsById?.filterNotNull().orEmpty() | ||
|
|
||
| val workoutDomain = workouts.map { | ||
| WorkoutDomain( | ||
| gymName = it.workoutFields.gymName, | ||
| timestamp = Instant.parse(it.workoutFields.workoutTime.toString()) | ||
| .toEpochMilli() | ||
| ) | ||
| } | ||
|
|
||
| val weeklyResponse = weeklyDeferred.await() | ||
| if (weeklyResponse.hasErrors()) { | ||
| Log.e("ProfileRepo", "Weekly query errors: ${weeklyResponse.errors}") | ||
| throw IllegalStateException("Weekly workout days query failed") | ||
| } | ||
|
|
||
| val weeklyDays = weeklyResponse.data?.getWeeklyWorkoutDays?.filterNotNull().orEmpty() | ||
|
|
||
| ProfileData( | ||
| name = user.name, | ||
| netId = user.netId, | ||
| encodedImage = user.encodedImage, | ||
| totalGymDays = user.totalGymDays, | ||
| activeStreak = user.activeStreak, | ||
| maxStreak = user.maxStreak, | ||
| streakStart = user.streakStart?.toString(), | ||
| workoutGoal = user.workoutGoal ?: 0, | ||
| workouts = workoutDomain, | ||
| weeklyWorkoutDays = weeklyDays | ||
| ) | ||
| } | ||
| }.onFailure { e -> | ||
| Log.e("ProfileRepo", "Failed to load profile", e) | ||
| } | ||
|
|
||
| suspend fun setWorkoutGoal(goal: Int): Result<Unit> = runCatching { | ||
| val userId = userInfoRepository.getUserIdFromDataStore()?.toIntOrNull() | ||
| ?: throw IllegalStateException("Missing user ID") | ||
|
|
||
| val response = apolloClient | ||
| .mutation( | ||
| SetWorkoutGoalsMutation( | ||
| id = userId, | ||
| workoutGoal = goal | ||
| ) | ||
| ) | ||
| .execute() | ||
|
|
||
| if (response.hasErrors()) { | ||
| throw IllegalStateException("Goal update failed") | ||
| } | ||
| }.onFailure { e -> | ||
| Log.e("ProfileRepo", "Failed to update workout goal", e) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Not sure if you need to separate into two variables if only used once