diff --git a/crates/backend/src/error.rs b/crates/backend/src/error.rs index 4747a25..e34cbba 100644 --- a/crates/backend/src/error.rs +++ b/crates/backend/src/error.rs @@ -67,10 +67,3 @@ impl MessageResponse { } } -#[derive(Serialize, ToSchema)] -pub struct ApiErrorResponse { - /// Error message - pub error: String, - /// HTTP status code - pub status: u16, -} diff --git a/crates/backend/src/main.rs b/crates/backend/src/main.rs index cf16015..4a47193 100644 --- a/crates/backend/src/main.rs +++ b/crates/backend/src/main.rs @@ -2,12 +2,12 @@ use actix_session::{SessionMiddleware, storage::RedisSessionStore}; use actix_web::cookie::SameSite; use actix_web::{App, HttpServer, cookie::Key, middleware::Logger, web}; use log::debug; -use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; mod controller; mod db; mod error; +mod utoipa; pub use db::Database; pub use db::entity; @@ -20,62 +20,6 @@ struct AppConfig { ldap_auth: bool, } -#[derive(OpenApi)] -#[openapi( - info( - title = "PGG API", - description = "API for the PGG (Peer Group Grading) application", - version = "0.0.1-rc1", - ), - paths( - controller::auth::login, - controller::auth::logout, - controller::project::get_projects, - controller::project::get_project, - controller::project::create_project, - controller::project::update_project, - controller::project::delete_project, - controller::user::get_users, - controller::user::get_user, - controller::user::create_user, - controller::user::update_user, - controller::user::delete_user, - controller::group::get_groups, - controller::group::get_groups_for_project, - controller::group::create_group, - controller::group::update_group, - controller::group::delete_group, - controller::class::get_classes, - controller::class::get_class, - controller::class::create_class, - controller::class::update_class, - controller::class::delete_class, - controller::template::get_templates, - controller::template::get_template, - controller::template::create_template, - controller::template::update_template, - controller::template::delete_template, - ), - components(schemas( - controller::auth::LoginRequest, - error::MessageResponse, - error::ApiErrorResponse, - db::project::CreateProject, - controller::user::CreateUser, - entity::project::Model, - entity::user::Model, - )), - tags( - (name = "auth", description = "Authentication endpoints"), - (name = "users", description = "User management endpoints"), - (name = "projects", description = "Project management endpoints"), - (name = "groups", description = "Group management endpoints (Not Implemented)"), - (name = "classes", description = "Class management endpoints (Not Implemented)"), - (name = "templates", description = "Template management endpoints (Not Implemented)"), - ) -)] -struct ApiDoc; - #[actix_web::main] async fn main() -> std::io::Result<()> { dotenvy::dotenv().ok(); @@ -118,7 +62,7 @@ async fn main() -> std::io::Result<()> { .service(web::scope("/api/v1").configure(controller::register_controllers)) .service( SwaggerUi::new("/swagger-ui/{_:.*}") - .url("/api-docs/openapi.json", ApiDoc::openapi()), + .url("/api-docs/openapi.json", crate::utoipa::ApiDoc::openapi_spec()), ); #[cfg(feature = "serve")] diff --git a/crates/backend/src/utoipa.rs b/crates/backend/src/utoipa.rs new file mode 100644 index 0000000..6814dd4 --- /dev/null +++ b/crates/backend/src/utoipa.rs @@ -0,0 +1,64 @@ +use utoipa::OpenApi; + +use crate::{controller, db, entity, error}; + +#[derive(OpenApi)] +#[openapi( + info( + title = "PGG API", + description = "API for the PGG (Peer Group Grading) application", + version = "0.0.1-rc1", + ), + paths( + controller::auth::login, + controller::auth::logout, + controller::project::get_projects, + controller::project::get_project, + controller::project::create_project, + controller::project::update_project, + controller::project::delete_project, + controller::user::get_users, + controller::user::get_user, + controller::user::create_user, + controller::user::update_user, + controller::user::delete_user, + controller::group::get_groups, + controller::group::get_groups_for_project, + controller::group::create_group, + controller::group::update_group, + controller::group::delete_group, + controller::class::get_classes, + controller::class::get_class, + controller::class::create_class, + controller::class::update_class, + controller::class::delete_class, + controller::template::get_templates, + controller::template::get_template, + controller::template::create_template, + controller::template::update_template, + controller::template::delete_template, + ), + components(schemas( + controller::auth::LoginRequest, + error::MessageResponse, + db::project::CreateProject, + controller::user::CreateUser, + entity::project::Model, + entity::user::Model, + )), + tags( + (name = "auth", description = "Authentication endpoints"), + (name = "users", description = "User management endpoints"), + (name = "projects", description = "Project management endpoints"), + (name = "groups", description = "Group management endpoints (Not Implemented)"), + (name = "classes", description = "Class management endpoints (Not Implemented)"), + (name = "templates", description = "Template management endpoints (Not Implemented)"), + ) +)] +pub struct ApiDoc; + +impl ApiDoc { + pub fn openapi_spec() -> utoipa::openapi::OpenApi { + Self::openapi() + } +} \ No newline at end of file