mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2026-03-03 15:10:51 +01:00
Add pre-commit config
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
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 AllowedLangs {
|
||||
#[serde(default = "default_langs")]
|
||||
pub allowed_langs: Vec<String>
|
||||
pub allowed_langs: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ use serde::Serialize;
|
||||
|
||||
use crate::prisma::{author, book};
|
||||
|
||||
use super::{sequence::Sequence, utils::{get_available_types, get_translators, get_sequences}};
|
||||
use super::{
|
||||
sequence::Sequence,
|
||||
utils::{get_available_types, get_sequences, get_translators},
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Author {
|
||||
@@ -34,7 +37,6 @@ impl From<author::Data> for Author {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct AuthorBook {
|
||||
pub id: i32,
|
||||
|
||||
@@ -7,18 +7,24 @@ pub struct AuthorAnnotation {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub text: String,
|
||||
pub file: Option<String>
|
||||
pub file: Option<String>,
|
||||
}
|
||||
|
||||
impl From<author_annotation::Data> for AuthorAnnotation {
|
||||
fn from(val: author_annotation::Data) -> Self {
|
||||
let author_annotation::Data { id, title, text, file, .. } = val;
|
||||
let author_annotation::Data {
|
||||
id,
|
||||
title,
|
||||
text,
|
||||
file,
|
||||
..
|
||||
} = val;
|
||||
|
||||
AuthorAnnotation {
|
||||
id,
|
||||
title,
|
||||
text,
|
||||
file
|
||||
file,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -2,13 +2,12 @@ use serde::Serialize;
|
||||
|
||||
use crate::prisma::book_annotation;
|
||||
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct BookAnnotation {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub text: String,
|
||||
pub file: Option<String>
|
||||
pub file: Option<String>,
|
||||
}
|
||||
|
||||
impl From<book_annotation::Data> for BookAnnotation {
|
||||
@@ -25,7 +24,7 @@ impl From<book_annotation::Data> for BookAnnotation {
|
||||
id,
|
||||
title,
|
||||
text,
|
||||
file
|
||||
file,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::prisma::genre;
|
||||
|
||||
@@ -11,7 +11,7 @@ pub struct Genre {
|
||||
pub remote_id: i32,
|
||||
pub code: String,
|
||||
pub description: String,
|
||||
pub meta: String
|
||||
pub meta: String,
|
||||
}
|
||||
|
||||
impl From<genre::Data> for Genre {
|
||||
@@ -32,12 +32,11 @@ impl From<genre::Data> for Genre {
|
||||
code,
|
||||
description,
|
||||
meta,
|
||||
source: source.unwrap().as_ref().clone().into()
|
||||
source: source.unwrap().as_ref().clone().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GenreFilter {
|
||||
pub meta: Option<String>,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
pub mod pagination;
|
||||
pub mod allowed_langs;
|
||||
pub mod author;
|
||||
pub mod author_annotation;
|
||||
pub mod genre;
|
||||
pub mod source;
|
||||
pub mod book;
|
||||
pub mod sequence;
|
||||
pub mod utils;
|
||||
pub mod translator;
|
||||
pub mod allowed_langs;
|
||||
pub mod book_annotation;
|
||||
pub mod genre;
|
||||
pub mod pagination;
|
||||
pub mod sequence;
|
||||
pub mod source;
|
||||
pub mod translator;
|
||||
pub mod utils;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
fn default_page() -> i64 {
|
||||
1
|
||||
}
|
||||
@@ -14,17 +13,16 @@ pub struct Pagination {
|
||||
#[serde(default = "default_page")]
|
||||
pub page: i64,
|
||||
#[serde(default = "default_size")]
|
||||
pub size: i64
|
||||
pub size: i64,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Page<T> {
|
||||
pub items: Vec<T>,
|
||||
pub total: i64,
|
||||
pub page: i64,
|
||||
pub size: i64,
|
||||
pub pages: i64
|
||||
pub pages: i64,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -34,7 +32,7 @@ pub struct PageWithParent<T, P> {
|
||||
pub page: i64,
|
||||
pub size: i64,
|
||||
pub pages: i64,
|
||||
pub parent_item: P
|
||||
pub parent_item: P,
|
||||
}
|
||||
|
||||
impl<T> Page<T> {
|
||||
@@ -44,7 +42,7 @@ impl<T> Page<T> {
|
||||
total,
|
||||
page: pagination.page,
|
||||
size: pagination.size,
|
||||
pages: (total + pagination.size - 1) / pagination.size
|
||||
pages: (total + pagination.size - 1) / pagination.size,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +55,7 @@ impl<T, P> PageWithParent<T, P> {
|
||||
page: pagination.page,
|
||||
size: pagination.size,
|
||||
pages: (total + pagination.size - 1) / pagination.size,
|
||||
parent_item
|
||||
parent_item,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::prisma::{sequence, book};
|
||||
|
||||
use super::{author::Author, utils::{get_available_types, get_authors, get_translators}};
|
||||
use crate::prisma::{book, sequence};
|
||||
|
||||
use super::{
|
||||
author::Author,
|
||||
utils::{get_authors, get_available_types, get_translators},
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Sequence {
|
||||
|
||||
@@ -5,21 +5,13 @@ use crate::prisma::source;
|
||||
#[derive(Serialize)]
|
||||
pub struct Source {
|
||||
pub id: i32,
|
||||
pub name: String
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl From<source::Data> for Source
|
||||
{
|
||||
impl From<source::Data> for Source {
|
||||
fn from(val: source::Data) -> Self {
|
||||
let source::Data {
|
||||
id,
|
||||
name,
|
||||
..
|
||||
} = val;
|
||||
let source::Data { id, name, .. } = val;
|
||||
|
||||
Source {
|
||||
id,
|
||||
name
|
||||
}
|
||||
Source { id, name }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,11 @@ use serde::Serialize;
|
||||
|
||||
use crate::prisma::book;
|
||||
|
||||
use super::{author::Author, sequence::Sequence, utils::{get_available_types, get_authors, get_sequences}};
|
||||
use super::{
|
||||
author::Author,
|
||||
sequence::Sequence,
|
||||
utils::{get_authors, get_available_types, get_sequences},
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct TranslatorBook {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::prisma::{translator, book_sequence, book_author, book_genre};
|
||||
use crate::prisma::{book_author, book_genre, book_sequence, translator};
|
||||
|
||||
use super::{author::Author, sequence::Sequence, genre::Genre};
|
||||
use super::{author::Author, genre::Genre, sequence::Sequence};
|
||||
|
||||
pub fn get_available_types(file_type: String, source_name: String) -> Vec<String> {
|
||||
if file_type == "fb2" && source_name == "flibusta" {
|
||||
@@ -15,9 +15,7 @@ pub fn get_available_types(file_type: String, source_name: String) -> Vec<String
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_authors(
|
||||
book_authors: Option<Vec<book_author::Data>>
|
||||
) -> Vec<Author> {
|
||||
pub fn get_authors(book_authors: Option<Vec<book_author::Data>>) -> Vec<Author> {
|
||||
book_authors
|
||||
.unwrap()
|
||||
.iter()
|
||||
@@ -25,9 +23,7 @@ pub fn get_authors(
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_translators(
|
||||
translations: Option<Vec<translator::Data>>
|
||||
) -> Vec<Author> {
|
||||
pub fn get_translators(translations: Option<Vec<translator::Data>>) -> Vec<Author> {
|
||||
translations
|
||||
.unwrap()
|
||||
.iter()
|
||||
@@ -35,9 +31,7 @@ pub fn get_translators(
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_sequences(
|
||||
book_sequences: Option<Vec<book_sequence::Data>>
|
||||
) -> Vec<Sequence> {
|
||||
pub fn get_sequences(book_sequences: Option<Vec<book_sequence::Data>>) -> Vec<Sequence> {
|
||||
book_sequences
|
||||
.unwrap()
|
||||
.iter()
|
||||
@@ -45,9 +39,7 @@ pub fn get_sequences(
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_genres(
|
||||
book_genres: Option<Vec<book_genre::Data>>
|
||||
) -> Vec<Genre> {
|
||||
pub fn get_genres(book_genres: Option<Vec<book_genre::Data>>) -> Vec<Genre> {
|
||||
book_genres
|
||||
.unwrap()
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user