Comments help non-Rust users understand what each function, struct, and module does. Covers the core service (18 source files) and all four example projects (can-sync, canfs, filemanager, paste). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use axum::extract::{Query, State};
|
|
use axum::routing::get;
|
|
use axum::{Json, Router};
|
|
|
|
use crate::error::AppError;
|
|
use crate::models::{ApiResponse, AssetMeta, ListParams, ListResponse, Pagination};
|
|
use crate::{db, AppState};
|
|
|
|
pub fn router() -> Router<AppState> {
|
|
Router::new().route("/api/v1/can/0/list", get(list_assets))
|
|
}
|
|
|
|
/// GET /api/v1/can/0/list - Return a paginated list of assets with their metadata.
|
|
/// Supports query params: limit, offset, order (asc/desc), application filter.
|
|
async fn list_assets(
|
|
State(state): State<AppState>,
|
|
Query(params): Query<ListParams>,
|
|
) -> Result<Json<ApiResponse<ListResponse>>, AppError> {
|
|
let conn = state.db.lock().unwrap();
|
|
let (assets, total) = db::list_assets(&conn, ¶ms)?;
|
|
|
|
let items: Vec<AssetMeta> = assets
|
|
.iter()
|
|
.map(|a| db::asset_to_meta(&conn, a))
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
let response = ListResponse {
|
|
items,
|
|
pagination: Pagination {
|
|
limit: params.limit.unwrap_or(50),
|
|
offset: params.offset.unwrap_or(0),
|
|
total,
|
|
},
|
|
};
|
|
|
|
Ok(Json(ApiResponse::success(response)))
|
|
}
|