feat: updated book instance search results
All checks were successful
/ test (push) Successful in 3m19s
All checks were successful
/ test (push) Successful in 3m19s
This commit is contained in:
parent
ff94003595
commit
b551f856df
1 changed files with 9 additions and 9 deletions
|
|
@ -390,9 +390,9 @@ pub struct BookInstanceSearchParams {
|
|||
}
|
||||
|
||||
#[derive(Serialize, utoipa::ToSchema)]
|
||||
pub struct BookInstanceSearchResults {
|
||||
book_instances: Vec<book_instance::Model>,
|
||||
books: HashMap<u32, book::Model>,
|
||||
pub struct BookInstanceWithBook {
|
||||
book_instance: book_instance::Model,
|
||||
book: book::Model
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
|
|
@ -403,7 +403,7 @@ pub struct BookInstanceSearchResults {
|
|||
request_body = BookInstanceSearchParams,
|
||||
security(("jwt" = [])),
|
||||
responses(
|
||||
(status = OK, body = BookInstanceSearchResults, description = "Found book instances in the database"),
|
||||
(status = OK, body = Vec<BookInstanceWithBook>, description = "Found book instances in the database"),
|
||||
(status = FORBIDDEN, description = "You do not own the specified bal"),
|
||||
),
|
||||
summary = "Search a BAL for books instances",
|
||||
|
|
@ -415,7 +415,7 @@ pub async fn search_bal_book_instances(
|
|||
claims: Claims,
|
||||
Path(bal_id): Path<u32>,
|
||||
Json(payload): Json<BookInstanceSearchParams>,
|
||||
) -> (StatusCode, Json<Option<BookInstanceSearchResults>>) {
|
||||
) -> (StatusCode, Json<Option<Vec<BookInstanceWithBook>>>) {
|
||||
if !user_is_bal_owner(claims.user_id, bal_id, state.db_conn.as_ref()).await {
|
||||
return (StatusCode::FORBIDDEN, Json(None));
|
||||
}
|
||||
|
|
@ -439,10 +439,10 @@ pub async fn search_bal_book_instances(
|
|||
book_id_map.insert(instance.book_id, Book::find_by_id(instance.book_id).one(state.db_conn.as_ref()).await.unwrap().unwrap());
|
||||
}
|
||||
}
|
||||
(StatusCode::OK, Json(Some(BookInstanceSearchResults {
|
||||
book_instances: res,
|
||||
books: book_id_map
|
||||
})))
|
||||
return (StatusCode::OK, Json(Some(res.iter().map(|i| BookInstanceWithBook {
|
||||
book: book_id_map.get(&i.book_id).unwrap().clone(),
|
||||
book_instance: i.clone()
|
||||
}).collect())))
|
||||
} else {
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(None))
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue