From 00b38c498966ee1b9c3edb67d920acd399095216 Mon Sep 17 00:00:00 2001 From: Ninjdai Date: Fri, 1 Aug 2025 13:01:28 +0200 Subject: [PATCH] feat: list owners endpoint (/owners) --- src/main.rs | 1 + src/routes/owner.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main.rs b/src/main.rs index 233ccf4..b6ba30b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,6 +75,7 @@ async fn main() { .routes(routes!(routes::book_instance::create_book_instance)) .routes(routes!(routes::owner::get_owner_by_id)) .routes(routes!(routes::owner::create_owner)) + .routes(routes!(routes::owner::get_owners)) .routes(routes!(routes::websocket::ws_handler)) .route("/", get(index)) .with_state(shared_state) diff --git a/src/routes/owner.rs b/src/routes/owner.rs index 85bee5f..abaf44f 100644 --- a/src/routes/owner.rs +++ b/src/routes/owner.rs @@ -82,3 +82,28 @@ pub async fn create_owner( } } } + +#[axum::debug_handler] +#[utoipa::path( + get, + path = "/owners", + responses( + (status = OK, body = Vec, description = "List of owners"), + ), + summary = "List book owners", + description = "List book owners", + tag = "owner-api", +)] +pub async fn get_owners( + State(state): State>, +) -> (StatusCode, Json>>) { + match Owner::find().all(state.db_conn.as_ref()).await { + Err(e) => { + log::error!(target: "api", "Error while getting owner list: {:#?}", e); + (StatusCode::INTERNAL_SERVER_ERROR, Json(None)) + } + Ok(owners) => { + (StatusCode::OK, Json(Some(owners))) + } + } +}