Add status to database
Some checks failed
Cargo CI / Build and Test (pull_request) Successful in 2m4s
Cargo CI / Lint (pull_request) Failing after 1m8s

This commit is contained in:
Wojciech Kozlowski 2025-01-03 19:03:05 +01:00
parent 6d1e8b88f4
commit 3fb3f304ff
6 changed files with 45 additions and 15 deletions

View File

@ -294,6 +294,7 @@ impl Merge for AlbumMeta {
impl Merge for AlbumInfo {
fn merge_in_place(&mut self, other: Self) {
self.status = self.status.take().or(other.status);
self.primary_type = self.primary_type.take().or(other.primary_type);
if self.secondary_types.is_empty() {
self.secondary_types = other.secondary_types;

View File

@ -14,13 +14,13 @@ pub static DATABASE_JSON: &str = "{\
\"title\":\"album_title a.a\",\"lib_id\":{\"Value\":1},\
\"date\":{\"year\":1998,\"month\":null,\"day\":null},\"seq\":1,\
\"musicbrainz\":{\"Some\":\"00000000-0000-0000-0000-000000000000\"},\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
},\
{\
\"title\":\"album_title a.b\",\"lib_id\":{\"Value\":2},\
\"date\":{\"year\":2015,\"month\":4,\"day\":null},\"seq\":1,\
\"musicbrainz\":\"None\",\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
}\
]\
},\
@ -41,25 +41,25 @@ pub static DATABASE_JSON: &str = "{\
\"title\":\"album_title b.a\",\"lib_id\":{\"Value\":3},\
\"date\":{\"year\":2003,\"month\":6,\"day\":6},\"seq\":1,\
\"musicbrainz\":\"None\",\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
},\
{\
\"title\":\"album_title b.b\",\"lib_id\":{\"Value\":4},\
\"date\":{\"year\":2008,\"month\":null,\"day\":null},\"seq\":3,\
\"musicbrainz\":{\"Some\":\"11111111-1111-1111-1111-111111111111\"},\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
},\
{\
\"title\":\"album_title b.c\",\"lib_id\":{\"Value\":5},\
\"date\":{\"year\":2009,\"month\":null,\"day\":null},\"seq\":2,\
\"musicbrainz\":{\"Some\":\"11111111-1111-1111-1111-111111111112\"},\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
},\
{\
\"title\":\"album_title b.d\",\"lib_id\":{\"Value\":6},\
\"date\":{\"year\":2015,\"month\":null,\"day\":null},\"seq\":4,\
\"musicbrainz\":\"None\",\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
}\
]\
},\
@ -73,13 +73,13 @@ pub static DATABASE_JSON: &str = "{\
\"title\":\"album_title c.a\",\"lib_id\":{\"Value\":7},\
\"date\":{\"year\":1985,\"month\":null,\"day\":null},\"seq\":0,\
\"musicbrainz\":\"None\",\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
},\
{\
\"title\":\"album_title c.b\",\"lib_id\":{\"Value\":8},\
\"date\":{\"year\":2018,\"month\":null,\"day\":null},\"seq\":0,\
\"musicbrainz\":\"None\",\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
}\
]\
},\
@ -93,13 +93,13 @@ pub static DATABASE_JSON: &str = "{\
\"title\":\"album_title d.a\",\"lib_id\":{\"Value\":9},\
\"date\":{\"year\":1995,\"month\":null,\"day\":null},\"seq\":0,\
\"musicbrainz\":\"None\",\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
},\
{\
\"title\":\"album_title d.b\",\"lib_id\":{\"Value\":10},\
\"date\":{\"year\":2028,\"month\":null,\"day\":null},\"seq\":0,\
\"musicbrainz\":\"None\",\
\"primary_type\":\"Album\",\"secondary_types\":[]\
\"status\":\"Official\",\"primary_type\":\"Album\",\"secondary_types\":[]\
}\
]\
}\

View File

@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::core::collection::{
album::{AlbumDate, AlbumLibId, AlbumPrimaryType, AlbumSecondaryType},
album::{AlbumDate, AlbumLibId, AlbumPrimaryType, AlbumSecondaryType, AlbumStatus},
musicbrainz::MbRefOption,
};
@ -59,6 +59,32 @@ pub enum MbRefOptionDef<T> {
None,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(remote = "AlbumStatus")]
pub enum AlbumStatusDef {
Official,
Promotion,
Bootleg,
PseudoRelease,
Withdrawn,
Cancelled,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct SerdeAlbumStatus(#[serde(with = "AlbumStatusDef")] AlbumStatus);
impl From<SerdeAlbumStatus> for AlbumStatus {
fn from(value: SerdeAlbumStatus) -> Self {
value.0
}
}
impl From<AlbumStatus> for SerdeAlbumStatus {
fn from(value: AlbumStatus) -> Self {
SerdeAlbumStatus(value)
}
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(remote = "AlbumPrimaryType")]
pub enum AlbumPrimaryTypeDef {

View File

@ -11,7 +11,7 @@ use crate::{
},
external::database::serde::common::{
MbRefOptionDef, SerdeAlbumDate, SerdeAlbumLibId, SerdeAlbumPrimaryType,
SerdeAlbumSecondaryType,
SerdeAlbumSecondaryType, SerdeAlbumStatus,
},
};
@ -46,6 +46,7 @@ pub struct DeserializeAlbum {
date: SerdeAlbumDate,
seq: u8,
musicbrainz: DeserializeMbRefOption,
status: Option<SerdeAlbumStatus>,
primary_type: Option<SerdeAlbumPrimaryType>,
secondary_types: Vec<SerdeAlbumSecondaryType>,
}
@ -138,7 +139,7 @@ impl From<DeserializeAlbum> for Album {
date: album.date.into(),
seq: AlbumSeq(album.seq),
info: AlbumInfo {
status: None,
status: album.status.map(Into::into),
primary_type: album.primary_type.map(Into::into),
secondary_types: album.secondary_types.into_iter().map(Into::into).collect(),
},

View File

@ -7,7 +7,7 @@ use crate::{
core::collection::{album::Album, artist::Artist, musicbrainz::IMusicBrainzRef, Collection},
external::database::serde::common::{
MbRefOptionDef, SerdeAlbumDate, SerdeAlbumLibId, SerdeAlbumPrimaryType,
SerdeAlbumSecondaryType,
SerdeAlbumSecondaryType, SerdeAlbumStatus,
},
};
@ -38,6 +38,7 @@ pub struct SerializeAlbum<'a> {
date: SerdeAlbumDate,
seq: u8,
musicbrainz: SerializeMbRefOption<'a>,
status: Option<SerdeAlbumStatus>,
primary_type: Option<SerdeAlbumPrimaryType>,
secondary_types: Vec<SerdeAlbumSecondaryType>,
}
@ -97,6 +98,7 @@ impl<'a> From<&'a Album> for SerializeAlbum<'a> {
date: album.meta.date.into(),
seq: album.meta.seq.0,
musicbrainz: (&album.meta.id.mb_ref).into(),
status: album.meta.info.status.map(Into::into),
primary_type: album.meta.info.primary_type.map(Into::into),
secondary_types: album
.meta

View File

@ -1 +1 @@
{"V20250103":[{"name":"Аркона","sort":"Arkona","musicbrainz":{"Some":"baad262d-55ef-427a-83c7-f7530964f212"},"properties":{"Bandcamp":["https://arkonamoscow.bandcamp.com/"],"MusicButler":["https://www.musicbutler.io/artist-page/283448581"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums"]},"albums":[{"title":"Slovo","lib_id":{"Value":7},"date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]}]},{"name":"Eluveitie","sort":null,"musicbrainz":{"Some":"8000598a-5edb-401c-8e6d-36b167feaf38"},"properties":{"MusicButler":["https://www.musicbutler.io/artist-page/269358403"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/eluveitie/download-streaming-albums"]},"albums":[{"title":"Vên [rerecorded]","lib_id":{"Value":1},"date":{"year":2004,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Ep","secondary_types":[]},{"title":"Slania","lib_id":{"Value":2},"date":{"year":2008,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]}]},{"name":"Frontside","sort":null,"musicbrainz":{"Some":"3a901353-fccd-4afd-ad01-9c03f451b490"},"properties":{"MusicButler":["https://www.musicbutler.io/artist-page/826588800"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/frontside/download-streaming-albums"]},"albums":[{"title":"…nasze jest królestwo, potęga i chwała na wieki…","lib_id":{"Value":3},"date":{"year":2001,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]}]},{"name":"Heavens Basement","sort":"Heavens Basement","musicbrainz":{"Some":"c2c4d56a-d599-4a18-bd2f-ae644e2198cc"},"properties":{"MusicButler":["https://www.musicbutler.io/artist-page/291158685"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/heaven-s-basement/download-streaming-albums"]},"albums":[{"title":"Paper Plague","lib_id":"Singleton","date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":null,"secondary_types":[]},{"title":"Unbreakable","lib_id":{"Value":4},"date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]}]},{"name":"Metallica","sort":null,"musicbrainz":{"Some":"65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab"},"properties":{"MusicButler":["https://www.musicbutler.io/artist-page/3996865"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/metallica/download-streaming-albums"]},"albums":[{"title":"Ride the Lightning","lib_id":{"Value":5},"date":{"year":1984,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":[]},{"title":"S&M","lib_id":{"Value":6},"date":{"year":1999,"month":null,"day":null},"seq":0,"musicbrainz":"None","primary_type":"Album","secondary_types":["Live"]}]}]}
{"V20250103":[{"name":"Аркона","sort":"Arkona","musicbrainz":{"Some":"baad262d-55ef-427a-83c7-f7530964f212"},"properties":{"Bandcamp":["https://arkonamoscow.bandcamp.com/"],"MusicButler":["https://www.musicbutler.io/artist-page/283448581"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums"]},"albums":[{"title":"Slovo","lib_id":{"Value":7},"date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]}]},{"name":"Eluveitie","sort":null,"musicbrainz":{"Some":"8000598a-5edb-401c-8e6d-36b167feaf38"},"properties":{"MusicButler":["https://www.musicbutler.io/artist-page/269358403"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/eluveitie/download-streaming-albums"]},"albums":[{"title":"Vên [rerecorded]","lib_id":{"Value":1},"date":{"year":2004,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Ep","secondary_types":[]},{"title":"Slania","lib_id":{"Value":2},"date":{"year":2008,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]}]},{"name":"Frontside","sort":null,"musicbrainz":{"Some":"3a901353-fccd-4afd-ad01-9c03f451b490"},"properties":{"MusicButler":["https://www.musicbutler.io/artist-page/826588800"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/frontside/download-streaming-albums"]},"albums":[{"title":"…nasze jest królestwo, potęga i chwała na wieki…","lib_id":{"Value":3},"date":{"year":2001,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]}]},{"name":"Heavens Basement","sort":"Heavens Basement","musicbrainz":{"Some":"c2c4d56a-d599-4a18-bd2f-ae644e2198cc"},"properties":{"MusicButler":["https://www.musicbutler.io/artist-page/291158685"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/heaven-s-basement/download-streaming-albums"]},"albums":[{"title":"Paper Plague","lib_id":"Singleton","date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":null,"primary_type":null,"secondary_types":[]},{"title":"Unbreakable","lib_id":{"Value":4},"date":{"year":2011,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]}]},{"name":"Metallica","sort":null,"musicbrainz":{"Some":"65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab"},"properties":{"MusicButler":["https://www.musicbutler.io/artist-page/3996865"],"Qobuz":["https://www.qobuz.com/nl-nl/interpreter/metallica/download-streaming-albums"]},"albums":[{"title":"Ride the Lightning","lib_id":{"Value":5},"date":{"year":1984,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":[]},{"title":"S&M","lib_id":{"Value":6},"date":{"year":1999,"month":null,"day":null},"seq":0,"musicbrainz":"None","status":"Official","primary_type":"Album","secondary_types":["Live"]}]}]}