aboutsummaryrefslogtreecommitdiffstats
path: root/sellershut/src/server/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'sellershut/src/server/mod.rs')
-rw-r--r--sellershut/src/server/mod.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/sellershut/src/server/mod.rs b/sellershut/src/server/mod.rs
new file mode 100644
index 0000000..9ec4bf4
--- /dev/null
+++ b/sellershut/src/server/mod.rs
@@ -0,0 +1,75 @@
+mod routes;
+pub mod shutdown;
+
+use std::sync::Arc;
+
+use axum::Router;
+use utoipa::OpenApi;
+use utoipa_axum::router::OpenApiRouter;
+
+use crate::{server::routes::ApiDoc, state::AppState};
+
+pub async fn router(state: Arc<AppState>) -> Router<()> {
+ let doc = ApiDoc::openapi();
+
+ // doc.merge(other_doc);
+
+ let stubs = OpenApiRouter::with_openapi(doc).routes(utoipa_axum::routes!(routes::health));
+
+ let (router, _api) = stubs.split_for_parts();
+
+ #[cfg(feature = "swagger")]
+ let router = router.merge(
+ utoipa_swagger_ui::SwaggerUi::new("/swagger-ui")
+ .url("/api-docs/swaggerdoc.json", _api.clone()),
+ );
+
+ #[cfg(feature = "redoc")]
+ let router = {
+ use utoipa_redoc::Servable as _;
+ router.merge(utoipa_redoc::Redoc::with_url("/redoc", _api.clone()))
+ };
+
+ #[cfg(feature = "scalar")]
+ let router = {
+ use utoipa_scalar::Servable as _;
+ router.merge(utoipa_scalar::Scalar::with_url("/scalar", _api.clone()))
+ };
+
+ #[cfg(feature = "rapidoc")]
+ let router = router.merge(
+ utoipa_rapidoc::RapiDoc::with_openapi("/api-docs/rapidoc.json", _api).path("/rapidoc"),
+ );
+
+ router.with_state(state)
+}
+
+#[cfg(test)]
+pub mod tests {
+ use std::str::FromStr;
+
+ use auth_service::client::{ClientConfig, OauthClient};
+ use secrecy::SecretString;
+ use shared_svc::cache::{CacheConfig, RedisManager, RedisVariant};
+ use url::Url;
+
+ pub async fn get_redis() -> RedisManager {
+ let config = CacheConfig {
+ redis_dsn: Url::parse("redis://localhost:6379/15").unwrap(),
+ pooled: false,
+ kind: RedisVariant::NonClustered,
+ max_connections: 10,
+ };
+ RedisManager::new(&config).await.unwrap()
+ }
+
+ pub fn get_oauth_client() -> OauthClient {
+ let oauth_client = ClientConfig::new(
+ String::default(),
+ SecretString::default(),
+ Url::from_str("http://localhost").unwrap(),
+ Url::from_str("http://localhost").unwrap(),
+ );
+ OauthClient::try_from(&oauth_client).unwrap()
+ }
+}