Slight Backend Refactoring

This commit is contained in:
Neshura 2023-11-01 21:55:08 +01:00
parent 9a8f2198f1
commit 5740d173c5
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
3 changed files with 37 additions and 28 deletions

View file

@ -21,5 +21,6 @@ fn main() {
#[tauri::command] #[tauri::command]
fn test(message: metadata::Metadata) -> String { fn test(message: metadata::Metadata) -> String {
message.save_to_xml("/home/neshura/Repositories/comicinfo-editor-v2/ComicInfo.xml");
format!("Series: '{}' | Title: '{}'", message.series_title, message.title) format!("Series: '{}' | Title: '{}'", message.series_title, message.title)
} }

View file

@ -16,18 +16,16 @@ pub(crate) struct Metadata {
pub(crate) volume_number: i16, pub(crate) volume_number: i16,
pub(crate) summary: Option<String>, pub(crate) summary: String,
pub(crate) year: i16, pub(crate) release_date: ReleaseDate,
pub(crate) month: i8,
pub(crate) day: i8,
pub(crate) writer: Option<String>, pub(crate) writer: String,
pub(crate) translator: Option<String>, pub(crate) translator: String,
pub(crate) letterer: Option<String>, pub(crate) letterer: String,
pub(crate) editor: Option<String>, pub(crate) editor: String,
pub(crate) publisher: Option<String>, pub(crate) publisher: String,
pub(crate) genre: String, pub(crate) genre: String,
@ -50,15 +48,17 @@ impl Default for Metadata {
chapter_number: 0, chapter_number: 0,
total_chapter_count: -1, total_chapter_count: -1,
volume_number: 1, volume_number: 1,
summary: None, summary: "".into(),
year: -1, release_date: ReleaseDate {
month: -1, year: -1,
day: -1, month: -1,
writer: None, day: -1,
letterer: None, },
editor: None, writer: "".into(),
translator: None, letterer: "".into(),
publisher: None, editor: "".into(),
translator: "".into(),
publisher: "".into(),
genre: "".into(), genre: "".into(),
tags: vec![], tags: vec![],
page_count: 0, page_count: 0,
@ -74,37 +74,38 @@ impl Serialize for Metadata {
let mut out_state = serializer.serialize_struct("Metadata", 22)?; let mut out_state = serializer.serialize_struct("Metadata", 22)?;
out_state.serialize_field("@xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")?; out_state.serialize_field("@xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")?;
out_state.serialize_field("@xsi:noNamespaceSchemaLocation", "ComicInfo.xsd")?; out_state.serialize_field("@xsi:noNamespaceSchemaLocation", "ComicInfo.xsd")?;
out_state.serialize_field("Title", &self.title)?;
out_state.serialize_field("Series", &self.series_title)?; out_state.serialize_field("Series", &self.series_title)?;
out_state.serialize_field("Title", &self.title)?;
out_state.serialize_field("Number", &self.chapter_number)?; out_state.serialize_field("Number", &self.chapter_number)?;
out_state.serialize_field("Count", &self.total_chapter_count)?; out_state.serialize_field("Count", &self.total_chapter_count)?;
out_state.serialize_field("Volume", &self.volume_number)?; out_state.serialize_field("Volume", &self.volume_number)?;
if self.summary.is_some() { if self.summary != "" {
out_state.serialize_field("Summary", &self.summary)?; out_state.serialize_field("Summary", &self.summary)?;
} }
out_state.serialize_field("Year", &self.year)?; out_state.serialize_field("Year", &self.release_date.year)?;
out_state.serialize_field("Month", &self.month)?; out_state.serialize_field("Month", &self.release_date.month)?;
out_state.serialize_field("Day", &self.day)?; out_state.serialize_field("Day", &self.release_date.day)?;
if self.writer.is_some() { if self.writer != "" {
out_state.serialize_field("Writer", &self.writer)?; out_state.serialize_field("Writer", &self.writer)?;
} }
if self.letterer.is_some() { if self.letterer != "" {
out_state.serialize_field("Letterer", &self.letterer)?; out_state.serialize_field("Letterer", &self.letterer)?;
} }
if self.editor.is_some() { if self.editor != "" {
out_state.serialize_field("Editor", &self.editor)?; out_state.serialize_field("Editor", &self.editor)?;
} }
if self.translator.is_some() { if self.translator != "" {
out_state.serialize_field("Translator", &self.translator)?; out_state.serialize_field("Translator", &self.translator)?;
} }
if self.publisher.is_some() { if self.publisher != "" {
out_state.serialize_field("Publisher", &self.publisher)?; out_state.serialize_field("Publisher", &self.publisher)?;
} }
@ -142,6 +143,13 @@ impl Metadata {
} }
} }
#[derive(Debug, Deserialize, PartialEq, Clone)]
pub(crate) struct ReleaseDate {
year: i16,
month: i8,
day: i8
}
/*#[derive(strum_macros::Display, Debug, PartialEq, strum_macros::EnumIter, Serialize, Deserialize, Clone)] /*#[derive(strum_macros::Display, Debug, PartialEq, strum_macros::EnumIter, Serialize, Deserialize, Clone)]
#[serde(tag = "AgeRating")] #[serde(tag = "AgeRating")]
pub(crate) enum AgeRating { pub(crate) enum AgeRating {

View file