diff options
| -rw-r--r-- | .sqlx/query-1c55bb1b9831f41a4dab754239ab6a30b7e42235be7e3f45ba23ac6f60bb3cae.json | 22 | ||||
| -rw-r--r-- | Cargo.lock | 16 | ||||
| -rw-r--r-- | lib/auth-service/src/service/mod.rs | 30 | ||||
| -rw-r--r-- | lib/users-service/Cargo.toml | 18 | ||||
| -rw-r--r-- | lib/users-service/src/lib.rs | 14 | ||||
| -rw-r--r-- | migrations/20260210193544_profile.sql | 30 | ||||
| -rw-r--r-- | migrations/20260210194218_oauth_account.sql | 2 | ||||
| -rw-r--r-- | sellershut/Cargo.toml | 1 |
8 files changed, 80 insertions, 53 deletions
diff --git a/.sqlx/query-1c55bb1b9831f41a4dab754239ab6a30b7e42235be7e3f45ba23ac6f60bb3cae.json b/.sqlx/query-1c55bb1b9831f41a4dab754239ab6a30b7e42235be7e3f45ba23ac6f60bb3cae.json new file mode 100644 index 0000000..88528db --- /dev/null +++ b/.sqlx/query-1c55bb1b9831f41a4dab754239ab6a30b7e42235be7e3f45ba23ac6f60bb3cae.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "insert into account\n (provider_id, provider_user_id, email, user_id)\n values\n ($1, $2, $3, $4)\n on conflict (provider_id, provider_user_id)\n do nothing\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + { + "Custom": { + "name": "citext", + "kind": "Simple" + } + }, + "Text" + ] + }, + "nullable": [] + }, + "hash": "1c55bb1b9831f41a4dab754239ab6a30b7e42235be7e3f45ba23ac6f60bb3cae" +} @@ -2279,6 +2279,7 @@ dependencies = [ "tracing-appender", "tracing-subscriber", "url", + "users-service", "utoipa", "utoipa-axum", "utoipa-rapidoc", @@ -3144,6 +3145,21 @@ dependencies = [ ] [[package]] +name = "users-service" +version = "0.1.0" +dependencies = [ + "async-trait", + "secrecy", + "serde_json", + "shared-svc", + "sqlx", + "thiserror 2.0.18", + "time", + "tracing", + "url", +] + +[[package]] name = "utf8_iter" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/lib/auth-service/src/service/mod.rs b/lib/auth-service/src/service/mod.rs index 6d04b67..31c9019 100644 --- a/lib/auth-service/src/service/mod.rs +++ b/lib/auth-service/src/service/mod.rs @@ -44,7 +44,7 @@ impl AccountMgr for AuthService { ) -> Result { let query = sqlx::query!( "insert into account - (provider_id, provider_user_id, email, ap_id) + (provider_id, provider_user_id, email, user_id) values ($1, $2, $3, $4) on conflict (provider_id, provider_user_id) @@ -131,31 +131,3 @@ 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!() -} diff --git a/lib/users-service/Cargo.toml b/lib/users-service/Cargo.toml new file mode 100644 index 0000000..639f4ff --- /dev/null +++ b/lib/users-service/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "users-service" +version = "0.1.0" +edition = "2024" +license.workspace = true +readme.workspace = true +documentation.workspace = true + +[dependencies] +async-trait.workspace = true +secrecy = "0.10.3" +serde_json = "1.0.149" +shared-svc = { workspace = true, features = ["cache"] } +sqlx.workspace = true +thiserror.workspace = true +time.workspace = true +tracing.workspace = true +url = { workspace = true, features = ["serde"] } diff --git a/lib/users-service/src/lib.rs b/lib/users-service/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/lib/users-service/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/migrations/20260210193544_profile.sql b/migrations/20260210193544_profile.sql index f47d034..930e657 100644 --- a/migrations/20260210193544_profile.sql +++ b/migrations/20260210193544_profile.sql @@ -1,26 +1,10 @@ -create type actor_kind as enum ( - 'application', - 'group', - 'organization', - 'person', - 'service' -); - create table profile ( - ap_id text primary key, - username varchar(15), - description varchar(255), - inbox text not null, - role actor_kind not null default 'person', - outbox text, - picture text, - public_key text not null, - private_key text, - created_at timestamptz not null default now(), - last_refreshed_at timestamptz not null default now() + data jsonb not null, + id text generated always as (data->>'id') stored, + primary key (id) ); -create index user_inbox_idx on profile (inbox); -create index user_outbox_idx on profile (outbox); -create index user_role_idx on profile (role); -create index user_username_idx on profile (username); +create index idx_profile_inbox on profile using gin ((data->'inbox')); +create index idx_profile_private_key_null + on profile ((data->>'private_key')) + where data->>'private_key' is null; diff --git a/migrations/20260210194218_oauth_account.sql b/migrations/20260210194218_oauth_account.sql index ce660fe..3431f85 100644 --- a/migrations/20260210194218_oauth_account.sql +++ b/migrations/20260210194218_oauth_account.sql @@ -4,7 +4,7 @@ create table account ( provider_id text not null, provider_user_id text not null, email citext not null, - ap_id text not null references profile(ap_id) on delete cascade, + user_id text not null references profile(id) on delete cascade, primary key (provider_id, provider_user_id) ); diff --git a/sellershut/Cargo.toml b/sellershut/Cargo.toml index 2a4de31..591d9f2 100644 --- a/sellershut/Cargo.toml +++ b/sellershut/Cargo.toml @@ -26,6 +26,7 @@ tracing.workspace = true tracing-appender = "0.2.4" tracing-subscriber = { version = "0.3.22", features = ["env-filter"] } url = { workspace = true, features = ["serde"] } +users-service = { path = "../lib/users-service" } utoipa = "5.4.0" utoipa-axum = "0.2.0" utoipa-rapidoc = { version = "6.0.0", optional = true } |
