commands/currentsong: implement response parser
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
DbSongInfo, Priority, SongId, SongPosition,
|
||||
commands::{Command, CommandResponse, ResponseParserError, empty_command_request},
|
||||
response_tokenizer::ResponseAttributes,
|
||||
response_tokenizer::{
|
||||
ResponseAttributes, get_and_parse_optional_property, get_and_parse_property,
|
||||
},
|
||||
};
|
||||
|
||||
/// Displays the song info of the current song (same song that is identified in status)
|
||||
@@ -10,8 +15,13 @@ pub struct CurrentSong;
|
||||
|
||||
empty_command_request!(CurrentSong, "currentsong");
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct CurrentSongResponse {}
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct CurrentSongResponse {
|
||||
position: SongPosition,
|
||||
id: SongId,
|
||||
priority: Option<Priority>,
|
||||
song_info: DbSongInfo,
|
||||
}
|
||||
|
||||
impl CommandResponse<'_> for CurrentSongResponse {
|
||||
fn into_response_enum(self) -> crate::Response {
|
||||
@@ -23,7 +33,24 @@ impl CommandResponse<'_> for CurrentSongResponse {
|
||||
}
|
||||
|
||||
fn parse(parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError<'_>> {
|
||||
unimplemented!()
|
||||
let mut parts: HashMap<_, _> = parts.into_map()?;
|
||||
|
||||
let position: SongPosition = get_and_parse_property!(parts, "Pos", Text);
|
||||
let id: SongId = get_and_parse_property!(parts, "Id", Text);
|
||||
let priority: Option<Priority> = get_and_parse_optional_property!(parts, "Prio", Text);
|
||||
|
||||
parts.remove("Pos");
|
||||
parts.remove("Id");
|
||||
parts.remove("Prio");
|
||||
|
||||
let song_info = DbSongInfo::parse_map(parts)?;
|
||||
|
||||
Ok(CurrentSongResponse {
|
||||
position,
|
||||
id,
|
||||
priority,
|
||||
song_info,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user