commands: add response types for multiple commands

This commit is contained in:
2025-12-08 00:44:37 +09:00
parent 9dd97c869c
commit 7844b68a1b
7 changed files with 84 additions and 8 deletions

View File

@@ -1,4 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::{
Uri,
commands::{Command, CommandResponse, ResponseParserError, empty_command_request},
response_tokenizer::ResponseAttributes,
};
@@ -7,7 +10,8 @@ pub struct Playlist;
empty_command_request!(Playlist, "playlist");
pub struct PlaylistResponse();
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaylistResponse(Vec<Uri>);
impl CommandResponse<'_> for PlaylistResponse {
fn into_response_enum(self) -> crate::Response {

View File

@@ -1,10 +1,12 @@
use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, CommandRequest, RequestParserError, empty_command_response},
DbSongInfo, Priority, Response, SongId, SongPosition,
commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError},
common::types::{Sort, WindowRange},
filter::Filter,
request_tokenizer::RequestTokenizer,
response_tokenizer::ResponseAttributes,
};
pub struct PlaylistFind;
@@ -83,7 +85,30 @@ impl CommandRequest<'_> for PlaylistFindRequest {
}
}
empty_command_response!(PlaylistFind);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaylistFindResponse(Vec<PlaylistFindResponseEntry>);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaylistFindResponseEntry {
pub position: SongPosition,
pub id: SongId,
pub priority: Option<Priority>,
pub song_info: DbSongInfo,
}
impl CommandResponse<'_> for PlaylistFindResponse {
fn into_response_enum(self) -> Response {
todo!()
}
fn from_response_enum(response: Response) -> Option<Self> {
todo!()
}
fn parse(_parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError<'_>> {
unimplemented!()
}
}
impl Command<'_, '_> for PlaylistFind {
type Request = PlaylistFindRequest;

View File

@@ -1,4 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::{
DbSongInfo, Priority, SongPosition,
commands::{Command, CommandResponse, ResponseParserError, single_item_command_request},
common::types::SongId,
response_tokenizer::ResponseAttributes,
@@ -8,7 +11,16 @@ pub struct PlaylistId;
single_item_command_request!(PlaylistId, "playlistid", SongId);
pub struct PlaylistIdResponse();
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaylistIdResponse(Vec<PlaylistIdResponseEntry>);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaylistIdResponseEntry {
pub position: SongPosition,
pub id: SongId,
pub priority: Option<Priority>,
pub song_info: DbSongInfo,
}
impl CommandResponse<'_> for PlaylistIdResponse {
fn into_response_enum(self) -> crate::Response {

View File

@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::{
DbSongInfo, Priority, SongId, SongPosition,
commands::{
Command, CommandResponse, RequestParserError, ResponseParserError,
single_optional_item_command_request,
@@ -14,7 +15,15 @@ pub struct PlaylistInfo;
single_optional_item_command_request!(PlaylistInfo, "playlistinfo", OneOrRange);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaylistInfoResponse;
pub struct PlaylistInfoResponse(Vec<PlaylistInfoResponseEntry>);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaylistInfoResponseEntry {
pub position: SongPosition,
pub id: SongId,
pub priority: Option<Priority>,
pub song_info: DbSongInfo,
}
impl CommandResponse<'_> for PlaylistInfoResponse {
fn into_response_enum(self) -> crate::Response {

View File

@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::{
DbSongInfo, Priority, SongId, SongPosition,
commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError},
common::types::{Sort, WindowRange},
filter::Filter,
@@ -85,7 +86,15 @@ impl CommandRequest<'_> for PlaylistSearchRequest {
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaylistSearchResponse;
pub struct PlaylistSearchResponse(Vec<PlaylistSearchResponseEntry>);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaylistSearchResponseEntry {
pub position: SongPosition,
pub id: SongId,
pub priority: Option<Priority>,
pub song_info: DbSongInfo,
}
impl CommandResponse<'_> for PlaylistSearchResponse {
fn from_response_enum(response: crate::Response) -> Option<Self> {

View File

@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::{
DbSongInfo, Priority, SongId, SongPosition,
commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError},
common::types::{PlaylistVersion, WindowRange},
request_tokenizer::RequestTokenizer,
@@ -59,7 +60,15 @@ impl CommandRequest<'_> for PlChangesRequest {
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlChangesResponse;
pub struct PlChangesResponse(Vec<PlChangesResponseEntry>);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlChangesResponseEntry {
pub position: SongPosition,
pub id: SongId,
pub priority: Option<Priority>,
pub song_info: DbSongInfo,
}
impl CommandResponse<'_> for PlChangesResponse {
fn from_response_enum(response: crate::Response) -> Option<Self> {

View File

@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::{
SongId, SongPosition,
commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError},
common::types::{PlaylistVersion, WindowRange},
request_tokenizer::RequestTokenizer,
@@ -59,7 +60,14 @@ impl CommandRequest<'_> for PlChangesPosIdRequest {
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlChangesPosIdResponse;
pub struct PlChangesPosIdResponse(Vec<PlChangesPosIdResponseEntry>);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlChangesPosIdResponseEntry {
// 'cpos'
pub position: SongPosition,
pub id: SongId,
}
impl CommandResponse<'_> for PlChangesPosIdResponse {
fn from_response_enum(response: crate::Response) -> Option<Self> {