Rewrite to rust init

This commit is contained in:
2023-08-11 01:11:27 +02:00
parent 22d8b33bf4
commit 9acdb20463
84 changed files with 28739 additions and 4196 deletions

78
src/serializers/author.rs Normal file
View File

@@ -0,0 +1,78 @@
use serde::Serialize;
use crate::prisma::{author, book};
use super::{sequence::Sequence, utils::{get_available_types, get_translators, get_sequences}};
#[derive(Serialize)]
pub struct Author {
pub id: i32,
pub first_name: String,
pub last_name: String,
pub middle_name: String,
pub annotation_exists: bool,
}
impl From<author::Data> for Author {
fn from(val: author::Data) -> Self {
let author::Data {
id,
first_name,
last_name,
middle_name,
author_annotation,
..
} = val;
Author {
id,
first_name,
last_name,
middle_name: middle_name.unwrap_or("".to_string()),
annotation_exists: author_annotation.unwrap().is_some(),
}
}
}
#[derive(Serialize)]
pub struct AuthorBook {
pub id: i32,
pub title: String,
pub lang: String,
pub file_type: String,
pub available_types: Vec<String>,
pub uploaded: String,
pub translators: Vec<Author>,
pub sequences: Vec<Sequence>,
pub annotation_exists: bool,
}
impl From<book::Data> for AuthorBook {
fn from(val: book::Data) -> Self {
let book::Data {
id,
title,
lang,
file_type,
uploaded,
translations,
book_sequences,
book_annotation,
source,
..
} = val;
AuthorBook {
id,
title,
lang,
file_type: file_type.clone(),
available_types: get_available_types(file_type, source.unwrap().name),
uploaded: uploaded.format("%Y-%m-%d").to_string(),
translators: get_translators(translations),
sequences: get_sequences(book_sequences),
annotation_exists: book_annotation.unwrap().is_some(),
}
}
}