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:
7
.pre-commit-config.yaml
Normal file
7
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/doublify/pre-commit-rust
|
||||||
|
rev: v1.0
|
||||||
|
hooks:
|
||||||
|
- id: fmt
|
||||||
|
- id: cargo-check
|
||||||
|
- id: clippy
|
||||||
@@ -16,7 +16,7 @@ pub struct Config {
|
|||||||
pub meili_host: String,
|
pub meili_host: String,
|
||||||
pub meili_master_key: String,
|
pub meili_master_key: String,
|
||||||
|
|
||||||
pub sentry_dsn: String
|
pub sentry_dsn: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@@ -33,11 +33,9 @@ impl Config {
|
|||||||
meili_host: get_env("MEILI_HOST"),
|
meili_host: get_env("MEILI_HOST"),
|
||||||
meili_master_key: get_env("MEILI_MASTER_KEY"),
|
meili_master_key: get_env("MEILI_MASTER_KEY"),
|
||||||
|
|
||||||
sentry_dsn: get_env("SENTRY_DSN")
|
sentry_dsn: get_env("SENTRY_DSN"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static CONFIG: Lazy<Config> = Lazy::new(|| {
|
pub static CONFIG: Lazy<Config> = Lazy::new(Config::load);
|
||||||
Config::load()
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use crate::{prisma::PrismaClient, config::CONFIG};
|
use crate::{config::CONFIG, prisma::PrismaClient};
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_prisma_client() -> PrismaClient {
|
pub async fn get_prisma_client() -> PrismaClient {
|
||||||
let database_url: String = format!(
|
let database_url: String = format!(
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod views;
|
|
||||||
pub mod prisma;
|
|
||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod serializers;
|
|
||||||
pub mod meilisearch;
|
pub mod meilisearch;
|
||||||
|
pub mod prisma;
|
||||||
|
pub mod serializers;
|
||||||
|
pub mod views;
|
||||||
|
|
||||||
|
use sentry::{integrations::debug_images::DebugImagesIntegration, types::Dsn, ClientOptions};
|
||||||
use std::{net::SocketAddr, str::FromStr};
|
use std::{net::SocketAddr, str::FromStr};
|
||||||
use sentry::{ClientOptions, types::Dsn, integrations::debug_images::DebugImagesIntegration};
|
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use crate::views::get_router;
|
use crate::views::get_router;
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let options = ClientOptions {
|
let options = ClientOptions {
|
||||||
|
|||||||
@@ -3,12 +3,8 @@ use serde::Deserialize;
|
|||||||
|
|
||||||
use crate::config::CONFIG;
|
use crate::config::CONFIG;
|
||||||
|
|
||||||
|
|
||||||
pub fn get_meili_client() -> Client {
|
pub fn get_meili_client() -> Client {
|
||||||
Client::new(
|
Client::new(&CONFIG.meili_host, Some(CONFIG.meili_master_key.clone()))
|
||||||
&CONFIG.meili_host,
|
|
||||||
Some(CONFIG.meili_master_key.clone())
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GetId {
|
pub trait GetId {
|
||||||
@@ -23,7 +19,7 @@ pub struct AuthorMeili {
|
|||||||
pub middle_name: String,
|
pub middle_name: String,
|
||||||
pub author_langs: Vec<String>,
|
pub author_langs: Vec<String>,
|
||||||
pub translator_langs: Vec<String>,
|
pub translator_langs: Vec<String>,
|
||||||
pub books_count: i32
|
pub books_count: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetId for AuthorMeili {
|
impl GetId for AuthorMeili {
|
||||||
@@ -32,13 +28,12 @@ impl GetId for AuthorMeili {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct BookMeili {
|
pub struct BookMeili {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub lang: String,
|
pub lang: String,
|
||||||
pub genres: Vec<i32>
|
pub genres: Vec<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetId for BookMeili {
|
impl GetId for BookMeili {
|
||||||
@@ -47,14 +42,13 @@ impl GetId for BookMeili {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct GenreMeili {
|
pub struct GenreMeili {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub meta: String,
|
pub meta: String,
|
||||||
pub langs: Vec<String>,
|
pub langs: Vec<String>,
|
||||||
pub books_count: i32
|
pub books_count: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetId for GenreMeili {
|
impl GetId for GenreMeili {
|
||||||
@@ -63,13 +57,12 @@ impl GetId for GenreMeili {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct SequenceMeili {
|
pub struct SequenceMeili {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub langs: Vec<String>,
|
pub langs: Vec<String>,
|
||||||
pub books_count: i32
|
pub books_count: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetId for SequenceMeili {
|
impl GetId for SequenceMeili {
|
||||||
|
|||||||
321
src/prisma.rs
321
src/prisma.rs
@@ -1,7 +1,8 @@
|
|||||||
// Code generated by Prisma Client Rust. DO NOT EDIT
|
// Code generated by Prisma Client Rust. DO NOT EDIT
|
||||||
|
|
||||||
pub static DATAMODEL_STR: &str =
|
#![allow(clippy::all)]
|
||||||
include_str!("../prisma/schema.prisma");
|
|
||||||
|
pub static DATAMODEL_STR: &str = include_str!("../prisma/schema.prisma");
|
||||||
static DATABASE_STR: &str = "postgresql";
|
static DATABASE_STR: &str = "postgresql";
|
||||||
pub async fn new_client() -> Result<PrismaClient, ::prisma_client_rust::NewClientError> {
|
pub async fn new_client() -> Result<PrismaClient, ::prisma_client_rust::NewClientError> {
|
||||||
PrismaClient::_builder().build().await
|
PrismaClient::_builder().build().await
|
||||||
@@ -21,9 +22,7 @@ pub mod author_annotation {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -92,9 +91,7 @@ pub mod author_annotation {
|
|||||||
pub mod author_id {
|
pub mod author_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "author_id";
|
pub const NAME: &str = "author_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -167,9 +164,7 @@ pub mod author_annotation {
|
|||||||
pub mod title {
|
pub mod title {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "title";
|
pub const NAME: &str = "title";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -234,9 +229,7 @@ pub mod author_annotation {
|
|||||||
pub mod text {
|
pub mod text {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "text";
|
pub const NAME: &str = "text";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -297,9 +290,7 @@ pub mod author_annotation {
|
|||||||
pub mod file {
|
pub mod file {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "file";
|
pub const NAME: &str = "file";
|
||||||
pub struct Set(pub Option<String>);
|
pub struct Set(pub Option<String>);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -364,9 +355,7 @@ pub mod author_annotation {
|
|||||||
pub mod author {
|
pub mod author {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "author";
|
pub const NAME: &str = "author";
|
||||||
pub struct Fetch(pub author::UniqueArgs);
|
pub struct Fetch(pub author::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -1019,9 +1008,7 @@ pub mod author {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -1090,9 +1077,7 @@ pub mod author {
|
|||||||
pub mod source_id {
|
pub mod source_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "source_id";
|
pub const NAME: &str = "source_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -1165,9 +1150,7 @@ pub mod author {
|
|||||||
pub mod remote_id {
|
pub mod remote_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "remote_id";
|
pub const NAME: &str = "remote_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -1240,9 +1223,7 @@ pub mod author {
|
|||||||
pub mod first_name {
|
pub mod first_name {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "first_name";
|
pub const NAME: &str = "first_name";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -1307,9 +1288,7 @@ pub mod author {
|
|||||||
pub mod last_name {
|
pub mod last_name {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "last_name";
|
pub const NAME: &str = "last_name";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -1374,9 +1353,7 @@ pub mod author {
|
|||||||
pub mod middle_name {
|
pub mod middle_name {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "middle_name";
|
pub const NAME: &str = "middle_name";
|
||||||
pub struct Set(pub Option<String>);
|
pub struct Set(pub Option<String>);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -1441,9 +1418,7 @@ pub mod author {
|
|||||||
pub mod source {
|
pub mod source {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "source";
|
pub const NAME: &str = "source";
|
||||||
pub struct Fetch(pub source::UniqueArgs);
|
pub struct Fetch(pub source::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -1549,9 +1524,7 @@ pub mod author {
|
|||||||
pub mod author_annotation {
|
pub mod author_annotation {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "author_annotation";
|
pub const NAME: &str = "author_annotation";
|
||||||
pub struct Fetch(pub author_annotation::UniqueArgs);
|
pub struct Fetch(pub author_annotation::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -1637,9 +1610,7 @@ pub mod author {
|
|||||||
pub mod book_authors {
|
pub mod book_authors {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_authors";
|
pub const NAME: &str = "book_authors";
|
||||||
pub struct Fetch(pub book_author::ManyArgs);
|
pub struct Fetch(pub book_author::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -1786,9 +1757,7 @@ pub mod author {
|
|||||||
pub mod translations {
|
pub mod translations {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "translations";
|
pub const NAME: &str = "translations";
|
||||||
pub struct Fetch(pub translator::ManyArgs);
|
pub struct Fetch(pub translator::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -2903,9 +2872,7 @@ pub mod book_annotation {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -2974,9 +2941,7 @@ pub mod book_annotation {
|
|||||||
pub mod book_id {
|
pub mod book_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_id";
|
pub const NAME: &str = "book_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -3045,9 +3010,7 @@ pub mod book_annotation {
|
|||||||
pub mod title {
|
pub mod title {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "title";
|
pub const NAME: &str = "title";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -3112,9 +3075,7 @@ pub mod book_annotation {
|
|||||||
pub mod text {
|
pub mod text {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "text";
|
pub const NAME: &str = "text";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -3175,9 +3136,7 @@ pub mod book_annotation {
|
|||||||
pub mod file {
|
pub mod file {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "file";
|
pub const NAME: &str = "file";
|
||||||
pub struct Set(pub Option<String>);
|
pub struct Set(pub Option<String>);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -3242,9 +3201,7 @@ pub mod book_annotation {
|
|||||||
pub mod book {
|
pub mod book {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book";
|
pub const NAME: &str = "book";
|
||||||
pub struct Fetch(pub book::UniqueArgs);
|
pub struct Fetch(pub book::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -3885,9 +3842,7 @@ pub mod book_author {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -3956,9 +3911,7 @@ pub mod book_author {
|
|||||||
pub mod author_id {
|
pub mod author_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "author_id";
|
pub const NAME: &str = "author_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -4031,9 +3984,7 @@ pub mod book_author {
|
|||||||
pub mod book_id {
|
pub mod book_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_id";
|
pub const NAME: &str = "book_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -4102,9 +4053,7 @@ pub mod book_author {
|
|||||||
pub mod author {
|
pub mod author {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "author";
|
pub const NAME: &str = "author";
|
||||||
pub struct Fetch(pub author::UniqueArgs);
|
pub struct Fetch(pub author::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -4210,9 +4159,7 @@ pub mod book_author {
|
|||||||
pub mod book {
|
pub mod book {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book";
|
pub const NAME: &str = "book";
|
||||||
pub struct Fetch(pub book::UniqueArgs);
|
pub struct Fetch(pub book::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -4923,9 +4870,7 @@ pub mod book_genre {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -4994,9 +4939,7 @@ pub mod book_genre {
|
|||||||
pub mod genre_id {
|
pub mod genre_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "genre_id";
|
pub const NAME: &str = "genre_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -5065,9 +5008,7 @@ pub mod book_genre {
|
|||||||
pub mod book_id {
|
pub mod book_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_id";
|
pub const NAME: &str = "book_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -5136,9 +5077,7 @@ pub mod book_genre {
|
|||||||
pub mod book {
|
pub mod book {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book";
|
pub const NAME: &str = "book";
|
||||||
pub struct Fetch(pub book::UniqueArgs);
|
pub struct Fetch(pub book::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -5243,9 +5182,7 @@ pub mod book_genre {
|
|||||||
pub mod genre {
|
pub mod genre {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "genre";
|
pub const NAME: &str = "genre";
|
||||||
pub struct Fetch(pub genre::UniqueArgs);
|
pub struct Fetch(pub genre::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -5956,9 +5893,7 @@ pub mod book_sequence {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -6027,9 +5962,7 @@ pub mod book_sequence {
|
|||||||
pub mod position {
|
pub mod position {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "position";
|
pub const NAME: &str = "position";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -6102,9 +6035,7 @@ pub mod book_sequence {
|
|||||||
pub mod sequence_id {
|
pub mod sequence_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "sequence_id";
|
pub const NAME: &str = "sequence_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -6177,9 +6108,7 @@ pub mod book_sequence {
|
|||||||
pub mod book_id {
|
pub mod book_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_id";
|
pub const NAME: &str = "book_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -6248,9 +6177,7 @@ pub mod book_sequence {
|
|||||||
pub mod book {
|
pub mod book {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book";
|
pub const NAME: &str = "book";
|
||||||
pub struct Fetch(pub book::UniqueArgs);
|
pub struct Fetch(pub book::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -6355,9 +6282,7 @@ pub mod book_sequence {
|
|||||||
pub mod sequence {
|
pub mod sequence {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "sequence";
|
pub const NAME: &str = "sequence";
|
||||||
pub struct Fetch(pub sequence::UniqueArgs);
|
pub struct Fetch(pub sequence::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -7142,9 +7067,7 @@ pub mod book {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -7213,9 +7136,7 @@ pub mod book {
|
|||||||
pub mod source_id {
|
pub mod source_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "source_id";
|
pub const NAME: &str = "source_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -7288,9 +7209,7 @@ pub mod book {
|
|||||||
pub mod remote_id {
|
pub mod remote_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "remote_id";
|
pub const NAME: &str = "remote_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -7363,9 +7282,7 @@ pub mod book {
|
|||||||
pub mod title {
|
pub mod title {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "title";
|
pub const NAME: &str = "title";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -7430,9 +7347,7 @@ pub mod book {
|
|||||||
pub mod lang {
|
pub mod lang {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "lang";
|
pub const NAME: &str = "lang";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -7493,9 +7408,7 @@ pub mod book {
|
|||||||
pub mod file_type {
|
pub mod file_type {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "file_type";
|
pub const NAME: &str = "file_type";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -7560,9 +7473,7 @@ pub mod book {
|
|||||||
pub mod uploaded {
|
pub mod uploaded {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "uploaded";
|
pub const NAME: &str = "uploaded";
|
||||||
pub struct Set(
|
pub struct Set(
|
||||||
pub ::prisma_client_rust::chrono::DateTime<::prisma_client_rust::chrono::FixedOffset>,
|
pub ::prisma_client_rust::chrono::DateTime<::prisma_client_rust::chrono::FixedOffset>,
|
||||||
@@ -7665,9 +7576,7 @@ pub mod book {
|
|||||||
pub mod is_deleted {
|
pub mod is_deleted {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "is_deleted";
|
pub const NAME: &str = "is_deleted";
|
||||||
pub struct Set(pub bool);
|
pub struct Set(pub bool);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -7722,9 +7631,7 @@ pub mod book {
|
|||||||
pub mod pages {
|
pub mod pages {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "pages";
|
pub const NAME: &str = "pages";
|
||||||
pub struct Set(pub Option<i32>);
|
pub struct Set(pub Option<i32>);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -7797,9 +7704,7 @@ pub mod book {
|
|||||||
pub mod source {
|
pub mod source {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "source";
|
pub const NAME: &str = "source";
|
||||||
pub struct Fetch(pub source::UniqueArgs);
|
pub struct Fetch(pub source::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -7905,9 +7810,7 @@ pub mod book {
|
|||||||
pub mod book_annotation {
|
pub mod book_annotation {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_annotation";
|
pub const NAME: &str = "book_annotation";
|
||||||
pub struct Fetch(pub book_annotation::UniqueArgs);
|
pub struct Fetch(pub book_annotation::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -7993,9 +7896,7 @@ pub mod book {
|
|||||||
pub mod book_authors {
|
pub mod book_authors {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_authors";
|
pub const NAME: &str = "book_authors";
|
||||||
pub struct Fetch(pub book_author::ManyArgs);
|
pub struct Fetch(pub book_author::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -8142,9 +8043,7 @@ pub mod book {
|
|||||||
pub mod book_genres {
|
pub mod book_genres {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_genres";
|
pub const NAME: &str = "book_genres";
|
||||||
pub struct Fetch(pub book_genre::ManyArgs);
|
pub struct Fetch(pub book_genre::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -8291,9 +8190,7 @@ pub mod book {
|
|||||||
pub mod book_sequences {
|
pub mod book_sequences {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_sequences";
|
pub const NAME: &str = "book_sequences";
|
||||||
pub struct Fetch(pub book_sequence::ManyArgs);
|
pub struct Fetch(pub book_sequence::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -8410,9 +8307,7 @@ pub mod book {
|
|||||||
pub mod translations {
|
pub mod translations {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "translations";
|
pub const NAME: &str = "translations";
|
||||||
pub struct Fetch(pub translator::ManyArgs);
|
pub struct Fetch(pub translator::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -9901,9 +9796,7 @@ pub mod genre {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -9972,9 +9865,7 @@ pub mod genre {
|
|||||||
pub mod source_id {
|
pub mod source_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "source_id";
|
pub const NAME: &str = "source_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -10047,9 +9938,7 @@ pub mod genre {
|
|||||||
pub mod remote_id {
|
pub mod remote_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "remote_id";
|
pub const NAME: &str = "remote_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -10122,9 +10011,7 @@ pub mod genre {
|
|||||||
pub mod code {
|
pub mod code {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "code";
|
pub const NAME: &str = "code";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -10185,9 +10072,7 @@ pub mod genre {
|
|||||||
pub mod description {
|
pub mod description {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "description";
|
pub const NAME: &str = "description";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -10252,9 +10137,7 @@ pub mod genre {
|
|||||||
pub mod meta {
|
pub mod meta {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "meta";
|
pub const NAME: &str = "meta";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -10315,9 +10198,7 @@ pub mod genre {
|
|||||||
pub mod source {
|
pub mod source {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "source";
|
pub const NAME: &str = "source";
|
||||||
pub struct Fetch(pub source::UniqueArgs);
|
pub struct Fetch(pub source::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -10423,9 +10304,7 @@ pub mod genre {
|
|||||||
pub mod book_genres {
|
pub mod book_genres {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_genres";
|
pub const NAME: &str = "book_genres";
|
||||||
pub struct Fetch(pub book_genre::ManyArgs);
|
pub struct Fetch(pub book_genre::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -11334,9 +11213,7 @@ pub mod sequence {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -11405,9 +11282,7 @@ pub mod sequence {
|
|||||||
pub mod source_id {
|
pub mod source_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "source_id";
|
pub const NAME: &str = "source_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -11480,9 +11355,7 @@ pub mod sequence {
|
|||||||
pub mod remote_id {
|
pub mod remote_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "remote_id";
|
pub const NAME: &str = "remote_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -11555,9 +11428,7 @@ pub mod sequence {
|
|||||||
pub mod name {
|
pub mod name {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "name";
|
pub const NAME: &str = "name";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -11618,9 +11489,7 @@ pub mod sequence {
|
|||||||
pub mod source {
|
pub mod source {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "source";
|
pub const NAME: &str = "source";
|
||||||
pub struct Fetch(pub source::UniqueArgs);
|
pub struct Fetch(pub source::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -11726,9 +11595,7 @@ pub mod sequence {
|
|||||||
pub mod book_sequences {
|
pub mod book_sequences {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_sequences";
|
pub const NAME: &str = "book_sequences";
|
||||||
pub struct Fetch(pub book_sequence::ManyArgs);
|
pub struct Fetch(pub book_sequence::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -12535,9 +12402,7 @@ pub mod source {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -12606,9 +12471,7 @@ pub mod source {
|
|||||||
pub mod name {
|
pub mod name {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "name";
|
pub const NAME: &str = "name";
|
||||||
pub struct Set(pub String);
|
pub struct Set(pub String);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -12669,9 +12532,7 @@ pub mod source {
|
|||||||
pub mod authors {
|
pub mod authors {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "authors";
|
pub const NAME: &str = "authors";
|
||||||
pub struct Fetch(pub author::ManyArgs);
|
pub struct Fetch(pub author::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -12818,9 +12679,7 @@ pub mod source {
|
|||||||
pub mod books {
|
pub mod books {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "books";
|
pub const NAME: &str = "books";
|
||||||
pub struct Fetch(pub book::ManyArgs);
|
pub struct Fetch(pub book::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -12960,9 +12819,7 @@ pub mod source {
|
|||||||
pub mod genres {
|
pub mod genres {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "genres";
|
pub const NAME: &str = "genres";
|
||||||
pub struct Fetch(pub genre::ManyArgs);
|
pub struct Fetch(pub genre::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -13108,9 +12965,7 @@ pub mod source {
|
|||||||
pub mod sequences {
|
pub mod sequences {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "sequences";
|
pub const NAME: &str = "sequences";
|
||||||
pub struct Fetch(pub sequence::ManyArgs);
|
pub struct Fetch(pub sequence::ManyArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -14068,9 +13923,7 @@ pub mod translator {
|
|||||||
pub mod id {
|
pub mod id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, UniqueWhereParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "id";
|
pub const NAME: &str = "id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -14139,9 +13992,7 @@ pub mod translator {
|
|||||||
pub mod position {
|
pub mod position {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "position";
|
pub const NAME: &str = "position";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -14214,9 +14065,7 @@ pub mod translator {
|
|||||||
pub mod author_id {
|
pub mod author_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "author_id";
|
pub const NAME: &str = "author_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -14289,9 +14138,7 @@ pub mod translator {
|
|||||||
pub mod book_id {
|
pub mod book_id {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{OrderByParam, SetParam, UncheckedSetParam, WhereParam};
|
||||||
OrderByParam, SetParam, UncheckedSetParam, WhereParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book_id";
|
pub const NAME: &str = "book_id";
|
||||||
pub struct Set(pub i32);
|
pub struct Set(pub i32);
|
||||||
impl From<Set> for SetParam {
|
impl From<Set> for SetParam {
|
||||||
@@ -14360,9 +14207,7 @@ pub mod translator {
|
|||||||
pub mod author {
|
pub mod author {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "author";
|
pub const NAME: &str = "author";
|
||||||
pub struct Fetch(pub author::UniqueArgs);
|
pub struct Fetch(pub author::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
@@ -14468,9 +14313,7 @@ pub mod translator {
|
|||||||
pub mod book {
|
pub mod book {
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
use super::{
|
use super::{SetParam, WhereParam, WithParam};
|
||||||
SetParam, WhereParam, WithParam,
|
|
||||||
};
|
|
||||||
pub const NAME: &str = "book";
|
pub const NAME: &str = "book";
|
||||||
pub struct Fetch(pub book::UniqueArgs);
|
pub struct Fetch(pub book::UniqueArgs);
|
||||||
impl Fetch {
|
impl Fetch {
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
fn default_langs() -> Vec<String> {
|
fn default_langs() -> Vec<String> {
|
||||||
vec![
|
vec!["ru".to_string(), "be".to_string(), "uk".to_string()]
|
||||||
"ru".to_string(),
|
|
||||||
"be".to_string(),
|
|
||||||
"uk".to_string()
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct AllowedLangs {
|
pub struct AllowedLangs {
|
||||||
#[serde(default = "default_langs")]
|
#[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 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)]
|
#[derive(Serialize)]
|
||||||
pub struct Author {
|
pub struct Author {
|
||||||
@@ -34,7 +37,6 @@ impl From<author::Data> for Author {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct AuthorBook {
|
pub struct AuthorBook {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
|
|||||||
@@ -7,18 +7,24 @@ pub struct AuthorAnnotation {
|
|||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub file: Option<String>
|
pub file: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<author_annotation::Data> for AuthorAnnotation {
|
impl From<author_annotation::Data> for AuthorAnnotation {
|
||||||
fn from(val: author_annotation::Data) -> Self {
|
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 {
|
AuthorAnnotation {
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
text,
|
text,
|
||||||
file
|
file,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
|
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::prisma::book::{self};
|
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> {
|
fn default_langs() -> Vec<String> {
|
||||||
vec![
|
vec!["ru".to_string(), "be".to_string(), "uk".to_string()]
|
||||||
"ru".to_string(),
|
|
||||||
"be".to_string(),
|
|
||||||
"uk".to_string()
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct BookFilter {
|
pub struct BookFilter {
|
||||||
#[serde(default = "default_langs")]
|
#[serde(default = "default_langs")]
|
||||||
@@ -30,45 +30,39 @@ impl BookFilter {
|
|||||||
pub fn get_filter_vec(self) -> Vec<book::WhereParam> {
|
pub fn get_filter_vec(self) -> Vec<book::WhereParam> {
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
|
|
||||||
result.push(
|
result.push(book::lang::in_vec(self.allowed_langs));
|
||||||
book::lang::in_vec(self.allowed_langs)
|
|
||||||
);
|
|
||||||
|
|
||||||
match self.is_deleted {
|
match self.is_deleted {
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
result.push(
|
result.push(book::is_deleted::equals(v));
|
||||||
book::is_deleted::equals(v)
|
}
|
||||||
);
|
|
||||||
},
|
|
||||||
None => {
|
None => {
|
||||||
result.push(
|
result.push(book::is_deleted::equals(false));
|
||||||
book::is_deleted::equals(false)
|
}
|
||||||
);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(uploaded_gte) = self.uploaded_gte {
|
if let Some(uploaded_gte) = self.uploaded_gte {
|
||||||
result.push(
|
result.push(book::uploaded::gte(
|
||||||
book::uploaded::gte(NaiveDateTime::new(uploaded_gte, NaiveTime::default()).and_utc().into())
|
NaiveDateTime::new(uploaded_gte, NaiveTime::default())
|
||||||
);
|
.and_utc()
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(uploaded_lte) = self.uploaded_lte {
|
if let Some(uploaded_lte) = self.uploaded_lte {
|
||||||
result.push(
|
result.push(book::uploaded::lte(
|
||||||
book::uploaded::lte(NaiveDateTime::new(uploaded_lte, NaiveTime::default()).and_utc().into())
|
NaiveDateTime::new(uploaded_lte, NaiveTime::default())
|
||||||
);
|
.and_utc()
|
||||||
|
.into(),
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(id_gte) = self.id_gte {
|
if let Some(id_gte) = self.id_gte {
|
||||||
result.push(
|
result.push(book::id::gte(id_gte));
|
||||||
book::id::gte(id_gte)
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(id_lte) = self.id_lte {
|
if let Some(id_lte) = self.id_lte {
|
||||||
result.push(
|
result.push(book::id::lte(id_lte));
|
||||||
book::id::lte(id_lte)
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
result
|
result
|
||||||
@@ -120,7 +114,7 @@ impl From<book::Data> for RemoteBook {
|
|||||||
sequences: get_sequences(book_sequences),
|
sequences: get_sequences(book_sequences),
|
||||||
annotation_exists: book_annotation.unwrap().is_some(),
|
annotation_exists: book_annotation.unwrap().is_some(),
|
||||||
source: source.unwrap().as_ref().clone().into(),
|
source: source.unwrap().as_ref().clone().into(),
|
||||||
remote_id
|
remote_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +157,7 @@ pub struct DetailBook {
|
|||||||
pub remote_id: i32,
|
pub remote_id: i32,
|
||||||
pub genres: Vec<Genre>,
|
pub genres: Vec<Genre>,
|
||||||
pub is_deleted: bool,
|
pub is_deleted: bool,
|
||||||
pub pages: Option<i32>
|
pub pages: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<book::Data> for DetailBook {
|
impl From<book::Data> for DetailBook {
|
||||||
@@ -209,7 +203,7 @@ impl From<book::Data> for DetailBook {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct RandomBookFilter {
|
pub struct RandomBookFilter {
|
||||||
pub allowed_langs: Vec<String>,
|
pub allowed_langs: Vec<String>,
|
||||||
pub genre: Option<i32>
|
pub genre: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ use serde::Serialize;
|
|||||||
|
|
||||||
use crate::prisma::book_annotation;
|
use crate::prisma::book_annotation;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct BookAnnotation {
|
pub struct BookAnnotation {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub file: Option<String>
|
pub file: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<book_annotation::Data> for BookAnnotation {
|
impl From<book_annotation::Data> for BookAnnotation {
|
||||||
@@ -25,7 +24,7 @@ impl From<book_annotation::Data> for BookAnnotation {
|
|||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
text,
|
text,
|
||||||
file
|
file,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::prisma::genre;
|
use crate::prisma::genre;
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ pub struct Genre {
|
|||||||
pub remote_id: i32,
|
pub remote_id: i32,
|
||||||
pub code: String,
|
pub code: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub meta: String
|
pub meta: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<genre::Data> for Genre {
|
impl From<genre::Data> for Genre {
|
||||||
@@ -32,12 +32,11 @@ impl From<genre::Data> for Genre {
|
|||||||
code,
|
code,
|
||||||
description,
|
description,
|
||||||
meta,
|
meta,
|
||||||
source: source.unwrap().as_ref().clone().into()
|
source: source.unwrap().as_ref().clone().into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct GenreFilter {
|
pub struct GenreFilter {
|
||||||
pub meta: Option<String>,
|
pub meta: Option<String>,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
pub mod pagination;
|
pub mod allowed_langs;
|
||||||
pub mod author;
|
pub mod author;
|
||||||
pub mod author_annotation;
|
pub mod author_annotation;
|
||||||
pub mod genre;
|
|
||||||
pub mod source;
|
|
||||||
pub mod book;
|
pub mod book;
|
||||||
pub mod sequence;
|
|
||||||
pub mod utils;
|
|
||||||
pub mod translator;
|
|
||||||
pub mod allowed_langs;
|
|
||||||
pub mod book_annotation;
|
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};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
||||||
fn default_page() -> i64 {
|
fn default_page() -> i64 {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
@@ -14,17 +13,16 @@ pub struct Pagination {
|
|||||||
#[serde(default = "default_page")]
|
#[serde(default = "default_page")]
|
||||||
pub page: i64,
|
pub page: i64,
|
||||||
#[serde(default = "default_size")]
|
#[serde(default = "default_size")]
|
||||||
pub size: i64
|
pub size: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Page<T> {
|
pub struct Page<T> {
|
||||||
pub items: Vec<T>,
|
pub items: Vec<T>,
|
||||||
pub total: i64,
|
pub total: i64,
|
||||||
pub page: i64,
|
pub page: i64,
|
||||||
pub size: i64,
|
pub size: i64,
|
||||||
pub pages: i64
|
pub pages: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@@ -34,7 +32,7 @@ pub struct PageWithParent<T, P> {
|
|||||||
pub page: i64,
|
pub page: i64,
|
||||||
pub size: i64,
|
pub size: i64,
|
||||||
pub pages: i64,
|
pub pages: i64,
|
||||||
pub parent_item: P
|
pub parent_item: P,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Page<T> {
|
impl<T> Page<T> {
|
||||||
@@ -44,7 +42,7 @@ impl<T> Page<T> {
|
|||||||
total,
|
total,
|
||||||
page: pagination.page,
|
page: pagination.page,
|
||||||
size: pagination.size,
|
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,
|
page: pagination.page,
|
||||||
size: pagination.size,
|
size: pagination.size,
|
||||||
pages: (total + pagination.size - 1) / pagination.size,
|
pages: (total + pagination.size - 1) / pagination.size,
|
||||||
parent_item
|
parent_item,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::prisma::{sequence, book};
|
use crate::prisma::{book, sequence};
|
||||||
|
|
||||||
use super::{author::Author, utils::{get_available_types, get_authors, get_translators}};
|
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
author::Author,
|
||||||
|
utils::{get_authors, get_available_types, get_translators},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Sequence {
|
pub struct Sequence {
|
||||||
|
|||||||
@@ -5,21 +5,13 @@ use crate::prisma::source;
|
|||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Source {
|
pub struct Source {
|
||||||
pub id: i32,
|
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 {
|
fn from(val: source::Data) -> Self {
|
||||||
let source::Data {
|
let source::Data { id, name, .. } = val;
|
||||||
id,
|
|
||||||
name,
|
|
||||||
..
|
|
||||||
} = val;
|
|
||||||
|
|
||||||
Source {
|
Source { id, name }
|
||||||
id,
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,11 @@ use serde::Serialize;
|
|||||||
|
|
||||||
use crate::prisma::book;
|
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)]
|
#[derive(Serialize)]
|
||||||
pub struct TranslatorBook {
|
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> {
|
pub fn get_available_types(file_type: String, source_name: String) -> Vec<String> {
|
||||||
if file_type == "fb2" && source_name == "flibusta" {
|
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(
|
pub fn get_authors(book_authors: Option<Vec<book_author::Data>>) -> Vec<Author> {
|
||||||
book_authors: Option<Vec<book_author::Data>>
|
|
||||||
) -> Vec<Author> {
|
|
||||||
book_authors
|
book_authors
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
@@ -25,9 +23,7 @@ pub fn get_authors(
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_translators(
|
pub fn get_translators(translations: Option<Vec<translator::Data>>) -> Vec<Author> {
|
||||||
translations: Option<Vec<translator::Data>>
|
|
||||||
) -> Vec<Author> {
|
|
||||||
translations
|
translations
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
@@ -35,9 +31,7 @@ pub fn get_translators(
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_sequences(
|
pub fn get_sequences(book_sequences: Option<Vec<book_sequence::Data>>) -> Vec<Sequence> {
|
||||||
book_sequences: Option<Vec<book_sequence::Data>>
|
|
||||||
) -> Vec<Sequence> {
|
|
||||||
book_sequences
|
book_sequences
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
@@ -45,9 +39,7 @@ pub fn get_sequences(
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_genres(
|
pub fn get_genres(book_genres: Option<Vec<book_genre::Data>>) -> Vec<Genre> {
|
||||||
book_genres: Option<Vec<book_genre::Data>>
|
|
||||||
) -> Vec<Genre> {
|
|
||||||
book_genres
|
book_genres
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -1,29 +1,37 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use axum::{Router, extract::{Query, Path}, Json, response::IntoResponse, routing::get, http::StatusCode};
|
use axum::{
|
||||||
|
extract::{Path, Query},
|
||||||
|
http::StatusCode,
|
||||||
|
response::IntoResponse,
|
||||||
|
routing::get,
|
||||||
|
Json, Router,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{prisma::{author, author_annotation::{self}, book, book_author, translator, book_sequence}, serializers::{pagination::{Pagination, Page, PageWithParent}, author::{Author, AuthorBook}, author_annotation::AuthorAnnotation, allowed_langs::AllowedLangs}, meilisearch::{get_meili_client, AuthorMeili}};
|
use crate::{
|
||||||
|
meilisearch::{get_meili_client, AuthorMeili},
|
||||||
|
prisma::{
|
||||||
|
author,
|
||||||
|
author_annotation::{self},
|
||||||
|
book, book_author, book_sequence, translator,
|
||||||
|
},
|
||||||
|
serializers::{
|
||||||
|
allowed_langs::AllowedLangs,
|
||||||
|
author::{Author, AuthorBook},
|
||||||
|
author_annotation::AuthorAnnotation,
|
||||||
|
pagination::{Page, PageWithParent, Pagination},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
use super::{Database, common::get_random_item::get_random_item};
|
use super::{common::get_random_item::get_random_item, Database};
|
||||||
|
|
||||||
|
async fn get_authors(db: Database, pagination: Query<Pagination>) -> impl IntoResponse {
|
||||||
async fn get_authors(
|
let authors_count = db.author().count(vec![]).exec().await.unwrap();
|
||||||
db: Database,
|
|
||||||
pagination: Query<Pagination>
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let authors_count = db
|
|
||||||
.author()
|
|
||||||
.count(vec![])
|
|
||||||
.exec()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let authors = db
|
let authors = db
|
||||||
.author()
|
.author()
|
||||||
.find_many(vec![])
|
.find_many(vec![])
|
||||||
.with(
|
.with(author::author_annotation::fetch())
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
.order_by(author::id::order(prisma_client_rust::Direction::Asc))
|
.order_by(author::id::order(prisma_client_rust::Direction::Asc))
|
||||||
.skip((pagination.page - 1) * pagination.size)
|
.skip((pagination.page - 1) * pagination.size)
|
||||||
.take(pagination.size)
|
.take(pagination.size)
|
||||||
@@ -34,41 +42,32 @@ async fn get_authors(
|
|||||||
let page: Page<Author> = Page::new(
|
let page: Page<Author> = Page::new(
|
||||||
authors.iter().map(|item| item.clone().into()).collect(),
|
authors.iter().map(|item| item.clone().into()).collect(),
|
||||||
authors_count,
|
authors_count,
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page)
|
Json(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn get_random_author(
|
async fn get_random_author(
|
||||||
db: Database,
|
db: Database,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
|
AllowedLangs,
|
||||||
|
>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let author_id = {
|
let author_id = {
|
||||||
let client = get_meili_client();
|
let client = get_meili_client();
|
||||||
|
|
||||||
let authors_index = client.index("authors");
|
let authors_index = client.index("authors");
|
||||||
|
|
||||||
let filter = format!(
|
let filter = format!("author_langs IN [{}]", allowed_langs.join(", "));
|
||||||
"author_langs IN [{}]",
|
|
||||||
allowed_langs.join(", ")
|
|
||||||
);
|
|
||||||
|
|
||||||
get_random_item::<AuthorMeili>(
|
get_random_item::<AuthorMeili>(authors_index, filter).await
|
||||||
authors_index,
|
|
||||||
filter
|
|
||||||
).await
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let author = db
|
let author = db
|
||||||
.author()
|
.author()
|
||||||
.find_unique(
|
.find_unique(author::id::equals(author_id))
|
||||||
author::id::equals(author_id)
|
.with(author::author_annotation::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -77,19 +76,11 @@ async fn get_random_author(
|
|||||||
Json::<Author>(author.into())
|
Json::<Author>(author.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_author(db: Database, Path(author_id): Path<i32>) -> impl IntoResponse {
|
||||||
async fn get_author(
|
|
||||||
db: Database,
|
|
||||||
Path(author_id): Path<i32>
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let author = db
|
let author = db
|
||||||
.author()
|
.author()
|
||||||
.find_unique(
|
.find_unique(author::id::equals(author_id))
|
||||||
author::id::equals(author_id)
|
.with(author::author_annotation::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -100,16 +91,10 @@ async fn get_author(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_author_annotation(db: Database, Path(author_id): Path<i32>) -> impl IntoResponse {
|
||||||
async fn get_author_annotation(
|
|
||||||
db: Database,
|
|
||||||
Path(author_id): Path<i32>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let author_annotation = db
|
let author_annotation = db
|
||||||
.author_annotation()
|
.author_annotation()
|
||||||
.find_unique(
|
.find_unique(author_annotation::author_id::equals(author_id))
|
||||||
author_annotation::author_id::equals(author_id)
|
|
||||||
)
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -120,21 +105,18 @@ async fn get_author_annotation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn get_author_books(
|
async fn get_author_books(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(author_id): Path<i32>,
|
Path(author_id): Path<i32>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>,
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
pagination: Query<Pagination>
|
AllowedLangs,
|
||||||
|
>,
|
||||||
|
pagination: Query<Pagination>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let author = db
|
let author = db
|
||||||
.author()
|
.author()
|
||||||
.find_unique(
|
.find_unique(author::id::equals(author_id))
|
||||||
author::id::equals(author_id),
|
.with(author::author_annotation::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -146,43 +128,22 @@ async fn get_author_books(
|
|||||||
|
|
||||||
let books_filter = vec![
|
let books_filter = vec![
|
||||||
book::is_deleted::equals(false),
|
book::is_deleted::equals(false),
|
||||||
book::book_authors::some(vec![
|
book::book_authors::some(vec![book_author::author_id::equals(author_id)]),
|
||||||
book_author::author_id::equals(author_id)
|
book::lang::in_vec(allowed_langs.clone()),
|
||||||
]),
|
|
||||||
book::lang::in_vec(allowed_langs.clone())
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let books_count = db
|
let books_count = db.book().count(books_filter.clone()).exec().await.unwrap();
|
||||||
.book()
|
|
||||||
.count(books_filter.clone())
|
|
||||||
.exec()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let books = db
|
let books = db
|
||||||
.book()
|
.book()
|
||||||
.find_many(books_filter)
|
.find_many(books_filter)
|
||||||
.with(
|
.with(book::source::fetch())
|
||||||
book::source::fetch()
|
.with(book::book_annotation::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_annotation::fetch()
|
|
||||||
)
|
|
||||||
.with(
|
.with(
|
||||||
book::translations::fetch(vec![])
|
book::translations::fetch(vec![])
|
||||||
.with(
|
.with(translator::author::fetch().with(author::author_annotation::fetch())),
|
||||||
translator::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_sequences::fetch(vec![])
|
|
||||||
.with(
|
|
||||||
book_sequence::sequence::fetch()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
.with(book::book_sequences::fetch(vec![]).with(book_sequence::sequence::fetch()))
|
||||||
.order_by(book::id::order(prisma_client_rust::Direction::Asc))
|
.order_by(book::id::order(prisma_client_rust::Direction::Asc))
|
||||||
.skip((pagination.page - 1) * pagination.size)
|
.skip((pagination.page - 1) * pagination.size)
|
||||||
.take(pagination.size)
|
.take(pagination.size)
|
||||||
@@ -194,26 +155,25 @@ async fn get_author_books(
|
|||||||
author.into(),
|
author.into(),
|
||||||
books.iter().map(|item| item.clone().into()).collect(),
|
books.iter().map(|item| item.clone().into()).collect(),
|
||||||
books_count,
|
books_count,
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page).into_response()
|
Json(page).into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn get_author_books_available_types(
|
async fn get_author_books_available_types(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(author_id): Path<i32>,
|
Path(author_id): Path<i32>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
|
AllowedLangs,
|
||||||
|
>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let books = db
|
let books = db
|
||||||
.book()
|
.book()
|
||||||
.find_many(vec![
|
.find_many(vec![
|
||||||
book::is_deleted::equals(false),
|
book::is_deleted::equals(false),
|
||||||
book::book_authors::some(vec![
|
book::book_authors::some(vec![book_author::author_id::equals(author_id)]),
|
||||||
book_author::author_id::equals(author_id)
|
book::lang::in_vec(allowed_langs),
|
||||||
]),
|
|
||||||
book::lang::in_vec(allowed_langs)
|
|
||||||
])
|
])
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
@@ -234,27 +194,29 @@ async fn get_author_books_available_types(
|
|||||||
Json::<Vec<String>>(file_types.into_iter().collect())
|
Json::<Vec<String>>(file_types.into_iter().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn search_authors(
|
async fn search_authors(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(query): Path<String>,
|
Path(query): Path<String>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>,
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
pagination: Query<Pagination>
|
AllowedLangs,
|
||||||
|
>,
|
||||||
|
pagination: Query<Pagination>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let client = get_meili_client();
|
let client = get_meili_client();
|
||||||
|
|
||||||
let authors_index = client.index("authors");
|
let authors_index = client.index("authors");
|
||||||
|
|
||||||
let filter = format!(
|
let filter = format!("author_langs IN [{}]", allowed_langs.join(", "));
|
||||||
"author_langs IN [{}]",
|
|
||||||
allowed_langs.join(", ")
|
|
||||||
);
|
|
||||||
|
|
||||||
let result = authors_index
|
let result = authors_index
|
||||||
.search()
|
.search()
|
||||||
.with_query(&query)
|
.with_query(&query)
|
||||||
.with_filter(&filter)
|
.with_filter(&filter)
|
||||||
.with_offset(((pagination.page - 1) * pagination.size).try_into().unwrap())
|
.with_offset(
|
||||||
|
((pagination.page - 1) * pagination.size)
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
.with_limit(pagination.size.try_into().unwrap())
|
.with_limit(pagination.size.try_into().unwrap())
|
||||||
.execute::<AuthorMeili>()
|
.execute::<AuthorMeili>()
|
||||||
.await
|
.await
|
||||||
@@ -265,12 +227,8 @@ async fn search_authors(
|
|||||||
|
|
||||||
let mut authors = db
|
let mut authors = db
|
||||||
.author()
|
.author()
|
||||||
.find_many(vec![
|
.find_many(vec![author::id::in_vec(author_ids.clone())])
|
||||||
author::id::in_vec(author_ids.clone())
|
.with(author::author_annotation::fetch())
|
||||||
])
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
.order_by(author::id::order(prisma_client_rust::Direction::Asc))
|
.order_by(author::id::order(prisma_client_rust::Direction::Asc))
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
@@ -286,13 +244,12 @@ async fn search_authors(
|
|||||||
let page: Page<Author> = Page::new(
|
let page: Page<Author> = Page::new(
|
||||||
authors.iter().map(|item| item.clone().into()).collect(),
|
authors.iter().map(|item| item.clone().into()).collect(),
|
||||||
total.try_into().unwrap(),
|
total.try_into().unwrap(),
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page)
|
Json(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_authors_router() -> Router {
|
pub async fn get_authors_router() -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", get(get_authors))
|
.route("/", get(get_authors))
|
||||||
@@ -300,6 +257,9 @@ pub async fn get_authors_router() -> Router {
|
|||||||
.route("/:author_id", get(get_author))
|
.route("/:author_id", get(get_author))
|
||||||
.route("/:author_id/annotation", get(get_author_annotation))
|
.route("/:author_id/annotation", get(get_author_annotation))
|
||||||
.route("/:author_id/books", get(get_author_books))
|
.route("/:author_id/books", get(get_author_books))
|
||||||
.route("/:author_id/available_types", get(get_author_books_available_types))
|
.route(
|
||||||
|
"/:author_id/available_types",
|
||||||
|
get(get_author_books_available_types),
|
||||||
|
)
|
||||||
.route("/search/:query", get(search_authors))
|
.route("/search/:query", get(search_authors))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +1,52 @@
|
|||||||
use axum::{Router, routing::get, extract::{Query, Path}, Json, response::IntoResponse, http::StatusCode};
|
use axum::{
|
||||||
|
extract::{Path, Query},
|
||||||
|
http::StatusCode,
|
||||||
|
response::IntoResponse,
|
||||||
|
routing::get,
|
||||||
|
Json, Router,
|
||||||
|
};
|
||||||
use prisma_client_rust::Direction;
|
use prisma_client_rust::Direction;
|
||||||
|
|
||||||
use crate::{serializers::{book::{BookFilter, RemoteBook, BaseBook, DetailBook, RandomBookFilter, Book}, pagination::{Pagination, Page}, book_annotation::BookAnnotation, allowed_langs::AllowedLangs}, prisma::{book::{self}, book_author, author, translator, book_sequence, book_genre, book_annotation, genre}, meilisearch::{get_meili_client, BookMeili}};
|
use crate::{
|
||||||
|
meilisearch::{get_meili_client, BookMeili},
|
||||||
use super::{Database, common::get_random_item::get_random_item};
|
prisma::{
|
||||||
|
author,
|
||||||
|
book::{self},
|
||||||
|
book_annotation, book_author, book_genre, book_sequence, genre, translator,
|
||||||
|
},
|
||||||
|
serializers::{
|
||||||
|
allowed_langs::AllowedLangs,
|
||||||
|
book::{BaseBook, Book, BookFilter, DetailBook, RandomBookFilter, RemoteBook},
|
||||||
|
book_annotation::BookAnnotation,
|
||||||
|
pagination::{Page, Pagination},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::{common::get_random_item::get_random_item, Database};
|
||||||
|
|
||||||
pub async fn get_books(
|
pub async fn get_books(
|
||||||
db: Database,
|
db: Database,
|
||||||
axum_extra::extract::Query(book_filter): axum_extra::extract::Query<BookFilter>,
|
axum_extra::extract::Query(book_filter): axum_extra::extract::Query<BookFilter>,
|
||||||
pagination: Query<Pagination>
|
pagination: Query<Pagination>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let filter = book_filter.get_filter_vec();
|
let filter = book_filter.get_filter_vec();
|
||||||
|
|
||||||
let books_count = db
|
let books_count = db.book().count(filter.clone()).exec().await.unwrap();
|
||||||
.book()
|
|
||||||
.count(filter.clone())
|
|
||||||
.exec()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let books = db
|
let books = db
|
||||||
.book()
|
.book()
|
||||||
.find_many(filter)
|
.find_many(filter)
|
||||||
.with(
|
.with(book::book_annotation::fetch())
|
||||||
book::book_annotation::fetch()
|
.with(book::source::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::source::fetch()
|
|
||||||
)
|
|
||||||
.with(
|
.with(
|
||||||
book::book_authors::fetch(vec![])
|
book::book_authors::fetch(vec![])
|
||||||
.with(
|
.with(book_author::author::fetch().with(author::author_annotation::fetch())),
|
||||||
book_author::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.with(
|
.with(
|
||||||
book::translations::fetch(vec![])
|
book::translations::fetch(vec![])
|
||||||
.with(
|
.with(translator::author::fetch().with(author::author_annotation::fetch())),
|
||||||
translator::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_sequences::fetch(vec![])
|
|
||||||
.with(
|
|
||||||
book_sequence::sequence::fetch()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
.with(book::book_sequences::fetch(vec![]).with(book_sequence::sequence::fetch()))
|
||||||
.order_by(book::id::order(Direction::Asc))
|
.order_by(book::id::order(Direction::Asc))
|
||||||
.skip((pagination.page - 1) * pagination.size)
|
.skip((pagination.page - 1) * pagination.size)
|
||||||
.take(pagination.size)
|
.take(pagination.size)
|
||||||
@@ -63,7 +57,7 @@ pub async fn get_books(
|
|||||||
let page: Page<RemoteBook> = Page::new(
|
let page: Page<RemoteBook> = Page::new(
|
||||||
books.iter().map(|item| item.clone().into()).collect(),
|
books.iter().map(|item| item.clone().into()).collect(),
|
||||||
books_count,
|
books_count,
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page)
|
Json(page)
|
||||||
@@ -72,23 +66,16 @@ pub async fn get_books(
|
|||||||
pub async fn get_base_books(
|
pub async fn get_base_books(
|
||||||
db: Database,
|
db: Database,
|
||||||
axum_extra::extract::Query(book_filter): axum_extra::extract::Query<BookFilter>,
|
axum_extra::extract::Query(book_filter): axum_extra::extract::Query<BookFilter>,
|
||||||
pagination: Query<Pagination>
|
pagination: Query<Pagination>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let filter = book_filter.get_filter_vec();
|
let filter = book_filter.get_filter_vec();
|
||||||
|
|
||||||
let books_count = db
|
let books_count = db.book().count(filter.clone()).exec().await.unwrap();
|
||||||
.book()
|
|
||||||
.count(filter.clone())
|
|
||||||
.exec()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let books = db
|
let books = db
|
||||||
.book()
|
.book()
|
||||||
.find_many(filter)
|
.find_many(filter)
|
||||||
.with(
|
.with(book::source::fetch())
|
||||||
book::source::fetch()
|
|
||||||
)
|
|
||||||
.order_by(book::id::order(Direction::Asc))
|
.order_by(book::id::order(Direction::Asc))
|
||||||
.skip((pagination.page - 1) * pagination.size)
|
.skip((pagination.page - 1) * pagination.size)
|
||||||
.take(pagination.size)
|
.take(pagination.size)
|
||||||
@@ -99,7 +86,7 @@ pub async fn get_base_books(
|
|||||||
let page: Page<BaseBook> = Page::new(
|
let page: Page<BaseBook> = Page::new(
|
||||||
books.iter().map(|item| item.clone().into()).collect(),
|
books.iter().map(|item| item.clone().into()).collect(),
|
||||||
books_count,
|
books_count,
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page)
|
Json(page)
|
||||||
@@ -115,10 +102,7 @@ pub async fn get_random_book(
|
|||||||
let authors_index = client.index("books");
|
let authors_index = client.index("books");
|
||||||
|
|
||||||
let filter = {
|
let filter = {
|
||||||
let langs_filter = format!(
|
let langs_filter = format!("lang IN [{}]", book_filter.allowed_langs.join(", "));
|
||||||
"lang IN [{}]",
|
|
||||||
book_filter.allowed_langs.join(", ")
|
|
||||||
);
|
|
||||||
let genre_filter = match book_filter.genre {
|
let genre_filter = match book_filter.genre {
|
||||||
Some(v) => format!(" AND genres = {v}"),
|
Some(v) => format!(" AND genres = {v}"),
|
||||||
None => "".to_string(),
|
None => "".to_string(),
|
||||||
@@ -127,53 +111,26 @@ pub async fn get_random_book(
|
|||||||
format!("{langs_filter}{genre_filter}")
|
format!("{langs_filter}{genre_filter}")
|
||||||
};
|
};
|
||||||
|
|
||||||
get_random_item::<BookMeili>(
|
get_random_item::<BookMeili>(authors_index, filter).await
|
||||||
authors_index,
|
|
||||||
filter
|
|
||||||
).await
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let book = db
|
let book = db
|
||||||
.book()
|
.book()
|
||||||
.find_unique(book::id::equals(book_id))
|
.find_unique(book::id::equals(book_id))
|
||||||
.with(
|
.with(book::book_annotation::fetch())
|
||||||
book::book_annotation::fetch()
|
.with(book::source::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::source::fetch()
|
|
||||||
)
|
|
||||||
.with(
|
.with(
|
||||||
book::book_authors::fetch(vec![])
|
book::book_authors::fetch(vec![])
|
||||||
.with(
|
.with(book_author::author::fetch().with(author::author_annotation::fetch())),
|
||||||
book_author::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.with(
|
.with(
|
||||||
book::translations::fetch(vec![])
|
book::translations::fetch(vec![])
|
||||||
.with(
|
.with(translator::author::fetch().with(author::author_annotation::fetch())),
|
||||||
translator::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_sequences::fetch(vec![])
|
|
||||||
.with(
|
|
||||||
book_sequence::sequence::fetch()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
.with(book::book_sequences::fetch(vec![]).with(book_sequence::sequence::fetch()))
|
||||||
.with(
|
.with(
|
||||||
book::book_genres::fetch(vec![])
|
book::book_genres::fetch(vec![])
|
||||||
.with(
|
.with(book_genre::genre::fetch().with(genre::source::fetch())),
|
||||||
book_genre::genre::fetch()
|
|
||||||
.with(
|
|
||||||
genre::source::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
@@ -190,44 +147,20 @@ pub async fn get_remote_book(
|
|||||||
let book = db
|
let book = db
|
||||||
.book()
|
.book()
|
||||||
.find_unique(book::source_id_remote_id(source_id, remote_id))
|
.find_unique(book::source_id_remote_id(source_id, remote_id))
|
||||||
.with(
|
.with(book::book_annotation::fetch())
|
||||||
book::book_annotation::fetch()
|
.with(book::source::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::source::fetch()
|
|
||||||
)
|
|
||||||
.with(
|
.with(
|
||||||
book::book_authors::fetch(vec![])
|
book::book_authors::fetch(vec![])
|
||||||
.with(
|
.with(book_author::author::fetch().with(author::author_annotation::fetch())),
|
||||||
book_author::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.with(
|
.with(
|
||||||
book::translations::fetch(vec![])
|
book::translations::fetch(vec![])
|
||||||
.with(
|
.with(translator::author::fetch().with(author::author_annotation::fetch())),
|
||||||
translator::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_sequences::fetch(vec![])
|
|
||||||
.with(
|
|
||||||
book_sequence::sequence::fetch()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
.with(book::book_sequences::fetch(vec![]).with(book_sequence::sequence::fetch()))
|
||||||
.with(
|
.with(
|
||||||
book::book_genres::fetch(vec![])
|
book::book_genres::fetch(vec![])
|
||||||
.with(
|
.with(book_genre::genre::fetch().with(genre::source::fetch())),
|
||||||
book_genre::genre::fetch()
|
|
||||||
.with(
|
|
||||||
genre::source::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
@@ -242,23 +175,26 @@ pub async fn get_remote_book(
|
|||||||
pub async fn search_books(
|
pub async fn search_books(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(query): Path<String>,
|
Path(query): Path<String>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>,
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
pagination: Query<Pagination>
|
AllowedLangs,
|
||||||
|
>,
|
||||||
|
pagination: Query<Pagination>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let client = get_meili_client();
|
let client = get_meili_client();
|
||||||
|
|
||||||
let book_index = client.index("books");
|
let book_index = client.index("books");
|
||||||
|
|
||||||
let filter = format!(
|
let filter = format!("lang IN [{}]", allowed_langs.join(", "));
|
||||||
"lang IN [{}]",
|
|
||||||
allowed_langs.join(", ")
|
|
||||||
);
|
|
||||||
|
|
||||||
let result = book_index
|
let result = book_index
|
||||||
.search()
|
.search()
|
||||||
.with_query(&query)
|
.with_query(&query)
|
||||||
.with_filter(&filter)
|
.with_filter(&filter)
|
||||||
.with_offset(((pagination.page - 1) * pagination.size).try_into().unwrap())
|
.with_offset(
|
||||||
|
((pagination.page - 1) * pagination.size)
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
.with_limit(pagination.size.try_into().unwrap())
|
.with_limit(pagination.size.try_into().unwrap())
|
||||||
.execute::<BookMeili>()
|
.execute::<BookMeili>()
|
||||||
.await
|
.await
|
||||||
@@ -270,36 +206,17 @@ pub async fn search_books(
|
|||||||
let mut books = db
|
let mut books = db
|
||||||
.book()
|
.book()
|
||||||
.find_many(vec![book::id::in_vec(book_ids.clone())])
|
.find_many(vec![book::id::in_vec(book_ids.clone())])
|
||||||
.with(
|
.with(book::book_annotation::fetch())
|
||||||
book::book_annotation::fetch()
|
.with(book::source::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::source::fetch()
|
|
||||||
)
|
|
||||||
.with(
|
.with(
|
||||||
book::book_authors::fetch(vec![])
|
book::book_authors::fetch(vec![])
|
||||||
.with(
|
.with(book_author::author::fetch().with(author::author_annotation::fetch())),
|
||||||
book_author::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.with(
|
.with(
|
||||||
book::translations::fetch(vec![])
|
book::translations::fetch(vec![])
|
||||||
.with(
|
.with(translator::author::fetch().with(author::author_annotation::fetch())),
|
||||||
translator::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_sequences::fetch(vec![])
|
|
||||||
.with(
|
|
||||||
book_sequence::sequence::fetch()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
.with(book::book_sequences::fetch(vec![]).with(book_sequence::sequence::fetch()))
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -314,57 +231,30 @@ pub async fn search_books(
|
|||||||
let page: Page<Book> = Page::new(
|
let page: Page<Book> = Page::new(
|
||||||
books.iter().map(|item| item.clone().into()).collect(),
|
books.iter().map(|item| item.clone().into()).collect(),
|
||||||
total.try_into().unwrap(),
|
total.try_into().unwrap(),
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page)
|
Json(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_book(
|
pub async fn get_book(db: Database, Path(book_id): Path<i32>) -> impl IntoResponse {
|
||||||
db: Database,
|
|
||||||
Path(book_id): Path<i32>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let book = db
|
let book = db
|
||||||
.book()
|
.book()
|
||||||
.find_unique(book::id::equals(book_id))
|
.find_unique(book::id::equals(book_id))
|
||||||
.with(
|
.with(book::book_annotation::fetch())
|
||||||
book::book_annotation::fetch()
|
.with(book::source::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::source::fetch()
|
|
||||||
)
|
|
||||||
.with(
|
.with(
|
||||||
book::book_authors::fetch(vec![])
|
book::book_authors::fetch(vec![])
|
||||||
.with(
|
.with(book_author::author::fetch().with(author::author_annotation::fetch())),
|
||||||
book_author::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.with(
|
.with(
|
||||||
book::translations::fetch(vec![])
|
book::translations::fetch(vec![])
|
||||||
.with(
|
.with(translator::author::fetch().with(author::author_annotation::fetch())),
|
||||||
translator::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_sequences::fetch(vec![])
|
|
||||||
.with(
|
|
||||||
book_sequence::sequence::fetch()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
.with(book::book_sequences::fetch(vec![]).with(book_sequence::sequence::fetch()))
|
||||||
.with(
|
.with(
|
||||||
book::book_genres::fetch(vec![])
|
book::book_genres::fetch(vec![])
|
||||||
.with(
|
.with(book_genre::genre::fetch().with(genre::source::fetch())),
|
||||||
book_genre::genre::fetch()
|
|
||||||
.with(
|
|
||||||
genre::source::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
@@ -376,15 +266,10 @@ pub async fn get_book(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_book_annotation(
|
pub async fn get_book_annotation(db: Database, Path(book_id): Path<i32>) -> impl IntoResponse {
|
||||||
db: Database,
|
|
||||||
Path(book_id): Path<i32>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let book_annotation = db
|
let book_annotation = db
|
||||||
.book_annotation()
|
.book_annotation()
|
||||||
.find_unique(
|
.find_unique(book_annotation::book_id::equals(book_id))
|
||||||
book_annotation::book_id::equals(book_id)
|
|
||||||
)
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ use serde::de::DeserializeOwned;
|
|||||||
|
|
||||||
use crate::meilisearch::GetId;
|
use crate::meilisearch::GetId;
|
||||||
|
|
||||||
pub async fn get_random_item<'a, T>(
|
pub async fn get_random_item<'a, T>(index: Index, filter: String) -> i32
|
||||||
index: Index, filter: String,
|
where
|
||||||
) -> i32
|
T: DeserializeOwned + GetId + 'static,
|
||||||
where T: DeserializeOwned + GetId + 'static {
|
{
|
||||||
let result = index
|
let result = index
|
||||||
.search()
|
.search()
|
||||||
.with_filter(&filter)
|
.with_filter(&filter)
|
||||||
@@ -15,7 +15,7 @@ where T: DeserializeOwned + GetId + 'static {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let offset: usize = rand::thread_rng().gen_range(0..result.estimated_total_hits.unwrap().try_into().unwrap());
|
let offset: usize = rand::thread_rng().gen_range(0..result.estimated_total_hits.unwrap());
|
||||||
|
|
||||||
let result = index
|
let result = index
|
||||||
.search()
|
.search()
|
||||||
|
|||||||
@@ -1,40 +1,36 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use axum::{Router, routing::get, extract::Query, Json, response::IntoResponse};
|
use axum::{extract::Query, response::IntoResponse, routing::get, Json, Router};
|
||||||
use prisma_client_rust::Direction;
|
use prisma_client_rust::Direction;
|
||||||
|
|
||||||
use crate::{serializers::{pagination::{Pagination, Page}, genre::{Genre, GenreFilter}}, prisma::genre};
|
use crate::{
|
||||||
|
prisma::genre,
|
||||||
|
serializers::{
|
||||||
|
genre::{Genre, GenreFilter},
|
||||||
|
pagination::{Page, Pagination},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
use super::Database;
|
use super::Database;
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_genres(
|
pub async fn get_genres(
|
||||||
db: Database,
|
db: Database,
|
||||||
pagination: Query<Pagination>,
|
pagination: Query<Pagination>,
|
||||||
Query(GenreFilter { meta }): Query<GenreFilter>
|
Query(GenreFilter { meta }): Query<GenreFilter>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let filter = {
|
let filter = {
|
||||||
match meta {
|
match meta {
|
||||||
Some(meta) => vec![
|
Some(meta) => vec![genre::meta::equals(meta)],
|
||||||
genre::meta::equals(meta)
|
|
||||||
],
|
|
||||||
None => vec![],
|
None => vec![],
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let genres_count = db
|
let genres_count = db.genre().count(filter.clone()).exec().await.unwrap();
|
||||||
.genre()
|
|
||||||
.count(filter.clone())
|
|
||||||
.exec()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let genres = db
|
let genres = db
|
||||||
.genre()
|
.genre()
|
||||||
.find_many(filter)
|
.find_many(filter)
|
||||||
.with(
|
.with(genre::source::fetch())
|
||||||
genre::source::fetch()
|
|
||||||
)
|
|
||||||
.order_by(genre::id::order(Direction::Asc))
|
.order_by(genre::id::order(Direction::Asc))
|
||||||
.skip((pagination.page - 1) * pagination.size)
|
.skip((pagination.page - 1) * pagination.size)
|
||||||
.take(pagination.size)
|
.take(pagination.size)
|
||||||
@@ -45,16 +41,13 @@ pub async fn get_genres(
|
|||||||
let page: Page<Genre> = Page::new(
|
let page: Page<Genre> = Page::new(
|
||||||
genres.iter().map(|item| item.clone().into()).collect(),
|
genres.iter().map(|item| item.clone().into()).collect(),
|
||||||
genres_count,
|
genres_count,
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page)
|
Json(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_genre_metas(db: Database) -> impl IntoResponse {
|
||||||
pub async fn get_genre_metas(
|
|
||||||
db: Database
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let genres = db
|
let genres = db
|
||||||
.genre()
|
.genre()
|
||||||
.find_many(vec![])
|
.find_many(vec![])
|
||||||
@@ -75,7 +68,6 @@ pub async fn get_genre_metas(
|
|||||||
Json::<Vec<String>>(metas)
|
Json::<Vec<String>>(metas)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_genres_router() -> Router {
|
pub async fn get_genres_router() -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", get(get_genres))
|
.route("/", get(get_genres))
|
||||||
|
|||||||
@@ -1,28 +1,36 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use axum::{Router, routing::get, middleware::{self, Next}, Extension, http::{Request, StatusCode, self}, response::Response};
|
use axum::{
|
||||||
|
http::{self, Request, StatusCode},
|
||||||
|
middleware::{self, Next},
|
||||||
|
response::Response,
|
||||||
|
routing::get,
|
||||||
|
Extension, Router,
|
||||||
|
};
|
||||||
use axum_prometheus::PrometheusMetricLayer;
|
use axum_prometheus::PrometheusMetricLayer;
|
||||||
use tower_http::trace::{TraceLayer, self};
|
use tower_http::trace::{self, TraceLayer};
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
|
|
||||||
use crate::{config::CONFIG, db::get_prisma_client, prisma::PrismaClient};
|
use crate::{config::CONFIG, db::get_prisma_client, prisma::PrismaClient};
|
||||||
|
|
||||||
use self::{authors::get_authors_router, genres::get_genres_router, books::get_books_router, sequences::get_sequences_router};
|
|
||||||
use self::translators::get_translators_router;
|
use self::translators::get_translators_router;
|
||||||
|
use self::{
|
||||||
|
authors::get_authors_router, books::get_books_router, genres::get_genres_router,
|
||||||
|
sequences::get_sequences_router,
|
||||||
|
};
|
||||||
|
|
||||||
pub mod authors;
|
pub mod authors;
|
||||||
pub mod books;
|
pub mod books;
|
||||||
|
pub mod common;
|
||||||
pub mod genres;
|
pub mod genres;
|
||||||
pub mod sequences;
|
pub mod sequences;
|
||||||
pub mod translators;
|
pub mod translators;
|
||||||
pub mod common;
|
|
||||||
|
|
||||||
|
|
||||||
pub type Database = Extension<Arc<PrismaClient>>;
|
pub type Database = Extension<Arc<PrismaClient>>;
|
||||||
|
|
||||||
|
|
||||||
async fn auth<B>(req: Request<B>, next: Next<B>) -> Result<Response, StatusCode> {
|
async fn auth<B>(req: Request<B>, next: Next<B>) -> Result<Response, StatusCode> {
|
||||||
let auth_header = req.headers()
|
let auth_header = req
|
||||||
|
.headers()
|
||||||
.get(http::header::AUTHORIZATION)
|
.get(http::header::AUTHORIZATION)
|
||||||
.and_then(|header| header.to_str().ok());
|
.and_then(|header| header.to_str().ok());
|
||||||
|
|
||||||
@@ -39,35 +47,30 @@ async fn auth<B>(req: Request<B>, next: Next<B>) -> Result<Response, StatusCode>
|
|||||||
Ok(next.run(req).await)
|
Ok(next.run(req).await)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_router() -> Router {
|
pub async fn get_router() -> Router {
|
||||||
let client = Arc::new(get_prisma_client().await);
|
let client = Arc::new(get_prisma_client().await);
|
||||||
|
|
||||||
let (prometheus_layer, metric_handle) = PrometheusMetricLayer::pair();
|
let (prometheus_layer, metric_handle) = PrometheusMetricLayer::pair();
|
||||||
|
|
||||||
let app_router = Router::new()
|
let app_router = Router::new()
|
||||||
|
|
||||||
.nest("/api/v1/authors", get_authors_router().await)
|
.nest("/api/v1/authors", get_authors_router().await)
|
||||||
.nest("/api/v1/translators", get_translators_router().await)
|
.nest("/api/v1/translators", get_translators_router().await)
|
||||||
.nest("/api/v1/genres", get_genres_router().await)
|
.nest("/api/v1/genres", get_genres_router().await)
|
||||||
.nest("/api/v1/books", get_books_router().await)
|
.nest("/api/v1/books", get_books_router().await)
|
||||||
.nest("/api/v1/sequences", get_sequences_router().await)
|
.nest("/api/v1/sequences", get_sequences_router().await)
|
||||||
|
|
||||||
.layer(middleware::from_fn(auth))
|
.layer(middleware::from_fn(auth))
|
||||||
.layer(Extension(client))
|
.layer(Extension(client))
|
||||||
.layer(prometheus_layer);
|
.layer(prometheus_layer);
|
||||||
|
|
||||||
let metric_router = Router::new()
|
let metric_router =
|
||||||
.route("/metrics", get(|| async move { metric_handle.render() }));
|
Router::new().route("/metrics", get(|| async move { metric_handle.render() }));
|
||||||
|
|
||||||
Router::new()
|
Router::new()
|
||||||
.nest("/", app_router)
|
.nest("/", app_router)
|
||||||
.nest("/", metric_router)
|
.nest("/", metric_router)
|
||||||
.layer(
|
.layer(
|
||||||
TraceLayer::new_for_http()
|
TraceLayer::new_for_http()
|
||||||
.make_span_with(trace::DefaultMakeSpan::new()
|
.make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO))
|
||||||
.level(Level::INFO))
|
.on_response(trace::DefaultOnResponse::new().level(Level::INFO)),
|
||||||
.on_response(trace::DefaultOnResponse::new()
|
|
||||||
.level(Level::INFO)),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,44 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use axum::{Router, routing::get, extract::{Path, Query}, http::StatusCode, response::IntoResponse, Json};
|
use axum::{
|
||||||
|
extract::{Path, Query},
|
||||||
|
http::StatusCode,
|
||||||
|
response::IntoResponse,
|
||||||
|
routing::get,
|
||||||
|
Json, Router,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{prisma::{sequence, book_sequence, book, book_author, author, translator}, serializers::{sequence::{Sequence, SequenceBook}, allowed_langs::AllowedLangs, pagination::{PageWithParent, Pagination, Page}}, meilisearch::{get_meili_client, SequenceMeili}};
|
use crate::{
|
||||||
|
meilisearch::{get_meili_client, SequenceMeili},
|
||||||
use super::{Database, common::get_random_item::get_random_item};
|
prisma::{author, book, book_author, book_sequence, sequence, translator},
|
||||||
|
serializers::{
|
||||||
|
allowed_langs::AllowedLangs,
|
||||||
|
pagination::{Page, PageWithParent, Pagination},
|
||||||
|
sequence::{Sequence, SequenceBook},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::{common::get_random_item::get_random_item, Database};
|
||||||
|
|
||||||
async fn get_random_sequence(
|
async fn get_random_sequence(
|
||||||
db: Database,
|
db: Database,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
|
AllowedLangs,
|
||||||
|
>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let sequence_id = {
|
let sequence_id = {
|
||||||
let client = get_meili_client();
|
let client = get_meili_client();
|
||||||
|
|
||||||
let authors_index = client.index("sequences");
|
let authors_index = client.index("sequences");
|
||||||
|
|
||||||
let filter = format!(
|
let filter = format!("langs IN [{}]", allowed_langs.join(", "));
|
||||||
"langs IN [{}]",
|
|
||||||
allowed_langs.join(", ")
|
|
||||||
);
|
|
||||||
|
|
||||||
get_random_item::<SequenceMeili>(
|
get_random_item::<SequenceMeili>(authors_index, filter).await
|
||||||
authors_index,
|
|
||||||
filter
|
|
||||||
).await
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let sequence = db
|
let sequence = db
|
||||||
.sequence()
|
.sequence()
|
||||||
.find_unique(
|
.find_unique(sequence::id::equals(sequence_id))
|
||||||
sequence::id::equals(sequence_id)
|
|
||||||
)
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -43,23 +50,26 @@ async fn get_random_sequence(
|
|||||||
async fn search_sequence(
|
async fn search_sequence(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(query): Path<String>,
|
Path(query): Path<String>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>,
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
pagination: Query<Pagination>
|
AllowedLangs,
|
||||||
|
>,
|
||||||
|
pagination: Query<Pagination>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let client = get_meili_client();
|
let client = get_meili_client();
|
||||||
|
|
||||||
let sequence_index = client.index("sequences");
|
let sequence_index = client.index("sequences");
|
||||||
|
|
||||||
let filter = format!(
|
let filter = format!("langs IN [{}]", allowed_langs.join(", "));
|
||||||
"langs IN [{}]",
|
|
||||||
allowed_langs.join(", ")
|
|
||||||
);
|
|
||||||
|
|
||||||
let result = sequence_index
|
let result = sequence_index
|
||||||
.search()
|
.search()
|
||||||
.with_query(&query)
|
.with_query(&query)
|
||||||
.with_filter(&filter)
|
.with_filter(&filter)
|
||||||
.with_offset(((pagination.page - 1) * pagination.size).try_into().unwrap())
|
.with_offset(
|
||||||
|
((pagination.page - 1) * pagination.size)
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
.with_limit(pagination.size.try_into().unwrap())
|
.with_limit(pagination.size.try_into().unwrap())
|
||||||
.execute::<SequenceMeili>()
|
.execute::<SequenceMeili>()
|
||||||
.await
|
.await
|
||||||
@@ -70,9 +80,7 @@ async fn search_sequence(
|
|||||||
|
|
||||||
let mut sequences = db
|
let mut sequences = db
|
||||||
.sequence()
|
.sequence()
|
||||||
.find_many(vec![
|
.find_many(vec![sequence::id::in_vec(sequence_ids.clone())])
|
||||||
sequence::id::in_vec(sequence_ids.clone())
|
|
||||||
])
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -87,21 +95,16 @@ async fn search_sequence(
|
|||||||
let page: Page<Sequence> = Page::new(
|
let page: Page<Sequence> = Page::new(
|
||||||
sequences.iter().map(|item| item.clone().into()).collect(),
|
sequences.iter().map(|item| item.clone().into()).collect(),
|
||||||
total.try_into().unwrap(),
|
total.try_into().unwrap(),
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page)
|
Json(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_sequence(
|
async fn get_sequence(db: Database, Path(sequence_id): Path<i32>) -> impl IntoResponse {
|
||||||
db: Database,
|
|
||||||
Path(sequence_id): Path<i32>
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let sequence = db
|
let sequence = db
|
||||||
.sequence()
|
.sequence()
|
||||||
.find_unique(
|
.find_unique(sequence::id::equals(sequence_id))
|
||||||
sequence::id::equals(sequence_id)
|
|
||||||
)
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -115,16 +118,16 @@ async fn get_sequence(
|
|||||||
async fn get_sequence_available_types(
|
async fn get_sequence_available_types(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(sequence_id): Path<i32>,
|
Path(sequence_id): Path<i32>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
|
AllowedLangs,
|
||||||
|
>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let books = db
|
let books = db
|
||||||
.book()
|
.book()
|
||||||
.find_many(vec![
|
.find_many(vec![
|
||||||
book::is_deleted::equals(false),
|
book::is_deleted::equals(false),
|
||||||
book::book_sequences::some(vec![
|
book::book_sequences::some(vec![book_sequence::sequence_id::equals(sequence_id)]),
|
||||||
book_sequence::sequence_id::equals(sequence_id)
|
book::lang::in_vec(allowed_langs),
|
||||||
]),
|
|
||||||
book::lang::in_vec(allowed_langs)
|
|
||||||
])
|
])
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
@@ -148,14 +151,14 @@ async fn get_sequence_available_types(
|
|||||||
async fn get_sequence_books(
|
async fn get_sequence_books(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(sequence_id): Path<i32>,
|
Path(sequence_id): Path<i32>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>,
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
pagination: Query<Pagination>
|
AllowedLangs,
|
||||||
|
>,
|
||||||
|
pagination: Query<Pagination>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let sequence = db
|
let sequence = db
|
||||||
.sequence()
|
.sequence()
|
||||||
.find_unique(
|
.find_unique(sequence::id::equals(sequence_id))
|
||||||
sequence::id::equals(sequence_id)
|
|
||||||
)
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -167,45 +170,24 @@ async fn get_sequence_books(
|
|||||||
|
|
||||||
let books_filter = vec![
|
let books_filter = vec![
|
||||||
book::is_deleted::equals(false),
|
book::is_deleted::equals(false),
|
||||||
book::book_sequences::some(vec![
|
book::book_sequences::some(vec![book_sequence::sequence_id::equals(sequence_id)]),
|
||||||
book_sequence::sequence_id::equals(sequence_id)
|
book::lang::in_vec(allowed_langs.clone()),
|
||||||
]),
|
|
||||||
book::lang::in_vec(allowed_langs.clone())
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let books_count = db
|
let books_count = db.book().count(books_filter.clone()).exec().await.unwrap();
|
||||||
.book()
|
|
||||||
.count(books_filter.clone())
|
|
||||||
.exec()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let books = db
|
let books = db
|
||||||
.book()
|
.book()
|
||||||
.find_many(books_filter)
|
.find_many(books_filter)
|
||||||
.with(
|
.with(book::source::fetch())
|
||||||
book::source::fetch()
|
.with(book::book_annotation::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_annotation::fetch()
|
|
||||||
)
|
|
||||||
.with(
|
.with(
|
||||||
book::book_authors::fetch(vec![])
|
book::book_authors::fetch(vec![])
|
||||||
.with(
|
.with(book_author::author::fetch().with(author::author_annotation::fetch())),
|
||||||
book_author::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.with(
|
.with(
|
||||||
book::translations::fetch(vec![])
|
book::translations::fetch(vec![])
|
||||||
.with(
|
.with(translator::author::fetch().with(author::author_annotation::fetch())),
|
||||||
translator::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.order_by(book::id::order(prisma_client_rust::Direction::Asc))
|
.order_by(book::id::order(prisma_client_rust::Direction::Asc))
|
||||||
.skip((pagination.page - 1) * pagination.size)
|
.skip((pagination.page - 1) * pagination.size)
|
||||||
@@ -218,18 +200,20 @@ async fn get_sequence_books(
|
|||||||
sequence.into(),
|
sequence.into(),
|
||||||
books.iter().map(|item| item.clone().into()).collect(),
|
books.iter().map(|item| item.clone().into()).collect(),
|
||||||
books_count,
|
books_count,
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page).into_response()
|
Json(page).into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_sequences_router() -> Router {
|
pub async fn get_sequences_router() -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/random", get(get_random_sequence))
|
.route("/random", get(get_random_sequence))
|
||||||
.route("/search/:query", get(search_sequence))
|
.route("/search/:query", get(search_sequence))
|
||||||
.route("/:sequence_id", get(get_sequence))
|
.route("/:sequence_id", get(get_sequence))
|
||||||
.route("/:sequence_id/available_types", get(get_sequence_available_types))
|
.route(
|
||||||
|
"/:sequence_id/available_types",
|
||||||
|
get(get_sequence_available_types),
|
||||||
|
)
|
||||||
.route("/:sequence_id/books", get(get_sequence_books))
|
.route("/:sequence_id/books", get(get_sequence_books))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,42 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use axum::{Router, routing::get, extract::{Path, Query}, response::IntoResponse, Json, http::StatusCode};
|
use axum::{
|
||||||
|
extract::{Path, Query},
|
||||||
|
http::StatusCode,
|
||||||
|
response::IntoResponse,
|
||||||
|
routing::get,
|
||||||
|
Json, Router,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{serializers::{pagination::{Pagination, Page, PageWithParent}, author::Author, translator::TranslatorBook, allowed_langs::AllowedLangs}, meilisearch::{get_meili_client, AuthorMeili}, prisma::{author, book::{self}, translator, book_author, book_sequence}};
|
use crate::{
|
||||||
|
meilisearch::{get_meili_client, AuthorMeili},
|
||||||
|
prisma::{
|
||||||
|
author,
|
||||||
|
book::{self},
|
||||||
|
book_author, book_sequence, translator,
|
||||||
|
},
|
||||||
|
serializers::{
|
||||||
|
allowed_langs::AllowedLangs,
|
||||||
|
author::Author,
|
||||||
|
pagination::{Page, PageWithParent, Pagination},
|
||||||
|
translator::TranslatorBook,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
use super::Database;
|
use super::Database;
|
||||||
|
|
||||||
|
|
||||||
async fn get_translated_books(
|
async fn get_translated_books(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(translator_id): Path<i32>,
|
Path(translator_id): Path<i32>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>,
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
pagination: Query<Pagination>
|
AllowedLangs,
|
||||||
|
>,
|
||||||
|
pagination: Query<Pagination>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let translator = db
|
let translator = db
|
||||||
.author()
|
.author()
|
||||||
.find_unique(
|
.find_unique(author::id::equals(translator_id))
|
||||||
author::id::equals(translator_id)
|
.with(author::author_annotation::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -32,43 +48,22 @@ async fn get_translated_books(
|
|||||||
|
|
||||||
let books_filter = vec![
|
let books_filter = vec![
|
||||||
book::is_deleted::equals(false),
|
book::is_deleted::equals(false),
|
||||||
book::translations::some(vec![
|
book::translations::some(vec![translator::author_id::equals(translator_id)]),
|
||||||
translator::author_id::equals(translator_id)
|
book::lang::in_vec(allowed_langs.clone()),
|
||||||
]),
|
|
||||||
book::lang::in_vec(allowed_langs.clone())
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let books_count = db
|
let books_count = db.book().count(books_filter.clone()).exec().await.unwrap();
|
||||||
.book()
|
|
||||||
.count(books_filter.clone())
|
|
||||||
.exec()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let books = db
|
let books = db
|
||||||
.book()
|
.book()
|
||||||
.find_many(books_filter)
|
.find_many(books_filter)
|
||||||
.with(
|
.with(book::source::fetch())
|
||||||
book::source::fetch()
|
.with(book::book_annotation::fetch())
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_annotation::fetch()
|
|
||||||
)
|
|
||||||
.with(
|
.with(
|
||||||
book::book_authors::fetch(vec![])
|
book::book_authors::fetch(vec![])
|
||||||
.with(
|
.with(book_author::author::fetch().with(author::author_annotation::fetch())),
|
||||||
book_author::author::fetch()
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.with(
|
|
||||||
book::book_sequences::fetch(vec![])
|
|
||||||
.with(
|
|
||||||
book_sequence::sequence::fetch()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
.with(book::book_sequences::fetch(vec![]).with(book_sequence::sequence::fetch()))
|
||||||
.order_by(book::id::order(prisma_client_rust::Direction::Asc))
|
.order_by(book::id::order(prisma_client_rust::Direction::Asc))
|
||||||
.skip((pagination.page - 1) * pagination.size)
|
.skip((pagination.page - 1) * pagination.size)
|
||||||
.take(pagination.size)
|
.take(pagination.size)
|
||||||
@@ -80,26 +75,25 @@ async fn get_translated_books(
|
|||||||
translator.into(),
|
translator.into(),
|
||||||
books.iter().map(|item| item.clone().into()).collect(),
|
books.iter().map(|item| item.clone().into()).collect(),
|
||||||
books_count,
|
books_count,
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page).into_response()
|
Json(page).into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn get_translated_books_available_types(
|
async fn get_translated_books_available_types(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(translator_id): Path<i32>,
|
Path(translator_id): Path<i32>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
|
AllowedLangs,
|
||||||
|
>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let books = db
|
let books = db
|
||||||
.book()
|
.book()
|
||||||
.find_many(vec![
|
.find_many(vec![
|
||||||
book::is_deleted::equals(false),
|
book::is_deleted::equals(false),
|
||||||
book::translations::some(vec![
|
book::translations::some(vec![translator::author_id::equals(translator_id)]),
|
||||||
translator::author_id::equals(translator_id)
|
book::lang::in_vec(allowed_langs),
|
||||||
]),
|
|
||||||
book::lang::in_vec(allowed_langs)
|
|
||||||
])
|
])
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
@@ -120,27 +114,29 @@ async fn get_translated_books_available_types(
|
|||||||
Json::<Vec<String>>(file_types.into_iter().collect())
|
Json::<Vec<String>>(file_types.into_iter().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn search_translators(
|
async fn search_translators(
|
||||||
db: Database,
|
db: Database,
|
||||||
Path(query): Path<String>,
|
Path(query): Path<String>,
|
||||||
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<AllowedLangs>,
|
axum_extra::extract::Query(AllowedLangs { allowed_langs }): axum_extra::extract::Query<
|
||||||
pagination: Query<Pagination>
|
AllowedLangs,
|
||||||
|
>,
|
||||||
|
pagination: Query<Pagination>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let client = get_meili_client();
|
let client = get_meili_client();
|
||||||
|
|
||||||
let authors_index = client.index("authors");
|
let authors_index = client.index("authors");
|
||||||
|
|
||||||
let filter = format!(
|
let filter = format!("translator_langs IN [{}]", allowed_langs.join(", "));
|
||||||
"translator_langs IN [{}]",
|
|
||||||
allowed_langs.join(", ")
|
|
||||||
);
|
|
||||||
|
|
||||||
let result = authors_index
|
let result = authors_index
|
||||||
.search()
|
.search()
|
||||||
.with_query(&query)
|
.with_query(&query)
|
||||||
.with_filter(&filter)
|
.with_filter(&filter)
|
||||||
.with_offset(((pagination.page - 1) * pagination.size).try_into().unwrap())
|
.with_offset(
|
||||||
|
((pagination.page - 1) * pagination.size)
|
||||||
|
.try_into()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
.with_limit(pagination.size.try_into().unwrap())
|
.with_limit(pagination.size.try_into().unwrap())
|
||||||
.execute::<AuthorMeili>()
|
.execute::<AuthorMeili>()
|
||||||
.await
|
.await
|
||||||
@@ -151,12 +147,8 @@ async fn search_translators(
|
|||||||
|
|
||||||
let mut translators = db
|
let mut translators = db
|
||||||
.author()
|
.author()
|
||||||
.find_many(vec![
|
.find_many(vec![author::id::in_vec(translator_ids.clone())])
|
||||||
author::id::in_vec(translator_ids.clone())
|
.with(author::author_annotation::fetch())
|
||||||
])
|
|
||||||
.with(
|
|
||||||
author::author_annotation::fetch()
|
|
||||||
)
|
|
||||||
.order_by(author::id::order(prisma_client_rust::Direction::Asc))
|
.order_by(author::id::order(prisma_client_rust::Direction::Asc))
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
@@ -172,16 +164,18 @@ async fn search_translators(
|
|||||||
let page: Page<Author> = Page::new(
|
let page: Page<Author> = Page::new(
|
||||||
translators.iter().map(|item| item.clone().into()).collect(),
|
translators.iter().map(|item| item.clone().into()).collect(),
|
||||||
total.try_into().unwrap(),
|
total.try_into().unwrap(),
|
||||||
&pagination
|
&pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
Json(page)
|
Json(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_translators_router() -> Router {
|
pub async fn get_translators_router() -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/:translator_id/books", get(get_translated_books))
|
.route("/:translator_id/books", get(get_translated_books))
|
||||||
.route("/:translator_id/available_types", get(get_translated_books_available_types))
|
.route(
|
||||||
|
"/:translator_id/available_types",
|
||||||
|
get(get_translated_books_available_types),
|
||||||
|
)
|
||||||
.route("/search/:query", get(search_translators))
|
.route("/search/:query", get(search_translators))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user