Skip to content
Open
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
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ android {
buildConfigField("String", "SOCKET_URL", "\"${secrets.getProperty("SOCKET_URL_PROD")}\"")
}
release {
buildConfigField("String", "BASE_URL", "\"${secrets.getProperty("API_URL_DEV")}\"")
// Match the endpoint used to download the current GraphQL schema.
buildConfigField("String", "BASE_URL", "\"${secrets.getProperty("API_URL_PROD")}\"")
buildConfigField(
"String",
"SOCKET_URL",
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/graphql/Account.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
query AccountProfile {
me {
id
name
favoriteTeams { gender sport }
bookmarkedHighlightIds
}
myBookmarkedHighlights { ...AccountHighlight }
}

fragment AccountHighlight on YoutubeVideoType {
id
title
thumbnail
url
publishedAt
duration
sportsType
}

query HighlightCatalog {
youtubeVideos { ...AccountHighlight }
}

mutation AddFavoriteTeam($gender: String!, $sport: String!) {
addFavoriteTeam(gender: $gender, sport: $sport) { success }
}

mutation RemoveFavoriteTeam($gender: String!, $sport: String!) {
removeFavoriteTeam(gender: $gender, sport: $sport) { success }
}

mutation AddBookmarkedHighlight($highlightId: String!) {
addBookmarkedHighlight(highlightId: $highlightId) { success }
}

mutation RemoveBookmarkedHighlight($highlightId: String!) {
removeBookmarkedHighlight(highlightId: $highlightId) { success }
}

mutation DeleteUser {
deleteUser { success }
}
125 changes: 112 additions & 13 deletions app/src/main/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ type Query {

youtubeVideo(id: String!): YoutubeVideoType

myBookmarkedHighlights: [YoutubeVideoType]

games("Number of games to return" limit: Int = 100, "Number of games to skip" offset: Int = 0): [GameType]

game(id: String!): GameType
Expand All @@ -19,16 +21,20 @@ type Query {

gamesByDate(startDate: DateTime!, endDate: DateTime!): [GameType]

gamesByLocation(onCampus: Boolean!): [GameType]

"""
Current user's favorited games (requires auth).
Current user's favorited teams, identified by gender and sport (requires auth).
"""
myFavoritedGames: [GameType]
myFavoritedTeams: [FavoriteTeamType]

teams: [TeamType]

team(id: String!): TeamType

teamByName(name: String!): TeamType

me: UserType!
}

"""
Expand All @@ -55,6 +61,11 @@ type ArticleType {
url: String!
}

"""
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
"""
scalar String

"""
A GraphQL type representing a YouTube video.

Expand Down Expand Up @@ -105,6 +116,10 @@ Attributes:
- `box_score`: The box score of the game.
- `score_breakdown`: The score breakdown of the game.
- `ticket_link`: The ticket link of the game. (optional)
- `recap_link`: The recap article link. (optional)
- `recap_article_title`: The recap article title. (optional)
- `recap_article_image`: The recap article image. (optional)
- `recap_published_at`: The recap article publication date. (optional)
"""
type GameType {
id: String
Expand Down Expand Up @@ -136,12 +151,21 @@ type GameType {
utcDate: String

ticketLink: String

recapLink: String

recapArticleTitle: String

recapArticleImage: String

recapPublishedAt: String
}

"""
Represents an individual entry in the box score of a game.

Attributes:
- `play_id`: Sidearm's stable id for the play, when it came from a live feed.
- `team`: The team involved in the scoring event.
- `period`: The period or inning of the event.
- `time`: The time of the scoring event.
Expand All @@ -153,6 +177,8 @@ Attributes:
- `opp_score`: Opponent's score at the time of the event.
"""
type BoxScoreEntryType {
playId: String

team: String

period: String
Expand All @@ -172,6 +198,11 @@ type BoxScoreEntryType {
oppScore: Int
}

"""
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31 - 1) and 2^31 - 1 since represented in JSON as double-precision floating point numbers specifiedby [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).
"""
scalar Int

"""
A GraphQL type representing a team.

Expand Down Expand Up @@ -201,11 +232,45 @@ value as specified by
"""
scalar DateTime

"""
The `Boolean` scalar type represents `true` or `false`.
"""
scalar Boolean

"""
A Cornell team identified by its gender and sport.
"""
type FavoriteTeamType {
gender: String!

sport: String!
}

"""
Public application-user fields returned after authentication.
"""
type UserType {
id: ID!

email: String

name: String

favoriteTeams: [FavoriteTeamType]!

bookmarkedHighlightIds: [String]!
}

"""
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
"""
scalar ID

type Mutation {
"""
Creates a new game.
"""
createGame(boxScore: String, city: String!, date: String!, gender: String!, location: String, opponentId: String!, result: String, scoreBreakdown: String, sport: String!, state: String!, ticketLink: String, time: String!, utcDate: String): CreateGame
createGame(boxScore: String, city: String!, date: String!, gender: String!, location: String, opponentId: String!, recapArticleImage: String, recapArticleTitle: String, recapLink: String, recapPublishedAt: String, result: String, scoreBreakdown: String, sport: String!, state: String!, ticketLink: String, time: String, utcDate: String): CreateGame

"""
Creates a new team.
Expand All @@ -223,14 +288,14 @@ type Mutation {
createArticle(image: String, publishedAt: String!, slug: String!, sportsType: String!, title: String!, url: String!): CreateArticle

"""
Login with Firebase ID token; returns access_token and refresh_token.
Login with a Google Firebase ID token; returns access_token and refresh_token.
"""
loginUser("Firebase ID token from the client." idToken: String!): LoginUser
loginUser("Google Firebase ID token from the client." idToken: String!): LoginUser

"""
Create a new user with Firebase ID token; returns access_token and refresh_token.
Create a new user with a Google Firebase ID token; returns access_token and refresh_token.
"""
signupUser("Firebase ID token from the client." idToken: String!): SignupUser
signupUser("Google Firebase ID token from the client." idToken: String!): SignupUser

"""
Exchange a valid refresh token (in Authorization header) for a new access_token.
Expand All @@ -243,14 +308,29 @@ type Mutation {
logoutUser: LogoutUser

"""
Add a game to the current user's favorites (requires auth).
Permanently delete the current user's application and Firebase accounts (requires auth).
"""
deleteUser: DeleteUser

"""
Add a team, identified by gender and sport, to the current user's favorites (requires auth).
"""
addFavoriteTeam("Gender of the team, such as Mens or Womens." gender: String!, "Sport of the team" sport: String!): AddFavoriteTeam

"""
Remove a team, identified by gender and sport, from the current user's favorites (requires auth).
"""
removeFavoriteTeam("Gender of the team, such as Mens or Womens." gender: String!, "Sport of the team" sport: String!): RemoveFavoriteTeam

"""
Bookmark a highlight for the current user (requires auth).
"""
addFavoriteGame("ID of the game to add to favorites." gameId: String!): AddFavoriteGame
addBookmarkedHighlight("ID of the highlight to bookmark." highlightId: String!): AddBookmarkedHighlight

"""
Remove a game from the current user's favorites (requires auth).
Remove a highlight bookmark for the current user (requires auth).
"""
removeFavoriteGame("ID of the game to remove from favorites." gameId: String!): RemoveFavoriteGame
removeBookmarkedHighlight("ID of the highlight to remove from bookmarks." highlightId: String!): RemoveBookmarkedHighlight
}

type CreateGame {
Expand All @@ -273,12 +353,16 @@ type LoginUser {
accessToken: String

refreshToken: String

user: UserType!
}

type SignupUser {
accessToken: String

refreshToken: String

user: UserType!
}

type RefreshAccessToken {
Expand All @@ -289,11 +373,26 @@ type LogoutUser {
success: Boolean
}

type AddFavoriteGame {
"""
Permanently delete the authenticated user's application and Firebase accounts.
"""
type DeleteUser {
success: Boolean!
}

type AddFavoriteTeam {
success: Boolean
}

type RemoveFavoriteTeam {
success: Boolean
}

type AddBookmarkedHighlight {
success: Boolean
}

type RemoveFavoriteGame {
type RemoveBookmarkedHighlight {
success: Boolean
}

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/cornellappdev/score/ScoreApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ fun ScoreApp(
)
}
onboardingComplete || skippedWelcome ->
RootNavigation(welcomeName = signedInState?.user?.name)
key(signedInState?.user?.id) {
RootNavigation(
preferences = onboardingPreferences,
onSignIn = onSignIn,
welcomeName = signedInState?.user?.name,
)
}
else ->
OnboardingScreen(
onSignUp = onSignIn,
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/cornellappdev/score/auth/AuthApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.api.ApolloResponse
import com.apollographql.apollo.api.http.HttpHeader
import com.apollographql.apollo.exception.ApolloHttpException
import com.example.score.DeleteUserMutation
import com.example.score.LoginUserMutation
import com.example.score.LogoutUserMutation
import com.example.score.RefreshAccessTokenMutation
Expand All @@ -19,6 +20,8 @@ interface AuthApi {
suspend fun refresh(refreshToken: String): String

suspend fun revoke(token: String)

suspend fun deleteAccount(token: String)
}

class UserNotFoundException : Exception()
Expand Down Expand Up @@ -64,6 +67,14 @@ class ApolloAuthApi @Inject constructor(@Named("auth") private val client: Apoll
.checkErrors()
}

override suspend fun deleteAccount(token: String) {
val response = client.mutation(DeleteUserMutation())
.httpHeaders(listOf(HttpHeader("Authorization", "Bearer $token")))
.execute()
response.checkErrors()
check(response.data?.deleteUser?.success == true) { "Account deletion failed" }
}

private fun tokens(access: String?, refresh: String?): AuthTokens {
require(!access.isNullOrBlank() && !refresh.isNullOrBlank()) { "Missing session tokens" }
return AuthTokens(access, refresh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ constructor(private val api: AuthApi, private val storage: SessionStorage) {
saveSession(current.copy(onboardingStage = nextStage))
}

suspend fun deleteAccount() {
val token = checkNotNull(accessToken()) { "Sign in to delete your account" }
mutex.withLock {
check(session?.accessToken == token) { "Session changed" }
api.deleteAccount(token)
clearSession()
}
}

suspend fun signOut() {
val previous =
mutex.withLock {
Expand Down
Loading
Loading