feat: book id use optional i64

This commit is contained in:
brian
2025-06-08 23:50:30 +08:00
parent 8273e610cb
commit 366862831c
2 changed files with 5 additions and 3 deletions

View File

@@ -46,7 +46,7 @@ async fn get_all_books_handler(
let mut books: Vec<BookItem> = Vec::new(); let mut books: Vec<BookItem> = Vec::new();
for b in all_books { for b in all_books {
let book_resp = BookItem { let book_resp = BookItem {
id: b.id, id: b.id.into(),
name: b.name, name: b.name,
}; };
books.push(book_resp); books.push(book_resp);
@@ -72,7 +72,7 @@ async fn get_book_by_id_handler(
match book_query { match book_query {
Some(b) => { Some(b) => {
book_resp = BookItem { book_resp = BookItem {
id: b.id, id: b.id.into(),
name: b.name, name: b.name,
}; };
} }

View File

@@ -1,8 +1,10 @@
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use super::common::{number_stringify, OptionalI64};
#[derive(Serialize)] #[derive(Serialize)]
pub struct BookItem { pub struct BookItem {
pub id: i64, #[serde(with="number_stringify")]
pub id: OptionalI64,
pub name: String, pub name: String,
} }