proper error handling

This commit is contained in:
Sebastian Hugentobler 2024-05-06 09:09:40 +02:00
parent 687c33829f
commit ac7b0e7e88
Signed by: shu
GPG key ID: BB32CF3CA052C2F0
15 changed files with 245 additions and 25 deletions

View file

@ -8,7 +8,7 @@ use super::{
#[derive(Debug, Serialize)]
pub struct Book {
pub id: i32,
pub id: u64,
pub title: String,
pub sort: String,
pub path: String,
@ -24,12 +24,12 @@ impl Book {
})
}
pub fn books(
pub fn multiple(
conn: &Connection,
limit: u64,
cursor: Option<&str>,
sort_order: SortOrder,
) -> Result<Vec<Book>, DataStoreError> {
) -> Result<Vec<Self>, DataStoreError> {
let pagination = Pagination::new("sort", cursor, limit, sort_order);
pagination.paginate(
conn,
@ -45,7 +45,7 @@ impl Book {
limit: u64,
cursor: Option<&str>,
sort_order: SortOrder,
) -> Result<Vec<Book>, DataStoreError> {
) -> Result<Vec<Self>, DataStoreError> {
let pagination = Pagination::new("books.sort", cursor, limit, sort_order);
pagination.paginate(
conn,
@ -57,7 +57,7 @@ impl Book {
)
}
pub fn recents(conn: &Connection, limit: u64) -> Result<Vec<Book>, DataStoreError> {
pub fn recents(conn: &Connection, limit: u64) -> Result<Vec<Self>, DataStoreError> {
let mut stmt = conn.prepare(
"SELECT id, title, sort, path FROM books ORDER BY timestamp DESC LIMIT (:limit)",
)?;
@ -66,7 +66,7 @@ impl Book {
Ok(iter.filter_map(Result::ok).collect())
}
pub fn scalar_book(conn: &Connection, id: u64) -> Result<Book, DataStoreError> {
pub fn scalar_book(conn: &Connection, id: u64) -> Result<Self, DataStoreError> {
let mut stmt = conn.prepare("SELECT id, title, sort, path FROM books WHERE id = (:id)")?;
let params = named_params! { ":id": id };
Ok(stmt.query_row(params, Self::from_row)?)