This commit is contained in:
2023-08-09 03:32:08 +02:00
parent d702a0f95d
commit 9a03978553
3 changed files with 96 additions and 12 deletions

View File

@@ -4,6 +4,8 @@ use serde::de::DeserializeOwned;
use crate::config::CONFIG;
use self::types::{BaseBook, Page};
async fn _make_request<T>(
url: &str,
params: Vec<(&str, String)>,
@@ -53,16 +55,13 @@ pub async fn get_books(
page_size: u32,
uploaded_gte: String,
uploaded_lte: String,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let _params: Vec<(&str, String)> = vec![
) -> Result<Page<BaseBook>, Box<dyn std::error::Error + Send + Sync>> {
let params: Vec<(&str, String)> = vec![
("page", page.to_string()),
("page_size", page_size.to_string()),
("size", page_size.to_string()),
("uploaded_gte", uploaded_gte),
("uploaded_lte", uploaded_lte)
];
// TODO
// _make_request(format!("/api/v1/books/").as_str(), params).await;
Ok(())
_make_request(format!("/api/v1/books/base/").as_str(), params).await
}

View File

@@ -36,6 +36,12 @@ pub struct BookWithRemote {
pub authors: Vec<BookAuthor>,
}
#[derive(Deserialize, Debug, Clone)]
pub struct BaseBook {
pub id: i32,
pub available_types: Vec<String>
}
impl BookWithRemote {
pub fn from_book(book: Book, remote_id: u32) -> Self {
Self {
@@ -106,3 +112,15 @@ impl BookWithRemote {
format!("{caption_title}\n\n{caption_authors}")
}
}
#[derive(Deserialize, Debug, Clone)]
pub struct Page<T> {
pub items: Vec<T>,
pub total: u32,
pub page: u32,
pub size: u32,
pub pages: u32,
}