mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-10 18:30:22 +01:00
Move to sqlx
This commit is contained in:
@@ -1,27 +1,16 @@
|
||||
use chrono::NaiveDate;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::prisma::{book, sequence};
|
||||
use super::author::Author;
|
||||
use super::date::naive_date_serializer;
|
||||
|
||||
use super::{
|
||||
author::Author,
|
||||
utils::{get_authors, get_available_types, get_translators},
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(sqlx::FromRow, sqlx::Type, Serialize)]
|
||||
pub struct Sequence {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl From<sequence::Data> for Sequence {
|
||||
fn from(val: sequence::Data) -> Self {
|
||||
let sequence::Data { id, name, .. } = val;
|
||||
|
||||
Sequence { id, name }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(sqlx::FromRow, Serialize)]
|
||||
pub struct SequenceBook {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
@@ -29,42 +18,10 @@ pub struct SequenceBook {
|
||||
pub file_type: String,
|
||||
pub year: i32,
|
||||
pub available_types: Vec<String>,
|
||||
pub uploaded: String,
|
||||
#[serde(serialize_with = "naive_date_serializer::serialize")]
|
||||
pub uploaded: NaiveDate,
|
||||
pub authors: Vec<Author>,
|
||||
pub translators: Vec<Author>,
|
||||
pub annotation_exists: bool,
|
||||
pub position: i32,
|
||||
}
|
||||
|
||||
impl From<book::Data> for SequenceBook {
|
||||
fn from(value: book::Data) -> Self {
|
||||
let book::Data {
|
||||
id,
|
||||
title,
|
||||
lang,
|
||||
file_type,
|
||||
year,
|
||||
uploaded,
|
||||
book_authors,
|
||||
translations,
|
||||
book_annotation,
|
||||
source,
|
||||
book_sequences,
|
||||
..
|
||||
} = value;
|
||||
|
||||
Self {
|
||||
id,
|
||||
title,
|
||||
lang,
|
||||
file_type: file_type.clone(),
|
||||
year,
|
||||
available_types: get_available_types(file_type, source.clone().unwrap().name),
|
||||
uploaded: uploaded.format("%Y-%m-%d").to_string(),
|
||||
authors: get_authors(book_authors),
|
||||
translators: get_translators(translations),
|
||||
annotation_exists: book_annotation.unwrap().is_some(),
|
||||
position: book_sequences.unwrap().first().unwrap().position,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user