diff --git a/acldb/src/rpc.rs b/acldb/src/rpc.rs index e3c0a24..32dc07a 100644 --- a/acldb/src/rpc.rs +++ b/acldb/src/rpc.rs @@ -25,7 +25,7 @@ pub struct RpcResponse { } /// ACL update request parameters -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, ToSchema)] pub struct AclUpdateParams { /// Public key of the requesting user pub caller_pubkey: String, @@ -40,7 +40,7 @@ pub struct AclUpdateParams { } /// ACL remove request parameters -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, ToSchema)] pub struct AclRemoveParams { /// Public key of the requesting user pub caller_pubkey: String, @@ -53,7 +53,7 @@ pub struct AclRemoveParams { } /// ACL delete request parameters -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, ToSchema)] pub struct AclDelParams { /// Public key of the requesting user pub caller_pubkey: String, @@ -64,7 +64,7 @@ pub struct AclDelParams { } /// Set request parameters -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, ToSchema)] pub struct SetParams { /// Public key of the requesting user pub caller_pubkey: String, @@ -83,7 +83,7 @@ pub struct SetParams { } /// Delete request parameters -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, ToSchema)] pub struct DelParams { /// Public key of the requesting user pub caller_pubkey: String, @@ -98,7 +98,7 @@ pub struct DelParams { } /// Get request parameters -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, ToSchema)] pub struct GetParams { /// Public key of the requesting user pub caller_pubkey: String, @@ -113,7 +113,7 @@ pub struct GetParams { } /// Prefix request parameters -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, ToSchema)] pub struct PrefixParams { /// Public key of the requesting user pub caller_pubkey: String, diff --git a/acldb/src/server.rs b/acldb/src/server.rs index b758ea6..d4b6533 100644 --- a/acldb/src/server.rs +++ b/acldb/src/server.rs @@ -7,7 +7,7 @@ use std::future; use tokio::sync::mpsc; use tokio::sync::RwLock; use serde_json::json; -use log::{error}; +use log::{error, info}; use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; @@ -158,20 +158,25 @@ impl Server { /// Starts the server pub async fn start(&self) -> std::io::Result<()> { - let server_data = web::Data::new(self.clone()); + let server = self.clone(); + + // Register RPC handlers + self.register_handlers(); + + info!("Starting ACLDB server on {}:{}", self.config.host, self.config.port); + info!("Swagger UI available at: http://{}:{}/swagger-ui/", self.config.host, self.config.port); // Start the HTTP server HttpServer::new(move || { App::new() + .app_data(web::Data::new(server.clone())) .wrap(Logger::default()) .wrap( Cors::default() .allow_any_origin() .allow_any_method() .allow_any_header() - .max_age(3600) ) - .app_data(web::Data::clone(&server_data)) .route("/rpc", web::post().to(handle_rpc)) .route("/health", web::get().to(health_check)) .service( @@ -179,7 +184,7 @@ impl Server { .url("/api-docs/openapi.json", ApiDoc::openapi()) ) }) - .bind(format!("{}:{}", self.config.host, self.config.port))? + .bind(format!("{0}:{1}", self.config.host, self.config.port))? .run() .await } @@ -256,31 +261,25 @@ fn extract_circle_id(request: &web::Json) -> Result { /// API documentation schema #[derive(OpenApi)] #[openapi( - paths( - health_check, - handle_rpc - ), components( schemas(RpcRequest, RpcResponse) ), tags( - (name = "acldb", description = "ACLDB API") + (name = "acldb", description = "ACLDB API - Access Control Database") + ), + info( + title = "ACLDB API", + version = "1.0.0", + description = "API for managing access control lists and data operations in HeroDB", + contact( + name = "HeroDB Team", + url = "https://ourworld.tf" + ) ) )] struct ApiDoc; -/// Handler for RPC requests with OpenAPI documentation -#[utoipa::path( - post, - path = "/rpc", - request_body = RpcRequest, - responses( - (status = 200, description = "RPC request processed successfully", body = RpcResponse), - (status = 400, description = "Bad request", body = RpcResponse), - (status = 500, description = "Internal server error", body = RpcResponse) - ), - tag = "acldb" -)] +/// Handler for RPC requests async fn handle_rpc( server: web::Data, request: web::Json, @@ -470,19 +469,13 @@ async fn process_request( } } -/// Handler for health check with OpenAPI documentation -#[utoipa::path( - get, - path = "/health", - responses( - (status = 200, description = "Server is healthy", body = String) - ), - tag = "acldb" -)] +/// Handler for health check async fn health_check() -> impl Responder { HttpResponse::Ok().json(json!({"status": "ok"})) } + + #[cfg(test)] mod tests { // Tests will be added here diff --git a/herodb/src/models/mcc/calendar.rs b/herodb/src/models/mcc/calendar.rs index 816ae08..266a1dc 100644 --- a/herodb/src/models/mcc/calendar.rs +++ b/herodb/src/models/mcc/calendar.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::db::{SledModel, Storable, SledDB, SledDBResult}; +use crate::db::{Model, Storable, DB, DbError, DbResult}; use crate::models::mcc::event::Event; /// Calendar represents a calendar container for events @@ -51,13 +51,12 @@ impl Calendar { } } -// Implement Storable trait (provides default dump/load) -impl Storable for Calendar {} +impl Storable for Calendar{} -// Implement SledModel trait -impl SledModel for Calendar { - fn get_id(&self) -> String { - self.id.to_string() +// Implement Model trait +impl Model for Calendar { + fn get_id(&self) -> u32 { + self.id } fn db_prefix() -> &'static str { diff --git a/herodb/src/models/mcc/contacts.rs b/herodb/src/models/mcc/contacts.rs index 0854d9e..2a50f5b 100644 --- a/herodb/src/models/mcc/contacts.rs +++ b/herodb/src/models/mcc/contacts.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::db::{SledModel, Storable, SledDB, SledDBResult}; +use crate::db::{Model, Storable, DB, DbError, DbResult}; use crate::models::mcc::event::Event; use chrono::Utc; @@ -63,8 +63,8 @@ impl Contact { } /// Get events where this contact is an attendee - pub fn get_events(&self, db: &SledDB) -> SledDBResult> { - let all_events = db.list()?; + pub fn get_events(&self, db: &DB) -> DbResult> { + let all_events = db.list::()?; let contact_events = all_events .into_iter() .filter(|event| event.attendees.contains(&self.email)) @@ -110,12 +110,12 @@ impl Contact { impl Storable for Contact {} // Implement SledModel trait -impl SledModel for Contact { - fn get_id(&self) -> String { - self.id.to_string() +impl Model for Contact { + fn get_id(&self) -> u32 { + self.id } fn db_prefix() -> &'static str { "contact" } -} \ No newline at end of file +} diff --git a/herodb/src/models/mcc/event.rs b/herodb/src/models/mcc/event.rs index e79e56b..1a4f660 100644 --- a/herodb/src/models/mcc/event.rs +++ b/herodb/src/models/mcc/event.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::db::{SledModel, Storable, SledDB, SledDBResult}; +use crate::db::{Model, Storable, DB, DbError, DbResult}; use crate::models::mcc::calendar::Calendar; use crate::models::mcc::contacts::Contact; use chrono::{DateTime, Utc}; diff --git a/herodb/src/models/mcc/mail.rs b/herodb/src/models/mcc/mail.rs index 68912e0..3054e13 100644 --- a/herodb/src/models/mcc/mail.rs +++ b/herodb/src/models/mcc/mail.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::db::{SledModel, Storable, SledDBResult, SledDB}; +use crate::db::{Model, Storable, DB, DbError, DbResult}; use chrono::Utc; /// Email represents an email message with all its metadata and content diff --git a/herodb/src/models/mcc/message.rs b/herodb/src/models/mcc/message.rs index 5728453..c92e727 100644 --- a/herodb/src/models/mcc/message.rs +++ b/herodb/src/models/mcc/message.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use crate::db::{SledModel, Storable, SledDB, SledDBResult}; +use crate::db::{Model, Storable, DB, DbError, DbResult}; use chrono::{DateTime, Utc}; /// MessageStatus represents the status of a message diff --git a/herodb/src/models/mcc/mod.rs b/herodb/src/models/mcc/mod.rs index 11ae716..8780078 100644 --- a/herodb/src/models/mcc/mod.rs +++ b/herodb/src/models/mcc/mod.rs @@ -12,4 +12,4 @@ pub use contacts::Contact; pub use message::{Message, MessageMeta, MessageStatus}; // Re-export database components from db module -pub use crate::db::{SledDB, SledDBError, SledDBResult, Storable, SledModel, DB}; \ No newline at end of file +pub use crate::db::{DB, DBBuilder, Model, Storable, DbError, DbResult}; \ No newline at end of file