init projectmycelium
This commit is contained in:
335
src/routes/mod.rs
Normal file
335
src/routes/mod.rs
Normal file
@@ -0,0 +1,335 @@
|
||||
use crate::config::oauth::GiteaOAuthConfig;
|
||||
use crate::controllers::auth::AuthController;
|
||||
use crate::controllers::currency::CurrencyController;
|
||||
use crate::controllers::dashboard::DashboardController;
|
||||
use crate::controllers::debug::DebugController;
|
||||
use crate::controllers::docs::DocsController;
|
||||
use crate::controllers::gitea_auth::GiteaAuthController;
|
||||
use crate::controllers::home::HomeController;
|
||||
use crate::controllers::marketplace::MarketplaceController;
|
||||
use crate::controllers::messaging::MessagingController;
|
||||
use crate::controllers::order::OrderController;
|
||||
use crate::controllers::pool::PoolController;
|
||||
use crate::controllers::product::ProductController;
|
||||
use crate::controllers::public::PublicController;
|
||||
use crate::controllers::rental::RentalController;
|
||||
use crate::controllers::wallet::WalletController;
|
||||
use crate::middleware::JwtAuth;
|
||||
use crate::SESSION_KEY;
|
||||
use actix_session::{storage::CookieSessionStore, SessionMiddleware};
|
||||
use actix_web::web;
|
||||
use std::env;
|
||||
|
||||
/// Configures all application routes
|
||||
pub fn configure_routes(cfg: &mut web::ServiceConfig) {
|
||||
// Configure session middleware with the consistent key
|
||||
let session_middleware =
|
||||
SessionMiddleware::builder(CookieSessionStore::default(), SESSION_KEY.clone())
|
||||
.cookie_secure(false) // Set to true in production with HTTPS
|
||||
.cookie_http_only(true)
|
||||
.cookie_name("threefold_marketplace_session".to_string())
|
||||
.cookie_path("/".to_string())
|
||||
.cookie_same_site(actix_web::cookie::SameSite::Lax) // Important for OAuth redirects
|
||||
.session_lifecycle(
|
||||
actix_session::config::PersistentSession::default()
|
||||
.session_ttl(actix_web::cookie::time::Duration::hours(2)),
|
||||
)
|
||||
.build();
|
||||
|
||||
// Build the main scope with common routes
|
||||
let mut main_scope = web::scope("")
|
||||
.wrap(session_middleware) // Wrap with session middleware
|
||||
// Home routes
|
||||
.route("/", web::get().to(HomeController::index))
|
||||
.route("/about", web::get().to(HomeController::about))
|
||||
.route("/contact", web::get().to(HomeController::contact))
|
||||
// Marketplace routes
|
||||
.route("/marketplace", web::get().to(MarketplaceController::dashboard))
|
||||
.route("/marketplace/compute", web::get().to(MarketplaceController::compute_resources))
|
||||
.route("/marketplace/3nodes", web::get().to(MarketplaceController::three_nodes))
|
||||
.route("/marketplace/gateways", web::get().to(MarketplaceController::gateways))
|
||||
.route("/marketplace/applications", web::get().to(MarketplaceController::applications))
|
||||
.route("/marketplace/services", web::get().to(MarketplaceController::services))
|
||||
.route("/marketplace/statistics", web::get().to(MarketplaceController::statistics))
|
||||
// Slice rental routes
|
||||
.route("/marketplace/slice/rent/{farmer_email}/{node_id}/{combination_id}", web::get().to(MarketplaceController::show_slice_rental_form))
|
||||
.route("/marketplace/slice/rent", web::post().to(MarketplaceController::process_slice_rental))
|
||||
// .route("/marketplace/rent-slice", web::post().to(MarketplaceController::rent_slice)) // Legacy route [DISABLED]
|
||||
// Product routes
|
||||
.route("/products", web::get().to(ProductController::list_products))
|
||||
.route("/products/{id}", web::get().to(ProductController::get_product_details))
|
||||
.route("/cart", web::get().to(OrderController::view_cart))
|
||||
.route("/checkout", web::get().to(OrderController::checkout))
|
||||
.route("/orders", web::get().to(OrderController::view_order_history))
|
||||
.route("/orders/{id}", web::get().to(OrderController::get_order_details))
|
||||
.route("/orders/{id}/invoice", web::get().to(OrderController::get_order_invoice))
|
||||
.route("/orders/{id}/confirmation", web::get().to(OrderController::get_order_confirmation))
|
||||
// API routes
|
||||
.service(
|
||||
web::scope("/api")
|
||||
// Product API
|
||||
.route("/products", web::get().to(ProductController::list_products))
|
||||
.route("/products/{id}", web::get().to(ProductController::get_product_details))
|
||||
.route("/products/search", web::get().to(ProductController::search_products))
|
||||
.route("/products/categories", web::get().to(ProductController::get_categories))
|
||||
.route("/products/featured", web::get().to(ProductController::get_featured_products))
|
||||
// Debug API
|
||||
.route("/debug/products", web::get().to(OrderController::debug_products))
|
||||
// Cart API
|
||||
.route("/cart", web::get().to(OrderController::get_cart_json))
|
||||
.route("/cart/add", web::post().to(OrderController::add_to_cart))
|
||||
.route("/cart/item/{id}", web::put().to(OrderController::update_cart_item))
|
||||
.route("/cart/item/{id}", web::delete().to(OrderController::remove_from_cart))
|
||||
.route("/cart", web::delete().to(OrderController::clear_cart))
|
||||
// Order API
|
||||
.route("/orders", web::post().to(OrderController::place_order))
|
||||
.route("/orders", web::get().to(OrderController::get_orders_json))
|
||||
.route("/orders/{id}", web::get().to(OrderController::get_order_details))
|
||||
// Currency API
|
||||
.route("/currencies", web::get().to(CurrencyController::get_supported_currencies))
|
||||
.route("/currencies/rates", web::get().to(CurrencyController::get_exchange_rates))
|
||||
.route("/currencies/convert", web::post().to(CurrencyController::convert_price))
|
||||
.route("/currencies/widget", web::get().to(CurrencyController::get_currency_widget_data))
|
||||
.route("/user/currency", web::get().to(CurrencyController::get_user_currency_preference))
|
||||
.route("/user/currency", web::post().to(CurrencyController::set_user_currency_preference))
|
||||
// Auth API routes
|
||||
.route("/auth/status", web::get().to(AuthController::auth_status))
|
||||
// Dashboard API routes
|
||||
.route("/dashboard/user-data", web::get().to(DashboardController::user_data_api))
|
||||
.route("/dashboard/user-dashboard-data", web::get().to(DashboardController::user_dashboard_data_api))
|
||||
// User dashboard API routes
|
||||
.route("/dashboard/user/activities", web::post().to(DashboardController::add_user_activity))
|
||||
.route("/dashboard/user/preferences", web::get().to(DashboardController::get_user_preferences))
|
||||
.route("/dashboard/user/preferences", web::put().to(DashboardController::update_user_preferences))
|
||||
.route("/dashboard/user/service-bookings", web::get().to(DashboardController::get_user_service_bookings_api))
|
||||
// Slice rental management API routes
|
||||
.route("/dashboard/slice-rentals", web::get().to(DashboardController::get_user_slice_rentals))
|
||||
.route("/dashboard/slice-rentals/{id}/manage", web::post().to(DashboardController::manage_slice_rental_deployment))
|
||||
.route("/dashboard/slice-rentals/{id}", web::delete().to(DashboardController::cancel_slice_rental))
|
||||
.route("/dashboard/user/slice-rentals/{id}", web::post().to(DashboardController::manage_slice_rental))
|
||||
.route("/dashboard/farmer-data", web::get().to(DashboardController::farmer_data_api))
|
||||
.route("/dashboard/app-provider-data", web::get().to(DashboardController::app_provider_data_api))
|
||||
.route("/dashboard/slice-products", web::get().to(DashboardController::get_slice_products))
|
||||
.route("/dashboard/slice-products", web::post().to(DashboardController::create_slice_product))
|
||||
.route("/dashboard/slice-products/{id}", web::delete().to(DashboardController::delete_slice_product))
|
||||
// Enhanced slice management routes
|
||||
.route("/dashboard/slice-details/{id}", web::get().to(DashboardController::get_slice_details))
|
||||
.route("/dashboard/slice-configuration/{id}", web::put().to(DashboardController::update_slice_configuration))
|
||||
.route("/dashboard/service-provider-data", web::get().to(DashboardController::service_provider_data_api))
|
||||
// Farmer management API routes
|
||||
.route("/dashboard/farm-nodes", web::post().to(DashboardController::add_farm_node))
|
||||
.route("/dashboard/farm-nodes-enhanced", web::post().to(DashboardController::add_farm_node_enhanced))
|
||||
.route("/dashboard/farm-nodes/{id}", web::get().to(DashboardController::get_node_details))
|
||||
.route("/dashboard/farm-nodes/{id}", web::put().to(DashboardController::update_node_comprehensive))
|
||||
.route("/dashboard/farm-nodes/{id}/status", web::put().to(DashboardController::update_node_status))
|
||||
// Farmer slice management API routes
|
||||
.route("/dashboard/farmer/slice-calculations/refresh", web::post().to(DashboardController::refresh_slice_calculations))
|
||||
.route("/dashboard/farmer/grid-sync", web::post().to(DashboardController::sync_with_grid))
|
||||
.route("/dashboard/farmer/nodes/{id}/slices", web::get().to(DashboardController::get_node_slices))
|
||||
.route("/dashboard/farmer/slice-statistics", web::get().to(DashboardController::get_slice_statistics))
|
||||
.route("/dashboard/farm-nodes/{id}", web::delete().to(DashboardController::delete_node))
|
||||
.route("/dashboard/farm-nodes/{id}/configuration", web::put().to(DashboardController::update_node_configuration))
|
||||
.route("/dashboard/default-slice-formats", web::get().to(DashboardController::get_default_slice_formats))
|
||||
.route("/dashboard/default-slice-details/{id}", web::get().to(DashboardController::get_default_slice_details))
|
||||
.route("/dashboard/default-slice-customization/{id}", web::put().to(DashboardController::save_default_slice_customization))
|
||||
// Grid node management API routes
|
||||
.route("/dashboard/grid-nodes/validate", web::post().to(DashboardController::validate_grid_nodes))
|
||||
.route("/dashboard/grid-nodes/add", web::post().to(DashboardController::add_grid_nodes))
|
||||
// Automatic slice management API routes
|
||||
.route("/dashboard/validate-grid-nodes-automatic", web::post().to(DashboardController::validate_grid_nodes_automatic))
|
||||
// .route("/dashboard/add-nodes-automatic", web::post().to(DashboardController::add_nodes_automatic)) // Deprecated [DISABLED]
|
||||
.route("/dashboard/refresh-slice-calculations", web::post().to(DashboardController::refresh_slice_calculations_api))
|
||||
.route("/dashboard/sync-with-grid", web::post().to(DashboardController::sync_with_grid_api))
|
||||
.route("/dashboard/node-slices/{id}", web::get().to(DashboardController::get_node_slices_api))
|
||||
.route("/dashboard/node-groups", web::get().to(DashboardController::get_node_groups))
|
||||
.route("/dashboard/node-groups", web::post().to(DashboardController::create_node_group))
|
||||
.route("/dashboard/node-groups/api", web::get().to(DashboardController::get_node_groups_api))
|
||||
.route("/dashboard/node-groups/custom", web::post().to(DashboardController::create_custom_node_group))
|
||||
.route("/dashboard/node-groups/{id}", web::delete().to(DashboardController::delete_custom_node_group))
|
||||
.route("/dashboard/nodes/assign-group", web::post().to(DashboardController::assign_node_to_group))
|
||||
// Node staking API routes
|
||||
.route("/dashboard/farm-nodes/{id}/stake", web::post().to(DashboardController::stake_on_node))
|
||||
.route("/dashboard/farm-nodes/{id}/staking", web::put().to(DashboardController::update_node_staking))
|
||||
.route("/dashboard/staking/statistics", web::get().to(DashboardController::get_staking_statistics))
|
||||
// Service management API routes
|
||||
.route("/dashboard/services", web::get().to(DashboardController::get_user_services))
|
||||
.route("/dashboard/services", web::post().to(DashboardController::create_service))
|
||||
.route("/dashboard/services/{id}", web::put().to(DashboardController::update_service))
|
||||
.route("/dashboard/services/{id}", web::delete().to(DashboardController::delete_service))
|
||||
// App management API routes
|
||||
.route("/dashboard/apps", web::get().to(DashboardController::get_user_apps))
|
||||
.route("/dashboard/apps", web::post().to(DashboardController::create_app))
|
||||
.route("/dashboard/apps/{id}", web::put().to(DashboardController::update_app))
|
||||
.route("/dashboard/apps/{id}", web::delete().to(DashboardController::delete_app))
|
||||
// Product management API routes (Service Provider applications)
|
||||
.route("/dashboard/products", web::get().to(DashboardController::get_user_products))
|
||||
.route("/dashboard/products", web::post().to(DashboardController::create_product))
|
||||
// Deployment management API routes
|
||||
.route("/dashboard/deployment/{id}", web::get().to(DashboardController::get_deployment_details))
|
||||
// Enhanced service management API routes for comprehensive management
|
||||
.route("/dashboard/services/{id}/details", web::get().to(DashboardController::get_service_details))
|
||||
.route("/dashboard/services/{id}/analytics", web::get().to(DashboardController::get_service_analytics))
|
||||
.route("/dashboard/services/{id}/clients", web::get().to(DashboardController::get_service_clients))
|
||||
.route("/dashboard/services/{id}/status", web::put().to(DashboardController::update_service_status))
|
||||
// Service request management API routes
|
||||
.route("/dashboard/service-requests", web::get().to(DashboardController::get_user_service_requests))
|
||||
.route("/dashboard/service-requests/{id}", web::put().to(DashboardController::update_service_request))
|
||||
.route("/dashboard/service-requests/{id}/progress", web::put().to(DashboardController::update_service_request_progress))
|
||||
.route("/dashboard/service-requests/{id}/details", web::get().to(DashboardController::get_service_request_details))
|
||||
.route("/dashboard/service-requests/{id}/completed-details", web::get().to(DashboardController::get_completed_request_details))
|
||||
.route("/dashboard/service-requests/{id}/invoice", web::get().to(DashboardController::generate_service_request_invoice))
|
||||
.route("/dashboard/service-requests/{id}/report", web::get().to(DashboardController::get_service_request_report))
|
||||
// Availability management API routes
|
||||
.route("/dashboard/availability", web::get().to(DashboardController::get_user_availability))
|
||||
.route("/dashboard/availability", web::put().to(DashboardController::update_user_availability))
|
||||
// SLA management API routes
|
||||
.route("/dashboard/slas", web::get().to(DashboardController::get_user_slas))
|
||||
.route("/dashboard/slas", web::post().to(DashboardController::create_sla))
|
||||
.route("/dashboard/slas/{id}", web::put().to(DashboardController::update_sla))
|
||||
.route("/dashboard/slas/{id}", web::delete().to(DashboardController::delete_sla))
|
||||
// Agreement download API route
|
||||
.route("/dashboard/agreement/download", web::get().to(DashboardController::download_agreement))
|
||||
// Settings API routes
|
||||
.route("/dashboard/settings/profile", web::post().to(DashboardController::update_profile))
|
||||
.route("/dashboard/settings/password", web::post().to(DashboardController::update_password))
|
||||
.route("/dashboard/settings/notifications", web::post().to(DashboardController::update_notifications))
|
||||
.route("/dashboard/settings/verify-password", web::post().to(DashboardController::verify_password))
|
||||
.route("/dashboard/settings/delete-account", web::post().to(DashboardController::delete_account))
|
||||
.route("/dashboard/settings/billing-history", web::get().to(DashboardController::get_billing_history))
|
||||
// SSH key management API routes
|
||||
.route("/dashboard/ssh-keys", web::get().to(DashboardController::get_ssh_keys))
|
||||
.route("/dashboard/ssh-keys", web::post().to(DashboardController::add_ssh_key))
|
||||
.route("/dashboard/ssh-keys/{id}", web::put().to(DashboardController::update_ssh_key))
|
||||
.route("/dashboard/ssh-keys/{id}", web::delete().to(DashboardController::delete_ssh_key))
|
||||
.route("/dashboard/ssh-keys/{id}/set-default", web::post().to(DashboardController::set_default_ssh_key))
|
||||
.route("/dashboard/ssh-keys/{id}", web::get().to(DashboardController::get_ssh_key_details))
|
||||
// Rental API routes
|
||||
.route("/products/{id}/rent", web::post().to(RentalController::rent_product))
|
||||
.route("/products/{id}/rent-node", web::post().to(RentalController::rent_node_product))
|
||||
.route("/products/{id}/purchase", web::post().to(RentalController::purchase_product))
|
||||
.route("/rentals/{id}/cancel", web::delete().to(RentalController::cancel_rental))
|
||||
// Credits API routes
|
||||
.route("/wallet/buy-credits", web::post().to(WalletController::buy_credits))
|
||||
.route("/wallet/sell-credits", web::post().to(WalletController::sell_credits))
|
||||
.route("/wallet/transfer-credits", web::post().to(WalletController::transfer_credits))
|
||||
.route("/wallet/balance", web::get().to(WalletController::get_balance))
|
||||
.route("/wallet/info", web::get().to(WalletController::get_wallet_info))
|
||||
.route("/wallet/transactions", web::get().to(WalletController::get_transactions))
|
||||
// OpenRouter-style instant purchase and top-up routes
|
||||
.route("/wallet/instant-purchase", web::post().to(WalletController::instant_purchase))
|
||||
.route("/wallet/quick-topup", web::post().to(WalletController::quick_topup))
|
||||
.route("/wallet/check-affordability", web::get().to(WalletController::check_affordability))
|
||||
.route("/wallet/topup-amounts", web::get().to(WalletController::get_quick_topup_amounts))
|
||||
// Auto top-up API routes
|
||||
.route("/wallet/auto-topup/configure", web::post().to(WalletController::configure_auto_topup))
|
||||
.route("/wallet/auto-topup/status", web::get().to(WalletController::get_auto_topup_status))
|
||||
.route("/wallet/auto-topup/trigger", web::post().to(WalletController::trigger_auto_topup))
|
||||
.route("/wallet/last-payment-method", web::get().to(WalletController::get_last_payment_method))
|
||||
// Navbar API routes
|
||||
.route("/navbar/dropdown-data", web::get().to(WalletController::get_navbar_data))
|
||||
// Slice rental API routes
|
||||
// .route("/marketplace/rent-slice", web::post().to(MarketplaceController::rent_slice)) // Deprecated [DISABLED]
|
||||
// Pool API routes
|
||||
.route("/pools", web::get().to(PoolController::get_pools))
|
||||
.route("/pools/{pool_id}", web::get().to(PoolController::get_pool))
|
||||
.route("/pools/exchange", web::post().to(PoolController::exchange_tokens))
|
||||
.route("/pools/analytics", web::get().to(PoolController::get_analytics))
|
||||
// Messaging API routes
|
||||
.route("/messages/threads", web::get().to(MessagingController::get_threads))
|
||||
.route("/messages/threads", web::post().to(MessagingController::create_thread))
|
||||
.route("/messages/threads/{thread_id}/messages", web::get().to(MessagingController::get_messages))
|
||||
.route("/messages/threads/{thread_id}/messages", web::post().to(MessagingController::send_message_with_path))
|
||||
.route("/messages/threads/{thread_id}/read", web::put().to(MessagingController::mark_thread_read))
|
||||
.route("/messages", web::post().to(MessagingController::send_message))
|
||||
)
|
||||
// Documentation routes
|
||||
.route("/docs", web::get().to(DocsController::index))
|
||||
.route("/docs/getting-started", web::get().to(DocsController::getting_started))
|
||||
.route("/docs/3nodes", web::get().to(DocsController::three_nodes))
|
||||
.route("/docs/compute", web::get().to(DocsController::compute))
|
||||
.route("/docs/gateways", web::get().to(DocsController::gateways))
|
||||
.route("/docs/applications", web::get().to(DocsController::applications))
|
||||
.route("/docs/services", web::get().to(DocsController::services))
|
||||
.route("/docs/credits", web::get().to(DocsController::credits))
|
||||
.route("/docs/slices", web::get().to(DocsController::slices))
|
||||
.route("/docs/certification", web::get().to(DocsController::certification))
|
||||
.route("/docs/api", web::get().to(DocsController::api))
|
||||
// Dashboard routes (protected by JwtAuth middleware)
|
||||
.service(
|
||||
web::scope("/dashboard")
|
||||
.wrap(JwtAuth) // Apply authentication middleware to all dashboard routes
|
||||
.route("", web::get().to(DashboardController::index))
|
||||
.route("/user", web::get().to(DashboardController::user_section))
|
||||
.route("/farmer", web::get().to(DashboardController::farmer_section))
|
||||
.route("/app-provider", web::get().to(DashboardController::app_provider_section))
|
||||
.route("/service-provider", web::get().to(DashboardController::service_provider_section))
|
||||
|
||||
// Shopping routes - embedded in dashboard
|
||||
.route("/cart", web::get().to(DashboardController::cart_section))
|
||||
.route("/orders", web::get().to(DashboardController::orders_section))
|
||||
|
||||
// HIDE: Main pools route - keep for admin/future use
|
||||
// .route("/pools", web::get().to(DashboardController::pools))
|
||||
|
||||
// Keep as hidden admin route
|
||||
.route("/pools-admin", web::get().to(DashboardController::pools))
|
||||
.route("/settings", web::get().to(DashboardController::settings))
|
||||
// Dashboard messaging route
|
||||
.route("/messages", web::get().to(DashboardController::messages_page))
|
||||
// Dashboard wallet route
|
||||
.route("/wallet", web::get().to(WalletController::dashboard_wallet_page))
|
||||
)
|
||||
// Public information routes (legal, changelog, roadmap)
|
||||
.route("/privacy", web::get().to(PublicController::privacy))
|
||||
.route("/terms", web::get().to(PublicController::terms))
|
||||
.route("/terms/farmers", web::get().to(PublicController::terms_farmers))
|
||||
.route("/terms/service-providers", web::get().to(PublicController::terms_service_providers))
|
||||
.route("/terms/solution-providers", web::get().to(PublicController::terms_solution_providers))
|
||||
.route("/terms/users", web::get().to(PublicController::terms_users))
|
||||
.route("/changelog", web::get().to(PublicController::changelog))
|
||||
.route("/roadmap", web::get().to(PublicController::roadmap));
|
||||
|
||||
// Conditionally add authentication routes based on GITEA_CLIENT_ID environment variable
|
||||
if env::var("GITEA_CLIENT_ID").ok().filter(|s| !s.is_empty()).is_some() {
|
||||
// Use Gitea OAuth flow
|
||||
// Create the OAuth configuration and add it to the scope
|
||||
let oauth_config = web::Data::new(GiteaOAuthConfig::new());
|
||||
main_scope = main_scope
|
||||
.app_data(oauth_config) // Add oauth_config data
|
||||
// Gitea OAuth routes
|
||||
.route("/login", web::get().to(GiteaAuthController::login)) // Add /login route for gitea
|
||||
.route("/auth/gitea", web::get().to(GiteaAuthController::login))
|
||||
.route(
|
||||
"/auth/gitea/callback",
|
||||
web::get().to(GiteaAuthController::callback),
|
||||
);
|
||||
} else {
|
||||
// Use standard username/password login
|
||||
main_scope = main_scope
|
||||
.route("/login", web::get().to(AuthController::login_page))
|
||||
.route("/login", web::post().to(AuthController::login))
|
||||
.route("/register", web::get().to(AuthController::register_page))
|
||||
.route("/register", web::post().to(AuthController::register));
|
||||
}
|
||||
|
||||
// Add common auth and debug routes (logout is common to both flows)
|
||||
main_scope = main_scope
|
||||
.route("/logout", web::get().to(AuthController::logout))
|
||||
// Debug routes
|
||||
.route("/debug", web::get().to(DebugController::debug_info));
|
||||
|
||||
// Register the main scope service
|
||||
cfg.service(main_scope);
|
||||
|
||||
// Protected routes that require JWT authentication
|
||||
cfg.service(
|
||||
web::scope("/protected").wrap(JwtAuth), // Apply JWT authentication middleware
|
||||
);
|
||||
|
||||
// API routes that require JWT authentication (for external API access)
|
||||
cfg.service(
|
||||
web::scope("/api/v1")
|
||||
.wrap(JwtAuth) // Apply JWT auth for versioned API endpoints
|
||||
// Future API endpoints would go here
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user