diff --git a/src/external/database/serde/common.rs b/src/external/database/serde/common.rs index ff75896..ff3e01f 100644 --- a/src/external/database/serde/common.rs +++ b/src/external/database/serde/common.rs @@ -13,6 +13,21 @@ pub enum AlbumLibIdDef { None, } +#[derive(Debug, Deserialize, Serialize)] +pub struct SerdeAlbumLibId(#[serde(with = "AlbumLibIdDef")] AlbumLibId); + +impl From for AlbumLibId { + fn from(value: SerdeAlbumLibId) -> Self { + value.0 + } +} + +impl From for SerdeAlbumLibId { + fn from(value: AlbumLibId) -> Self { + SerdeAlbumLibId(value) + } +} + #[derive(Debug, Deserialize, Serialize)] #[serde(remote = "MbRefOption")] pub enum MbRefOptionDef { diff --git a/src/external/database/serde/deserialize.rs b/src/external/database/serde/deserialize.rs index 49eeffc..4a361ab 100644 --- a/src/external/database/serde/deserialize.rs +++ b/src/external/database/serde/deserialize.rs @@ -4,7 +4,7 @@ use serde::{de::Visitor, Deserialize, Deserializer}; use crate::{ collection::{ - album::{AlbumInfo, AlbumLibId, AlbumMeta}, + album::{AlbumInfo, AlbumMeta}, artist::{ArtistInfo, ArtistMeta}, musicbrainz::{MbAlbumRef, MbArtistRef, MbRefOption, Mbid}, }, @@ -14,7 +14,7 @@ use crate::{ Collection, Error as CollectionError, }, external::database::serde::common::{ - AlbumLibIdDef, MbRefOptionDef, SerdeAlbumPrimaryType, SerdeAlbumSecondaryType, + MbRefOptionDef, SerdeAlbumLibId, SerdeAlbumPrimaryType, SerdeAlbumSecondaryType, }, }; @@ -45,22 +45,13 @@ pub struct DeserializeArtist { #[derive(Debug, Deserialize)] pub struct DeserializeAlbum { title: String, - lib_id: DeserializeAlbumLibId, + lib_id: SerdeAlbumLibId, seq: u8, musicbrainz: DeserializeMbRefOption, primary_type: Option, secondary_types: Vec, } -#[derive(Debug, Deserialize)] -pub struct DeserializeAlbumLibId(#[serde(with = "AlbumLibIdDef")] AlbumLibId); - -impl From for AlbumLibId { - fn from(value: DeserializeAlbumLibId) -> Self { - value.0 - } -} - #[derive(Debug, Deserialize)] pub struct DeserializeMbRefOption(#[serde(with = "MbRefOptionDef")] MbRefOption); diff --git a/src/external/database/serde/serialize.rs b/src/external/database/serde/serialize.rs index a895a22..70ab598 100644 --- a/src/external/database/serde/serialize.rs +++ b/src/external/database/serde/serialize.rs @@ -3,13 +3,10 @@ use std::collections::BTreeMap; use serde::Serialize; use crate::{ - collection::{ - album::AlbumLibId, - musicbrainz::{MbRefOption, Mbid}, - }, + collection::musicbrainz::{MbRefOption, Mbid}, core::collection::{album::Album, artist::Artist, musicbrainz::IMusicBrainzRef, Collection}, external::database::serde::common::{ - AlbumLibIdDef, MbRefOptionDef, SerdeAlbumPrimaryType, SerdeAlbumSecondaryType, + MbRefOptionDef, SerdeAlbumLibId, SerdeAlbumPrimaryType, SerdeAlbumSecondaryType, }, }; @@ -36,22 +33,13 @@ pub struct SerializeArtist<'a> { #[derive(Debug, Serialize)] pub struct SerializeAlbum<'a> { title: &'a str, - lib_id: SerializeAlbumLibId, + lib_id: SerdeAlbumLibId, seq: u8, musicbrainz: SerializeMbRefOption<'a>, primary_type: Option, secondary_types: Vec, } -#[derive(Debug, Serialize)] -pub struct SerializeAlbumLibId(#[serde(with = "AlbumLibIdDef")] AlbumLibId); - -impl From for SerializeAlbumLibId { - fn from(value: AlbumLibId) -> Self { - SerializeAlbumLibId(value) - } -} - #[derive(Debug, Serialize)] pub struct SerializeMbRefOption<'a>( #[serde(with = "MbRefOptionDef")] MbRefOption>,