diff options
| author | rtkay123 <dev@kanjala.com> | 2026-02-11 00:19:20 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2026-02-11 00:19:20 +0200 |
| commit | 9fd685039613d0e9aa71eabe51d3a6272a3ace21 (patch) | |
| tree | 0ea22dd7cfc160b91dd4294c4806bd02c4a4647f /lib | |
| parent | 4f30128feb0715f05c103fec20aa6cba61e60984 (diff) | |
| download | sellershut-9fd685039613d0e9aa71eabe51d3a6272a3ace21.tar.bz2 sellershut-9fd685039613d0e9aa71eabe51d3a6272a3ace21.zip | |
fix: merge create account
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/auth-service/src/lib.rs | 12 | ||||
| -rw-r--r-- | lib/auth-service/src/service/mod.rs | 66 |
2 files changed, 60 insertions, 18 deletions
diff --git a/lib/auth-service/src/lib.rs b/lib/auth-service/src/lib.rs index 61ff230..abccd65 100644 --- a/lib/auth-service/src/lib.rs +++ b/lib/auth-service/src/lib.rs @@ -11,6 +11,18 @@ pub enum Provider { Discord, } +impl std::fmt::Display for Provider { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + Provider::Discord => "discord", + } + ) + } +} + #[derive(Error, Debug)] pub enum AuthServiceError { #[error("invalid url provided")] diff --git a/lib/auth-service/src/service/mod.rs b/lib/auth-service/src/service/mod.rs index 80b29de..6d04b67 100644 --- a/lib/auth-service/src/service/mod.rs +++ b/lib/auth-service/src/service/mod.rs @@ -1,7 +1,7 @@ use async_session::{Result, Session, SessionStore}; use async_trait::async_trait; use shared_svc::cache::{CacheKey, RedisManager, redis::AsyncCommands}; -use sqlx::{PgPool, Postgres, Transaction}; +use sqlx::{Executor, PgPool, Postgres}; use tracing::{debug, instrument}; use crate::Provider; @@ -9,14 +9,13 @@ use crate::Provider; #[async_trait] pub trait AccountMgr { async fn get_apid_by_email(&self, email: &str) -> Result<Option<String>>; - async fn create_account(&self, provider: Provider, provider_user_id: &str, ap_id: &str); - async fn create_account_step( + async fn create_account<'c>( &self, provider: Provider, provider_user_id: &str, ap_id: &str, email: &str, - transaction: &mut Transaction<'_, Postgres>, + transaction: Option<impl Executor<'c, Database = Postgres>>, ) -> Result; async fn persist_session(&self); } @@ -34,31 +33,34 @@ impl AccountMgr for AuthService { todo!() } - #[instrument(skip(self))] - async fn create_account(&self, provider: Provider, provider_user_id: &str, ap_id: &str) { - todo!() - } - #[instrument(skip(self, transaction))] - async fn create_account_step( + #[instrument(skip(transaction))] + async fn create_account<'c>( &self, provider: Provider, provider_user_id: &str, ap_id: &str, email: &str, - transaction: &mut Transaction<'_, Postgres>, + transaction: Option<impl Executor<'c, Database = Postgres>>, ) -> Result { - sqlx::query!( + let query = sqlx::query!( "insert into account (provider_id, provider_user_id, email, ap_id) - values ($1, $2, $3, $4) + values + ($1, $2, $3, $4) + on conflict (provider_id, provider_user_id) + do nothing ", - "", + provider.to_string(), provider_user_id, - "", + email, ap_id - ) - .execute(&mut **transaction) - .await?; + ); + + if let Some(con) = transaction { + query.execute(con).await?; + } else { + query.execute(&self.database).await?; + }; todo!() } @@ -129,3 +131,31 @@ impl SessionStore for AuthService { Ok(()) } } + +async fn create_account_step<'c, E>( + provider: Provider, + provider_user_id: &str, + ap_id: &str, + email: &str, + transaction: E, +) -> Result +where + E: Executor<'c, Database = Postgres>, +{ + sqlx::query!( + "insert into account + (provider_id, provider_user_id, email, ap_id) + values + ($1, $2, $3, $4) + on conflict (provider_id, provider_user_id) + do nothing + ", + provider.to_string(), + provider_user_id, + email, + ap_id + ) + .execute(transaction) + .await?; + todo!() +} |
