1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

storage: wrap the postgres repository in a struct

This commit is contained in:
Quentin Gliech
2023-01-13 18:03:37 +01:00
parent 488a666a8d
commit 195203823a
44 changed files with 505 additions and 548 deletions

View File

@@ -16,7 +16,8 @@ use anyhow::Context as _;
use async_graphql::{Context, Object, ID};
use chrono::{DateTime, Utc};
use mas_storage::{
upstream_oauth2::UpstreamOAuthProviderRepository, user::UserRepository, Repository,
upstream_oauth2::UpstreamOAuthProviderRepository, user::UserRepository, PgRepository,
Repository,
};
use sqlx::PgPool;
@@ -102,9 +103,8 @@ impl UpstreamOAuth2Link {
provider.clone()
} else {
// Fetch on-the-fly
let database = ctx.data::<PgPool>()?;
let mut conn = database.acquire().await?;
conn.upstream_oauth_provider()
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
repo.upstream_oauth_provider()
.lookup(self.link.provider_id)
.await?
.context("Upstream OAuth 2.0 provider not found")?
@@ -120,9 +120,8 @@ impl UpstreamOAuth2Link {
user.clone()
} else if let Some(user_id) = &self.link.user_id {
// Fetch on-the-fly
let database = ctx.data::<PgPool>()?;
let mut conn = database.acquire().await?;
conn.user()
let mut repo = PgRepository::from_pool(ctx.data::<PgPool>()?).await?;
repo.user()
.lookup(*user_id)
.await?
.context("User not found")?