summaryrefslogtreecommitdiffstats
path: root/crates/profile-service
diff options
context:
space:
mode:
Diffstat (limited to 'crates/profile-service')
-rw-r--r--crates/profile-service/Cargo.toml32
-rw-r--r--crates/profile-service/migrations/20250726161947_profile.sql32
-rw-r--r--crates/profile-service/profile.toml37
-rw-r--r--crates/profile-service/src/cnfg.rs8
-rw-r--r--crates/profile-service/src/main.rs110
-rw-r--r--crates/profile-service/src/server.rs2
-rw-r--r--crates/profile-service/src/server/interceptor.rs11
-rw-r--r--crates/profile-service/src/server/manager.rs45
-rw-r--r--crates/profile-service/src/state.rs42
9 files changed, 0 insertions, 319 deletions
diff --git a/crates/profile-service/Cargo.toml b/crates/profile-service/Cargo.toml
deleted file mode 100644
index e56db3a..0000000
--- a/crates/profile-service/Cargo.toml
+++ /dev/null
@@ -1,32 +0,0 @@
-[package]
-name = "sellershut-profiles"
-version = "0.1.0"
-edition = "2024"
-license.workspace = true
-homepage.workspace = true
-documentation.workspace = true
-description.workspace = true
-
-[dependencies]
-anyhow.workspace = true
-base64.workspace = true
-clap = { workspace = true, features = ["derive"] }
-config = { workspace = true, features = ["convert-case", "toml"] }
-futures-util.workspace = true
-nanoid.workspace = true
-prost.workspace = true
-sellershut-core = { workspace = true, features = ["profile", "serde"] }
-serde = { workspace = true, features = ["derive"] }
-serde_json.workspace = true
-sqlx = { workspace = true, features = ["macros", "migrate", "runtime-tokio", "time", "tls-rustls", "uuid"] }
-time = { workspace = true, features = ["parsing", "serde"] }
-tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }
-tonic.workspace = true
-tonic-reflection = "0.13.0"
-tracing.workspace = true
-url.workspace = true
-uuid = { workspace = true, features = ["serde", "v7"] }
-
-[dependencies.stack-up]
-workspace = true
-features = ["api", "cache", "postgres", "tracing"]
diff --git a/crates/profile-service/migrations/20250726161947_profile.sql b/crates/profile-service/migrations/20250726161947_profile.sql
deleted file mode 100644
index 15822c8..0000000
--- a/crates/profile-service/migrations/20250726161947_profile.sql
+++ /dev/null
@@ -1,32 +0,0 @@
-create table profile (
- id text primary key,
- username varchar(30) not null,
- inbox text not null,
- outbox text,
- local boolean not null,
- avatar_url text,
- description text,
- user_type text not null check (
- user_type IN ('PERSON', 'APPLICATION', 'GROUP', 'ORGANIZATION', 'SERVICE')
- ),
- created_at timestamptz not null default now(),
- updated_at timestamptz not null default now(),
- public_key text not null
-);
-
-create unique index unique_username_local
- on profile (username)
- where local = true;
-
-create or replace function set_updated_at()
-returns trigger as $$
-begin
- new.updated_at := now();
- return new;
-end;
-$$ language plpgsql;
-
-create trigger trigger_set_updated_at
-before update on profile
-for each row
-execute function set_updated_at();
diff --git a/crates/profile-service/profile.toml b/crates/profile-service/profile.toml
deleted file mode 100644
index 13a5f0a..0000000
--- a/crates/profile-service/profile.toml
+++ /dev/null
@@ -1,37 +0,0 @@
-[application]
-env = "development"
-port = 1610
-
-[monitoring]
-log-level = "sellershut_profiles=trace,info"
-
-[misc]
-temp-ttl = 1000
-cache-ttl = 300
-
-[database]
-pool_size = 100
-port = 5432
-name = "profiles"
-host = "localhost"
-password = "password"
-user = "postgres"
-
-[nats]
-hosts = ["nats://localhost:4222"]
-
-[cache]
-dsn = "redis://localhost:6379"
-pooled = true
-type = "non-clustered" # clustered, non-clustered or sentinel
-max-connections = 100
-
-[cache.sentinel]
-master-name = "mymaster"
-nodes = [
- { host = "127.0.0.1", port = 26379 },
- { host = "127.0.0.2", port = 26379 },
- { host = "127.0.0.3", port = 26379 },
-]
-
-# vim:ft=toml
diff --git a/crates/profile-service/src/cnfg.rs b/crates/profile-service/src/cnfg.rs
deleted file mode 100644
index fec4cf7..0000000
--- a/crates/profile-service/src/cnfg.rs
+++ /dev/null
@@ -1,8 +0,0 @@
-use serde::Deserialize;
-
-#[derive(Deserialize, Clone)]
-#[serde(rename_all = "kebab-case")]
-pub struct LocalConfig {
- pub temp_ttl: u64,
- pub cache_ttl: u64,
-}
diff --git a/crates/profile-service/src/main.rs b/crates/profile-service/src/main.rs
deleted file mode 100644
index 5fe1331..0000000
--- a/crates/profile-service/src/main.rs
+++ /dev/null
@@ -1,110 +0,0 @@
-mod cnfg;
-mod server;
-mod state;
-use std::net::{Ipv6Addr, SocketAddr};
-
-use clap::Parser;
-use sellershut_core::profile::profile_server::ProfileServer;
-use stack_up::{Configuration, Services, tracing::Tracing};
-use tokio::signal;
-use tonic::transport::{Server, server::TcpIncoming};
-use tracing::{error, info};
-
-use crate::{
- server::interceptor::MyInterceptor,
- state::{AppHandle, AppState},
-};
-
-/// sellershut-profiles
-#[derive(Parser, Debug)]
-#[command(version, about, long_about = None)]
-struct Args {
- /// Path to config file
- #[arg(short, long)]
- config_file: Option<std::path::PathBuf>,
-}
-
-#[tokio::main]
-async fn main() -> anyhow::Result<()> {
- let args = Args::parse();
- let config = include_str!("../profile.toml");
-
- let mut config = config::Config::builder()
- .add_source(config::File::from_str(config, config::FileFormat::Toml));
-
- if let Some(cf) = args.config_file.as_ref().and_then(|v| v.to_str()) {
- config = config.add_source(config::File::new(cf, config::FileFormat::Toml));
- };
-
- let mut config: Configuration = config.build()?.try_deserialize()?;
- config.application.name = env!("CARGO_CRATE_NAME").into();
- config.application.version = env!("CARGO_PKG_VERSION").into();
-
- let tracing = Tracing::builder().build(&config.monitoring);
-
- let mut services = Services::builder()
- .postgres(&config.database)
- .await
- .inspect_err(|e| error!("database: {e}"))?
- .cache(&config.cache)
- .await
- .inspect_err(|e| error!("cache: {e}"))?
- .build();
-
- let postgres = services
- .postgres
- .take()
- .ok_or_else(|| anyhow::anyhow!("database is not ready"))?;
-
- let cache = services
- .cache
- .take()
- .ok_or_else(|| anyhow::anyhow!("cache is not ready"))?;
-
- let services = crate::state::Services { postgres, cache };
-
- let state = AppState::create(services, &config).await?;
-
- let addr = SocketAddr::from((Ipv6Addr::UNSPECIFIED, config.application.port));
-
- let listener = tokio::net::TcpListener::bind(addr).await?;
-
- info!(addr = ?addr, "starting server");
-
- Server::builder()
- .trace_fn(|_| tracing::info_span!(env!("CARGO_PKG_NAME")))
- // .add_service(QueryUsersServer::new(state.clone()))
- .add_service(ProfileServer::with_interceptor(
- state.clone(),
- MyInterceptor,
- ))
- .serve_with_incoming_shutdown(TcpIncoming::from(listener), shutdown_signal(state))
- .await?;
-
- Ok(())
-}
-async fn shutdown_signal(state: AppHandle) {
- let ctrl_c = async {
- signal::ctrl_c()
- .await
- .expect("failed to install Ctrl+C handler");
- };
-
- #[cfg(unix)]
- let terminate = async {
- signal::unix::signal(signal::unix::SignalKind::terminate())
- .expect("failed to install signal handler")
- .recv()
- .await;
- };
-
- #[cfg(not(unix))]
- let terminate = std::future::pending::<()>();
-
- tokio::select! {
- _ = ctrl_c => {
- },
- _ = terminate => {
- },
- }
-}
diff --git a/crates/profile-service/src/server.rs b/crates/profile-service/src/server.rs
deleted file mode 100644
index b2e04f9..0000000
--- a/crates/profile-service/src/server.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-pub mod interceptor;
-pub mod manager;
diff --git a/crates/profile-service/src/server/interceptor.rs b/crates/profile-service/src/server/interceptor.rs
deleted file mode 100644
index 6fbe7fa..0000000
--- a/crates/profile-service/src/server/interceptor.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-use tonic::{Status, service::Interceptor};
-use tracing::Span;
-
-#[derive(Clone, Copy)]
-pub struct MyInterceptor;
-
-impl Interceptor for MyInterceptor {
- fn call(&mut self, request: tonic::Request<()>) -> Result<tonic::Request<()>, Status> {
- Ok(request)
- }
-}
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/src/state.rs b/crates/profile-service/src/state.rs
deleted file mode 100644
index 1ccfbfd..0000000
--- a/crates/profile-service/src/state.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-use std::sync::Arc;
-
-use sqlx::PgPool;
-use stack_up::{Configuration, cache::RedisManager};
-
-use crate::cnfg::LocalConfig;
-
-#[derive(Clone)]
-pub struct AppHandle(Arc<AppState>);
-
-impl std::ops::Deref for AppHandle {
- type Target = Arc<AppState>;
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-#[derive(Clone)]
-pub struct Services {
- pub postgres: PgPool,
- pub cache: RedisManager,
-}
-
-pub struct AppState {
- pub services: Services,
- pub local_config: LocalConfig,
-}
-
-impl AppState {
- pub async fn create(
- services: Services,
- configuration: &Configuration,
- ) -> Result<AppHandle, anyhow::Error> {
- let local_config: LocalConfig = serde_json::from_value(configuration.misc.clone())?;
-
- Ok(AppHandle(Arc::new(Self {
- services,
- local_config,
- })))
- }
-}