refactor: make ids able to be strings, use prefixes
This commit is contained in:
parent
453a496377
commit
d4e68ccbd8
3 changed files with 17 additions and 10 deletions
|
|
@ -31,7 +31,7 @@ pub async fn get_album(
|
||||||
duration: 100,
|
duration: 100,
|
||||||
songs: vec![
|
songs: vec![
|
||||||
Child {
|
Child {
|
||||||
id: 111,
|
id: "tr-111".to_string(),
|
||||||
title: "Example - 1".to_string(),
|
title: "Example - 1".to_string(),
|
||||||
album: Some("Example".to_string()),
|
album: Some("Example".to_string()),
|
||||||
duration: Some(20),
|
duration: Some(20),
|
||||||
|
|
@ -44,7 +44,7 @@ pub async fn get_album(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Child {
|
Child {
|
||||||
id: 112,
|
id: "tr-112".to_string(),
|
||||||
title: "Example - 2".to_string(),
|
title: "Example - 2".to_string(),
|
||||||
album: Some("Example".to_string()),
|
album: Some("Example".to_string()),
|
||||||
duration: Some(20),
|
duration: Some(20),
|
||||||
|
|
@ -57,7 +57,7 @@ pub async fn get_album(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Child {
|
Child {
|
||||||
id: 113,
|
id: "tr-113".to_string(),
|
||||||
title: "Example - 3".to_string(),
|
title: "Example - 3".to_string(),
|
||||||
album: Some("Example".to_string()),
|
album: Some("Example".to_string()),
|
||||||
duration: Some(20),
|
duration: Some(20),
|
||||||
|
|
@ -70,7 +70,7 @@ pub async fn get_album(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Child {
|
Child {
|
||||||
id: 114,
|
id: "tr-114".to_string(),
|
||||||
title: "Example - 4".to_string(),
|
title: "Example - 4".to_string(),
|
||||||
album: Some("Example".to_string()),
|
album: Some("Example".to_string()),
|
||||||
duration: Some(20),
|
duration: Some(20),
|
||||||
|
|
@ -83,7 +83,7 @@ pub async fn get_album(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Child {
|
Child {
|
||||||
id: 115,
|
id: "tr-115".to_string(),
|
||||||
title: "Example - 5".to_string(),
|
title: "Example - 5".to_string(),
|
||||||
album: Some("Example".to_string()),
|
album: Some("Example".to_string()),
|
||||||
duration: Some(20),
|
duration: Some(20),
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ pub async fn get_album_list(
|
||||||
|
|
||||||
let album_list = vec![
|
let album_list = vec![
|
||||||
Child {
|
Child {
|
||||||
id: 11,
|
id: "al-11".to_string(),
|
||||||
parent: Some(1),
|
parent: Some(1),
|
||||||
title: "Example".to_string(),
|
title: "Example".to_string(),
|
||||||
artist: Some("Example".to_string()),
|
artist: Some("Example".to_string()),
|
||||||
|
|
@ -37,7 +37,7 @@ pub async fn get_album_list(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Child {
|
Child {
|
||||||
id: 12,
|
id: "al-12".to_string(),
|
||||||
parent: Some(1),
|
parent: Some(1),
|
||||||
title: "Example 2".to_string(),
|
title: "Example 2".to_string(),
|
||||||
artist: Some("Example 2".to_string()),
|
artist: Some("Example 2".to_string()),
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use poem::{http::StatusCode, IntoResponse, Response};
|
use poem::{http::StatusCode, IntoResponse, Response};
|
||||||
use serde::{ser::SerializeStruct, Serialize};
|
use serde::{ser::SerializeStruct, Serialize, Serializer};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use crate::authentication::VersionTriple;
|
use crate::authentication::VersionTriple;
|
||||||
|
|
@ -99,7 +99,7 @@ pub enum SubResponseType {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Default)]
|
#[derive(Debug, Clone, Serialize, Default)]
|
||||||
pub struct AlbumId3 {
|
pub struct AlbumId3 {
|
||||||
#[serde(rename = "@id")]
|
#[serde(rename = "@id", serialize_with = "album_id")]
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
#[serde(rename = "@parent")]
|
#[serde(rename = "@parent")]
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
@ -127,11 +127,18 @@ pub struct AlbumId3 {
|
||||||
pub songs: Vec<Child>,
|
pub songs: Vec<Child>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||||
|
fn album_id<S: Serializer>(id: &i32, s: S) -> Result<S::Ok, S::Error> {
|
||||||
|
let str = format!("al-{id}");
|
||||||
|
|
||||||
|
s.serialize_str(&str)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Default)]
|
#[derive(Debug, Clone, Serialize, Default)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Child {
|
pub struct Child {
|
||||||
#[serde(rename = "@id")]
|
#[serde(rename = "@id")]
|
||||||
pub id: i32,
|
pub id: String,
|
||||||
#[serde(rename = "@parent", skip_serializing_if = "Option::is_none")]
|
#[serde(rename = "@parent", skip_serializing_if = "Option::is_none")]
|
||||||
pub parent: Option<i32>,
|
pub parent: Option<i32>,
|
||||||
#[serde(rename = "@isDir")]
|
#[serde(rename = "@isDir")]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue