summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/auth-service/Cargo.toml2
-rw-r--r--crates/auth-service/src/server/routes/authorised.rs4
-rw-r--r--crates/auth-service/src/state.rs8
-rw-r--r--crates/profile-service/src/server/manager.rs45
-rw-r--r--crates/users-service/Cargo.toml (renamed from crates/profile-service/Cargo.toml)4
-rw-r--r--crates/users-service/migrations/20250726161947_profile.sql (renamed from crates/profile-service/migrations/20250726161947_profile.sql)0
-rw-r--r--crates/users-service/src/cnfg.rs (renamed from crates/profile-service/src/cnfg.rs)0
-rw-r--r--crates/users-service/src/main.rs (renamed from crates/profile-service/src/main.rs)9
-rw-r--r--crates/users-service/src/server.rs (renamed from crates/profile-service/src/server.rs)0
-rw-r--r--crates/users-service/src/server/interceptor.rs (renamed from crates/profile-service/src/server/interceptor.rs)0
-rw-r--r--crates/users-service/src/server/manager.rs85
-rw-r--r--crates/users-service/src/state.rs (renamed from crates/profile-service/src/state.rs)25
-rw-r--r--crates/users-service/users.toml (renamed from crates/profile-service/profile.toml)2
13 files changed, 123 insertions, 61 deletions
diff --git a/crates/auth-service/Cargo.toml b/crates/auth-service/Cargo.toml
index bbbb10d..837fc8b 100644
--- a/crates/auth-service/Cargo.toml
+++ b/crates/auth-service/Cargo.toml
@@ -19,7 +19,7 @@ jsonwebtoken = "9.3.1"
nanoid.workspace = true
oauth2 = "5.0.0"
reqwest = { workspace = true, features = ["json", "rustls-tls"] }
-sellershut-core = { workspace = true, features = ["auth", "serde"] }
+sellershut-core = { workspace = true, features = ["auth", "serde", "users"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
sqlx = { workspace = true, features = ["macros", "migrate", "runtime-tokio", "time", "tls-rustls", "uuid"] }
diff --git a/crates/auth-service/src/server/routes/authorised.rs b/crates/auth-service/src/server/routes/authorised.rs
index 4d48299..2538cdc 100644
--- a/crates/auth-service/src/server/routes/authorised.rs
+++ b/crates/auth-service/src/server/routes/authorised.rs
@@ -9,7 +9,7 @@ use axum::{
use axum_extra::{TypedHeader, headers};
use oauth2::{AuthorizationCode, TokenResponse};
use reqwest::{StatusCode, header::SET_COOKIE};
-use sellershut_core::profile::CreateUserRequest;
+use sellershut_core::users::CreateUserRequest;
use serde::{Deserialize, Serialize};
use sqlx::types::uuid;
use time::OffsetDateTime;
@@ -215,7 +215,7 @@ pub async fn login_authorised(
let cookie = format!("{SESSION_COOKIE}={session_id}; SameSite=Lax; HttpOnly; Secure; Path=/");
- let mut profile_client = state.profile_client.clone();
+ let mut profile_client = state.users_client.clone();
let resp = profile_client.create_user(user_request).await?.into_inner();
let user_id = resp.temp_id;
diff --git a/crates/auth-service/src/state.rs b/crates/auth-service/src/state.rs
index 5905948..07bfda9 100644
--- a/crates/auth-service/src/state.rs
+++ b/crates/auth-service/src/state.rs
@@ -1,6 +1,6 @@
use std::{ops::Deref, sync::Arc};
-use sellershut_core::profile::profile_client::ProfileClient;
+use sellershut_core::users::users_service_client::UsersServiceClient;
use sqlx::PgPool;
use stack_up::Configuration;
use tokio::task::JoinHandle;
@@ -39,7 +39,7 @@ pub struct AppState {
pub discord_client: OauthClient,
pub http_client: reqwest::Client,
pub session_store: CachingSessionStore<MokaStore, PostgresStore>,
- pub profile_client: ProfileClient<Intercepted>,
+ pub users_client: UsersServiceClient<Intercepted>,
}
impl AppState {
@@ -68,7 +68,7 @@ impl AppState {
.await
.inspect_err(|e| error!("could not connect to profile service: {e}"))?;
- let profile_client = ProfileClient::with_interceptor(channel, MyInterceptor);
+ let users_client = UsersServiceClient::with_interceptor(channel, MyInterceptor);
Ok((
AppHandle(Arc::new(Self {
@@ -77,7 +77,7 @@ impl AppState {
discord_client,
http_client: reqwest::Client::new(),
session_store: store,
- profile_client,
+ users_client,
})),
deletion_task,
))
diff --git a/crates/profile-service/src/server/manager.rs b/crates/profile-service/src/server/manager.rs
deleted file mode 100644
index bd7e149..0000000
--- a/crates/profile-service/src/server/manager.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-use prost::Message;
-use sellershut_core::profile::{
- CompleteUserRequest, CreateUserRequest, CreateUserResponse, User, profile_server::Profile,
-};
-use stack_up::redis::AsyncCommands;
-use tonic::{Request, Response, Status, async_trait};
-use tracing::trace;
-use uuid::Uuid;
-
-use crate::state::AppHandle;
-
-#[async_trait]
-impl Profile for AppHandle {
- #[doc = " Create a new user profile"]
- async fn create_user(
- &self,
- request: Request<CreateUserRequest>,
- ) -> Result<Response<CreateUserResponse>, Status> {
- trace!("creating user");
- let data = request.into_inner();
- let id = Uuid::now_v7().to_string();
-
- let bytes = data.encode_to_vec();
- let mut cache = self
- .services
- .cache
- .get()
- .await
- .map_err(|e| Status::internal("storage not ready"))?;
- cache
- .set_ex::<_, _, ()>(&id, &bytes, self.local_config.temp_ttl)
- .await
- .map_err(|e| Status::internal("storage not ready"))?;
-
- Ok(Response::new(CreateUserResponse { temp_id: id }))
- }
-
- #[doc = " Complete Profile"]
- async fn complete_profile(
- &self,
- request: Request<CompleteUserRequest>,
- ) -> Result<Response<User>, Status> {
- todo!()
- }
-}
diff --git a/crates/profile-service/Cargo.toml b/crates/users-service/Cargo.toml
index e56db3a..2bbfe28 100644
--- a/crates/profile-service/Cargo.toml
+++ b/crates/users-service/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "sellershut-profiles"
+name = "sellershut-users"
version = "0.1.0"
edition = "2024"
license.workspace = true
@@ -15,7 +15,7 @@ config = { workspace = true, features = ["convert-case", "toml"] }
futures-util.workspace = true
nanoid.workspace = true
prost.workspace = true
-sellershut-core = { workspace = true, features = ["profile", "serde"] }
+sellershut-core = { workspace = true, features = ["users", "serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
sqlx = { workspace = true, features = ["macros", "migrate", "runtime-tokio", "time", "tls-rustls", "uuid"] }
diff --git a/crates/profile-service/migrations/20250726161947_profile.sql b/crates/users-service/migrations/20250726161947_profile.sql
index 15822c8..15822c8 100644
--- a/crates/profile-service/migrations/20250726161947_profile.sql
+++ b/crates/users-service/migrations/20250726161947_profile.sql
diff --git a/crates/profile-service/src/cnfg.rs b/crates/users-service/src/cnfg.rs
index fec4cf7..fec4cf7 100644
--- a/crates/profile-service/src/cnfg.rs
+++ b/crates/users-service/src/cnfg.rs
diff --git a/crates/profile-service/src/main.rs b/crates/users-service/src/main.rs
index 5fe1331..218c74a 100644
--- a/crates/profile-service/src/main.rs
+++ b/crates/users-service/src/main.rs
@@ -4,7 +4,7 @@ mod state;
use std::net::{Ipv6Addr, SocketAddr};
use clap::Parser;
-use sellershut_core::profile::profile_server::ProfileServer;
+use sellershut_core::users::users_service_server::UsersServiceServer;
use stack_up::{Configuration, Services, tracing::Tracing};
use tokio::signal;
use tonic::transport::{Server, server::TcpIncoming};
@@ -27,7 +27,7 @@ struct Args {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = Args::parse();
- let config = include_str!("../profile.toml");
+ let config = include_str!("../users.toml");
let mut config = config::Config::builder()
.add_source(config::File::from_str(config, config::FileFormat::Toml));
@@ -61,7 +61,7 @@ async fn main() -> anyhow::Result<()> {
.take()
.ok_or_else(|| anyhow::anyhow!("cache is not ready"))?;
- let services = crate::state::Services { postgres, cache };
+ let services = crate::state::Services::new(postgres, cache);
let state = AppState::create(services, &config).await?;
@@ -73,8 +73,7 @@ async fn main() -> anyhow::Result<()> {
Server::builder()
.trace_fn(|_| tracing::info_span!(env!("CARGO_PKG_NAME")))
- // .add_service(QueryUsersServer::new(state.clone()))
- .add_service(ProfileServer::with_interceptor(
+ .add_service(UsersServiceServer::with_interceptor(
state.clone(),
MyInterceptor,
))
diff --git a/crates/profile-service/src/server.rs b/crates/users-service/src/server.rs
index b2e04f9..b2e04f9 100644
--- a/crates/profile-service/src/server.rs
+++ b/crates/users-service/src/server.rs
diff --git a/crates/profile-service/src/server/interceptor.rs b/crates/users-service/src/server/interceptor.rs
index 6fbe7fa..6fbe7fa 100644
--- a/crates/profile-service/src/server/interceptor.rs
+++ b/crates/users-service/src/server/interceptor.rs
diff --git a/crates/users-service/src/server/manager.rs b/crates/users-service/src/server/manager.rs
new file mode 100644
index 0000000..6affb4a
--- /dev/null
+++ b/crates/users-service/src/server/manager.rs
@@ -0,0 +1,85 @@
+use prost::Message;
+use sellershut_core::users::{
+ CompleteUserRequest, CreateUserRequest, CreateUserResponse, User,
+ users_service_server::UsersService,
+};
+use stack_up::redis::AsyncCommands;
+use tonic::{Request, Response, Status, async_trait};
+use tracing::{error, trace};
+use uuid::Uuid;
+
+use crate::state::AppHandle;
+
+#[async_trait]
+impl UsersService for AppHandle {
+ #[doc = " Create a new user profile"]
+ async fn create_user(
+ &self,
+ request: Request<CreateUserRequest>,
+ ) -> Result<Response<CreateUserResponse>, Status> {
+ trace!("creating user");
+ let data = request.into_inner();
+ let id = Uuid::now_v7().to_string();
+
+ let bytes = data.encode_to_vec();
+ let mut cache = self.cache().await?;
+ cache
+ .set_ex::<_, _, ()>(&id, &bytes, self.local_config.temp_ttl)
+ .await
+ .inspect_err(|e| error!("{e}"))
+ .map_err(|_e| Status::internal("storage not ready"))?;
+
+ Ok(Response::new(CreateUserResponse { temp_id: id }))
+ }
+
+ #[doc = " Complete Profile"]
+ async fn complete_user(
+ &self,
+ request: Request<CompleteUserRequest>,
+ ) -> Result<Response<User>, Status> {
+ let request = request.into_inner();
+
+ let mut cache = self.cache().await?;
+
+ let resp = cache
+ .get_del::<_, Vec<u8>>(&request.id)
+ .await
+ .inspect_err(|e| error!("{e}"))
+ .map_err(|_e| Status::internal("storage not ready"))?;
+
+ if resp.is_empty() {
+ return Err(Status::data_loss("user unavailable"));
+ }
+
+ let create_user = CreateUserRequest::decode(resp.as_ref())
+ .map_err(|_e| Status::data_loss("internal data corrupted"))?;
+
+ let user = sqlx::query!(
+ "insert
+ into
+ profile (
+ id,
+ username,
+ inbox,
+ outbox,
+ local,
+ avatar_url,
+ description,
+ user_type,
+ public_key
+ )
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9)
+ ",
+ request.id,
+ request.username,
+ request.inbox,
+ request.outbox,
+ request.local,
+ request.avatar.or(create_user.avatar),
+ request.description,
+ request.user_type.to_string(),
+ request.public_key,
+ );
+ todo!()
+ }
+}
diff --git a/crates/profile-service/src/state.rs b/crates/users-service/src/state.rs
index 1ccfbfd..3f5ac7b 100644
--- a/crates/profile-service/src/state.rs
+++ b/crates/users-service/src/state.rs
@@ -1,7 +1,12 @@
use std::sync::Arc;
use sqlx::PgPool;
-use stack_up::{Configuration, cache::RedisManager};
+use stack_up::{
+ Configuration,
+ cache::{RedisConnection, RedisManager},
+};
+use tonic::Status;
+use tracing::error;
use crate::cnfg::LocalConfig;
@@ -22,6 +27,12 @@ pub struct Services {
pub cache: RedisManager,
}
+impl Services {
+ pub fn new(postgres: PgPool, cache: RedisManager) -> Self {
+ Self { postgres, cache }
+ }
+}
+
pub struct AppState {
pub services: Services,
pub local_config: LocalConfig,
@@ -39,4 +50,16 @@ impl AppState {
local_config,
})))
}
+
+ pub async fn cache(&self) -> Result<RedisConnection, tonic::Status> {
+ let cache = self
+ .services
+ .cache
+ .get()
+ .await
+ .inspect_err(|e| error!("{e}"))
+ .map_err(|_e| Status::internal("storage not ready"))?;
+
+ Ok(cache)
+ }
}
diff --git a/crates/profile-service/profile.toml b/crates/users-service/users.toml
index 13a5f0a..9706fcf 100644
--- a/crates/profile-service/profile.toml
+++ b/crates/users-service/users.toml
@@ -3,7 +3,7 @@ env = "development"
port = 1610
[monitoring]
-log-level = "sellershut_profiles=trace,info"
+log-level = "sellershut_users=trace,info"
[misc]
temp-ttl = 1000