Serialize side done
This commit is contained in:
parent
43961b3ea1
commit
f1a02e8e58
10
src/external/database/serde/common.rs
vendored
10
src/external/database/serde/common.rs
vendored
@ -4,7 +4,7 @@ use crate::core::collection::album::{AlbumPrimaryType, AlbumSecondaryType};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(remote = "AlbumPrimaryType")]
|
||||
pub enum SerdeAlbumPrimaryTypeDef {
|
||||
pub enum AlbumPrimaryTypeDef {
|
||||
Album,
|
||||
Single,
|
||||
Ep,
|
||||
@ -13,7 +13,7 @@ pub enum SerdeAlbumPrimaryTypeDef {
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct SerdeAlbumPrimaryType(#[serde(with = "SerdeAlbumPrimaryTypeDef")] AlbumPrimaryType);
|
||||
pub struct SerdeAlbumPrimaryType(#[serde(with = "AlbumPrimaryTypeDef")] AlbumPrimaryType);
|
||||
|
||||
impl From<SerdeAlbumPrimaryType> for AlbumPrimaryType {
|
||||
fn from(value: SerdeAlbumPrimaryType) -> Self {
|
||||
@ -29,7 +29,7 @@ impl From<AlbumPrimaryType> for SerdeAlbumPrimaryType {
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(remote = "AlbumSecondaryType")]
|
||||
pub enum SerdeAlbumSecondaryTypeDef {
|
||||
pub enum AlbumSecondaryTypeDef {
|
||||
Compilation,
|
||||
Soundtrack,
|
||||
Spokenword,
|
||||
@ -45,9 +45,7 @@ pub enum SerdeAlbumSecondaryTypeDef {
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct SerdeAlbumSecondaryType(
|
||||
#[serde(with = "SerdeAlbumSecondaryTypeDef")] AlbumSecondaryType,
|
||||
);
|
||||
pub struct SerdeAlbumSecondaryType(#[serde(with = "AlbumSecondaryTypeDef")] AlbumSecondaryType);
|
||||
|
||||
impl From<SerdeAlbumSecondaryType> for AlbumSecondaryType {
|
||||
fn from(value: SerdeAlbumSecondaryType) -> Self {
|
||||
|
33
src/external/database/serde/serialize.rs
vendored
33
src/external/database/serde/serialize.rs
vendored
@ -3,6 +3,7 @@ use std::collections::BTreeMap;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
collection::musicbrainz::{MbAlbumRef, MbArtistRef},
|
||||
core::collection::{album::Album, artist::Artist, musicbrainz::IMusicBrainzRef, Collection},
|
||||
external::database::serde::common::{SerdeAlbumPrimaryType, SerdeAlbumSecondaryType},
|
||||
};
|
||||
@ -22,7 +23,7 @@ impl<'a> From<&'a Collection> for SerializeDatabase<'a> {
|
||||
pub struct SerializeArtist<'a> {
|
||||
name: &'a str,
|
||||
sort: Option<&'a str>,
|
||||
musicbrainz: Option<&'a str>,
|
||||
musicbrainz: Option<SerdeMbArtistRef<'a>>,
|
||||
properties: BTreeMap<&'a str, &'a Vec<String>>,
|
||||
albums: Vec<SerializeAlbum<'a>>,
|
||||
}
|
||||
@ -31,17 +32,41 @@ pub struct SerializeArtist<'a> {
|
||||
pub struct SerializeAlbum<'a> {
|
||||
title: &'a str,
|
||||
seq: u8,
|
||||
musicbrainz: Option<&'a str>,
|
||||
musicbrainz: Option<SerdeMbAlbumRef<'a>>,
|
||||
primary_type: Option<SerdeAlbumPrimaryType>,
|
||||
secondary_types: Vec<SerdeAlbumSecondaryType>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SerdeMbArtistRef<'a>(&'a MbArtistRef);
|
||||
|
||||
impl<'a> Serialize for SerdeMbArtistRef<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.0.url().as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SerdeMbAlbumRef<'a>(&'a MbAlbumRef);
|
||||
|
||||
impl<'a> Serialize for SerdeMbAlbumRef<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.0.url().as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Artist> for SerializeArtist<'a> {
|
||||
fn from(artist: &'a Artist) -> Self {
|
||||
SerializeArtist {
|
||||
name: &artist.id.name,
|
||||
sort: artist.sort.as_ref().map(|id| id.name.as_ref()),
|
||||
musicbrainz: artist.musicbrainz.as_ref().map(|mb| mb.url().as_str()),
|
||||
musicbrainz: artist.musicbrainz.as_ref().map(|mb| SerdeMbArtistRef(mb)),
|
||||
properties: artist
|
||||
.properties
|
||||
.iter()
|
||||
@ -57,7 +82,7 @@ impl<'a> From<&'a Album> for SerializeAlbum<'a> {
|
||||
SerializeAlbum {
|
||||
title: &album.id.title,
|
||||
seq: album.seq.0,
|
||||
musicbrainz: album.musicbrainz.as_ref().map(|mb| mb.url().as_str()),
|
||||
musicbrainz: album.musicbrainz.as_ref().map(|mb| SerdeMbAlbumRef(mb)),
|
||||
primary_type: album.primary_type.map(Into::into),
|
||||
secondary_types: album
|
||||
.secondary_types
|
||||
|
Loading…
Reference in New Issue
Block a user