refactor: move API routes to api.rs and remove unused imports

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-12 14:50:14 -03:00
parent afdecb6c51
commit 4c82c55f58
2 changed files with 15 additions and 25 deletions

View File

@@ -20,10 +20,6 @@ mod api;
mod docs; mod docs;
pub use common::{ServerConfig, AppState, logging_middleware}; pub use common::{ServerConfig, AppState, logging_middleware};
use api::item::{handle_list_items, handle_get_item, handle_post_item, handle_delete_item};
use api::item::{handle_get_content_latest, handle_get_content, handle_get_content_latest_raw, handle_get_content_raw};
use api::status::handle_status;
use docs::{handle_openapi, handle_swagger_ui};
pub fn mode_server( pub fn mode_server(
_cmd: &mut Command, _cmd: &mut Command,
@@ -63,16 +59,7 @@ async fn run_server(
args: Arc::new(args.clone()), args: Arc::new(args.clone()),
}; };
let app = Router::new() let app = api::api_router()
.route("/status", get(handle_status))
.route("/item/", get(handle_list_items).put(handle_post_item))
.route("/item/:id", get(handle_get_item).delete(handle_delete_item))
.route("/content", get(handle_get_content_latest))
.route("/content/:id", get(handle_get_content))
.route("/content-raw", get(handle_get_content_latest_raw))
.route("/content-raw/:id", get(handle_get_content_raw))
.route("/openapi.json", get(handle_openapi))
.route("/swagger/", get(handle_swagger_ui))
.layer(axum::middleware::from_fn(logging_middleware)) .layer(axum::middleware::from_fn(logging_middleware))
.layer( .layer(
ServiceBuilder::new() ServiceBuilder::new()

View File

@@ -5,24 +5,27 @@ use axum::{
use crate::modes::server::common::AppState; use crate::modes::server::common::AppState;
use crate::modes::server::api::{ use crate::modes::server::api::{
item, status, docs item, status
}; };
use crate::modes::server::docs;
pub fn api_router() -> Router<AppState> { pub fn api_router() -> Router<AppState> {
Router::new() Router::new()
// Status endpoints // Status endpoints
.route("/api/status", get(status::handle_status)) .route("/status", get(status::handle_status))
// Item endpoints // Item endpoints
.route("/api/item/", get(item::handle_list_items).post(item::handle_post_item)) .route("/item/", get(item::handle_list_items).post(item::handle_post_item))
.route("/api/item/latest", get(item::handle_get_item_latest)) .route("/item/latest", get(item::handle_get_item_latest))
.route("/api/item/latest/meta", get(item::handle_get_item_latest_meta)) .route("/item/latest/meta", get(item::handle_get_item_latest_meta))
.route("/api/item/latest/content", get(item::handle_get_content_latest).get(item::handle_get_content_latest_raw)) .route("/content", get(item::handle_get_content_latest))
.route("/api/item/:id", get(item::handle_get_item).delete(item::handle_delete_item)) .route("/content/:id", get(item::handle_get_content))
.route("/api/item/:id/meta", get(item::handle_get_item_meta)) .route("/content-raw", get(item::handle_get_content_latest_raw))
.route("/api/item/:id/content", get(item::handle_get_content).get(item::handle_get_content_raw)) .route("/content-raw/:id", get(item::handle_get_content_raw))
.route("/item/:id", get(item::handle_get_item).delete(item::handle_delete_item))
.route("/item/:id/meta", get(item::handle_get_item_meta))
// Documentation endpoints // Documentation endpoints
.route("/api/openapi.json", get(docs::handle_openapi)) .route("/openapi.json", get(docs::handle_openapi))
.route("/api/docs", get(docs::handle_swagger_ui)) .route("/swagger/", get(docs::handle_swagger_ui))
} }