mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-06 15:15:36 +01:00
Add pre-commit config
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::prisma::book::{self};
|
||||
|
||||
use super::{source::Source, utils::{get_available_types, get_translators, get_sequences, get_authors, get_genres}, author::Author, sequence::Sequence, genre::Genre};
|
||||
|
||||
use super::{
|
||||
author::Author,
|
||||
genre::Genre,
|
||||
sequence::Sequence,
|
||||
source::Source,
|
||||
utils::{get_authors, get_available_types, get_genres, get_sequences, get_translators},
|
||||
};
|
||||
|
||||
fn default_langs() -> Vec<String> {
|
||||
vec![
|
||||
"ru".to_string(),
|
||||
"be".to_string(),
|
||||
"uk".to_string()
|
||||
]
|
||||
vec!["ru".to_string(), "be".to_string(), "uk".to_string()]
|
||||
}
|
||||
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct BookFilter {
|
||||
#[serde(default = "default_langs")]
|
||||
@@ -30,45 +30,39 @@ impl BookFilter {
|
||||
pub fn get_filter_vec(self) -> Vec<book::WhereParam> {
|
||||
let mut result = vec![];
|
||||
|
||||
result.push(
|
||||
book::lang::in_vec(self.allowed_langs)
|
||||
);
|
||||
result.push(book::lang::in_vec(self.allowed_langs));
|
||||
|
||||
match self.is_deleted {
|
||||
Some(v) => {
|
||||
result.push(
|
||||
book::is_deleted::equals(v)
|
||||
);
|
||||
},
|
||||
result.push(book::is_deleted::equals(v));
|
||||
}
|
||||
None => {
|
||||
result.push(
|
||||
book::is_deleted::equals(false)
|
||||
);
|
||||
},
|
||||
result.push(book::is_deleted::equals(false));
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(uploaded_gte) = self.uploaded_gte {
|
||||
result.push(
|
||||
book::uploaded::gte(NaiveDateTime::new(uploaded_gte, NaiveTime::default()).and_utc().into())
|
||||
);
|
||||
result.push(book::uploaded::gte(
|
||||
NaiveDateTime::new(uploaded_gte, NaiveTime::default())
|
||||
.and_utc()
|
||||
.into(),
|
||||
));
|
||||
};
|
||||
|
||||
if let Some(uploaded_lte) = self.uploaded_lte {
|
||||
result.push(
|
||||
book::uploaded::lte(NaiveDateTime::new(uploaded_lte, NaiveTime::default()).and_utc().into())
|
||||
);
|
||||
result.push(book::uploaded::lte(
|
||||
NaiveDateTime::new(uploaded_lte, NaiveTime::default())
|
||||
.and_utc()
|
||||
.into(),
|
||||
));
|
||||
};
|
||||
|
||||
if let Some(id_gte) = self.id_gte {
|
||||
result.push(
|
||||
book::id::gte(id_gte)
|
||||
);
|
||||
result.push(book::id::gte(id_gte));
|
||||
};
|
||||
|
||||
if let Some(id_lte) = self.id_lte {
|
||||
result.push(
|
||||
book::id::lte(id_lte)
|
||||
);
|
||||
result.push(book::id::lte(id_lte));
|
||||
};
|
||||
|
||||
result
|
||||
@@ -120,7 +114,7 @@ impl From<book::Data> for RemoteBook {
|
||||
sequences: get_sequences(book_sequences),
|
||||
annotation_exists: book_annotation.unwrap().is_some(),
|
||||
source: source.unwrap().as_ref().clone().into(),
|
||||
remote_id
|
||||
remote_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +157,7 @@ pub struct DetailBook {
|
||||
pub remote_id: i32,
|
||||
pub genres: Vec<Genre>,
|
||||
pub is_deleted: bool,
|
||||
pub pages: Option<i32>
|
||||
pub pages: Option<i32>,
|
||||
}
|
||||
|
||||
impl From<book::Data> for DetailBook {
|
||||
@@ -209,7 +203,7 @@ impl From<book::Data> for DetailBook {
|
||||
#[derive(Deserialize)]
|
||||
pub struct RandomBookFilter {
|
||||
pub allowed_langs: Vec<String>,
|
||||
pub genre: Option<i32>
|
||||
pub genre: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
||||
Reference in New Issue
Block a user