feat: list owners endpoint (/owners)
This commit is contained in:
parent
53c95f90fd
commit
00b38c4989
2 changed files with 26 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -82,3 +82,28 @@ pub async fn create_owner(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/owners",
|
||||
responses(
|
||||
(status = OK, body = Vec<owner::Model>, description = "List of owners"),
|
||||
),
|
||||
summary = "List book owners",
|
||||
description = "List book owners",
|
||||
tag = "owner-api",
|
||||
)]
|
||||
pub async fn get_owners(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> (StatusCode, Json<Option<Vec<owner::Model>>>) {
|
||||
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)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue