Skip to content

Commit

Permalink
refactor(backend): return all integrations from one resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Jul 17, 2023
1 parent 8414fec commit b87d899
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 47 deletions.
64 changes: 39 additions & 25 deletions apps/backend/src/miscellaneous/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ enum UserSinkIntegrationLot {
}

#[derive(Debug, Serialize, Deserialize, SimpleObject, Clone)]
struct GraphqlUserYankIntegration {
struct GraphqlUserIntegration {
id: usize,
lot: UserYankIntegrationLot,
description: String,
timestamp: DateTimeUtc,
lot: UserIntegrationLot,
}

#[derive(Debug, Serialize, Deserialize, InputObject, Clone)]
Expand Down Expand Up @@ -664,15 +664,15 @@ impl MiscellaneousQuery {
.await
}

/// Get all the yank based integrations for the currently logged in user.
async fn user_yank_integrations(
/// Get all the integrations for the currently logged in user.
async fn user_integrations(
&self,
gql_ctx: &Context<'_>,
) -> Result<Vec<GraphqlUserYankIntegration>> {
) -> Result<Vec<GraphqlUserIntegration>> {
let user_id = user_id_from_ctx(gql_ctx).await?;
gql_ctx
.data_unchecked::<Arc<MiscellaneousService>>()
.user_yank_integrations(user_id)
.user_integrations(user_id)
.await
}

Expand Down Expand Up @@ -3134,32 +3134,46 @@ impl MiscellaneousService {
Ok(api_token)
}

async fn user_yank_integrations(
&self,
user_id: i32,
) -> Result<Vec<GraphqlUserYankIntegration>> {
async fn user_integrations(&self, user_id: i32) -> Result<Vec<GraphqlUserIntegration>> {
let user = self.user_by_id(user_id).await?;
let integrations = if let Some(i) = user.yank_integrations {
let mut all_integrations = vec![];
let yank_integrations = if let Some(i) = user.yank_integrations {
i.0
} else {
vec![]
};
Ok(integrations
.into_iter()
.map(|i| {
let (lot, description) = match i.settings {
UserYankIntegrationSetting::Audiobookshelf { base_url, .. } => {
(UserYankIntegrationLot::Audiobookshelf, base_url)
}
};
GraphqlUserYankIntegration {
id: i.id,
lot,
description,
timestamp: i.timestamp,
yank_integrations.into_iter().for_each(|i| {
let description = match i.settings {
UserYankIntegrationSetting::Audiobookshelf { base_url, .. } => {
format!("Connected to {}", base_url)
}
};
all_integrations.push(GraphqlUserIntegration {
id: i.id,
lot: UserIntegrationLot::Yank,
description,
timestamp: i.timestamp,
})
});
let sink_integrations = if let Some(i) = user.sink_integrations {
i.0
} else {
vec![]
};
sink_integrations.into_iter().for_each(|i| {
let description = match i.settings {
UserSinkIntegrationSetting::Jellyfin { slug } => {
format!("Connected to {}", slug)
}
};
all_integrations.push(GraphqlUserIntegration {
id: i.id,
lot: UserIntegrationLot::Sink,
description,
timestamp: i.timestamp,
})
.collect())
});
Ok(all_integrations)
}

async fn create_user_sink_integration(
Expand Down
8 changes: 4 additions & 4 deletions libs/generated/src/graphql/backend/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ const documents = {
"query SeenHistory($metadataId: Int!) {\n seenHistory(metadataId: $metadataId) {\n id\n progress\n dropped\n startedOn\n finishedOn\n lastUpdatedOn\n showInformation {\n episode\n season\n }\n podcastInformation {\n episode\n }\n }\n}": types.SeenHistoryDocument,
"query UserAuthTokens {\n userAuthTokens {\n lastUsedOn\n token\n }\n}": types.UserAuthTokensDocument,
"query UserDetails {\n userDetails {\n __typename\n ... on User {\n id\n email\n name\n lot\n }\n }\n}": types.UserDetailsDocument,
"query UserIntegrations {\n userIntegrations {\n id\n lot\n description\n timestamp\n }\n}": types.UserIntegrationsDocument,
"query UserPreferences {\n userPreferences {\n featuresEnabled {\n anime\n audioBooks\n books\n manga\n movies\n podcasts\n shows\n videoGames\n }\n }\n}": types.UserPreferencesDocument,
"query UserSummary {\n userSummary {\n calculatedOn\n media {\n manga {\n chapters\n read\n }\n books {\n pages\n read\n }\n movies {\n runtime\n watched\n }\n anime {\n episodes\n watched\n }\n podcasts {\n runtime\n played\n playedEpisodes\n }\n videoGames {\n played\n }\n shows {\n runtime\n watchedEpisodes\n watchedSeasons\n watched\n }\n audioBooks {\n runtime\n played\n }\n }\n }\n}": types.UserSummaryDocument,
"query UserYankIntegrations {\n userYankIntegrations {\n id\n lot\n description\n timestamp\n }\n}": types.UserYankIntegrationsDocument,
"query Users {\n users {\n id\n name\n lot\n }\n}": types.UsersDocument,
};

Expand Down Expand Up @@ -261,15 +261,15 @@ export function graphql(source: "query UserDetails {\n userDetails {\n __typ
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "query UserPreferences {\n userPreferences {\n featuresEnabled {\n anime\n audioBooks\n books\n manga\n movies\n podcasts\n shows\n videoGames\n }\n }\n}"): (typeof documents)["query UserPreferences {\n userPreferences {\n featuresEnabled {\n anime\n audioBooks\n books\n manga\n movies\n podcasts\n shows\n videoGames\n }\n }\n}"];
export function graphql(source: "query UserIntegrations {\n userIntegrations {\n id\n lot\n description\n timestamp\n }\n}"): (typeof documents)["query UserIntegrations {\n userIntegrations {\n id\n lot\n description\n timestamp\n }\n}"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "query UserSummary {\n userSummary {\n calculatedOn\n media {\n manga {\n chapters\n read\n }\n books {\n pages\n read\n }\n movies {\n runtime\n watched\n }\n anime {\n episodes\n watched\n }\n podcasts {\n runtime\n played\n playedEpisodes\n }\n videoGames {\n played\n }\n shows {\n runtime\n watchedEpisodes\n watchedSeasons\n watched\n }\n audioBooks {\n runtime\n played\n }\n }\n }\n}"): (typeof documents)["query UserSummary {\n userSummary {\n calculatedOn\n media {\n manga {\n chapters\n read\n }\n books {\n pages\n read\n }\n movies {\n runtime\n watched\n }\n anime {\n episodes\n watched\n }\n podcasts {\n runtime\n played\n playedEpisodes\n }\n videoGames {\n played\n }\n shows {\n runtime\n watchedEpisodes\n watchedSeasons\n watched\n }\n audioBooks {\n runtime\n played\n }\n }\n }\n}"];
export function graphql(source: "query UserPreferences {\n userPreferences {\n featuresEnabled {\n anime\n audioBooks\n books\n manga\n movies\n podcasts\n shows\n videoGames\n }\n }\n}"): (typeof documents)["query UserPreferences {\n userPreferences {\n featuresEnabled {\n anime\n audioBooks\n books\n manga\n movies\n podcasts\n shows\n videoGames\n }\n }\n}"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "query UserYankIntegrations {\n userYankIntegrations {\n id\n lot\n description\n timestamp\n }\n}"): (typeof documents)["query UserYankIntegrations {\n userYankIntegrations {\n id\n lot\n description\n timestamp\n }\n}"];
export function graphql(source: "query UserSummary {\n userSummary {\n calculatedOn\n media {\n manga {\n chapters\n read\n }\n books {\n pages\n read\n }\n movies {\n runtime\n watched\n }\n anime {\n episodes\n watched\n }\n podcasts {\n runtime\n played\n playedEpisodes\n }\n videoGames {\n played\n }\n shows {\n runtime\n watchedEpisodes\n watchedSeasons\n watched\n }\n audioBooks {\n runtime\n played\n }\n }\n }\n}"): (typeof documents)["query UserSummary {\n userSummary {\n calculatedOn\n media {\n manga {\n chapters\n read\n }\n books {\n pages\n read\n }\n movies {\n runtime\n watched\n }\n anime {\n episodes\n watched\n }\n podcasts {\n runtime\n played\n playedEpisodes\n }\n videoGames {\n played\n }\n shows {\n runtime\n watchedEpisodes\n watchedSeasons\n watched\n }\n audioBooks {\n runtime\n played\n }\n }\n }\n}"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading

0 comments on commit b87d899

Please sign in to comment.