Add create/update playlist mutations and form

This commit is contained in:
jeffvli 2022-12-31 12:40:11 -08:00
parent 82f107d835
commit 88f53c17db
11 changed files with 409 additions and 145 deletions

View file

@ -33,6 +33,8 @@ import type {
PlaylistSongListArgs,
ArtistListArgs,
RawArtistListResponse,
UpdatePlaylistArgs,
RawUpdatePlaylistResponse,
} from '/@/renderer/api/types';
import { subsonicApi } from '/@/renderer/api/subsonic.api';
import { jellyfinApi } from '/@/renderer/api/jellyfin.api';
@ -60,7 +62,7 @@ export type ControllerEndpoint = Partial<{
getPlaylistSongList: (args: PlaylistSongListArgs) => Promise<RawSongListResponse>;
getSongDetail: (args: SongDetailArgs) => Promise<RawSongDetailResponse>;
getSongList: (args: SongListArgs) => Promise<RawSongListResponse>;
updatePlaylist: () => void;
updatePlaylist: (args: UpdatePlaylistArgs) => Promise<RawUpdatePlaylistResponse>;
updateRating: (args: RatingArgs) => Promise<RawRatingResponse>;
}>;
@ -120,7 +122,7 @@ const endpoints: ApiController = {
getPlaylistSongList: navidromeApi.getPlaylistSongList,
getSongDetail: navidromeApi.getSongDetail,
getSongList: navidromeApi.getSongList,
updatePlaylist: undefined,
updatePlaylist: navidromeApi.updatePlaylist,
updateRating: subsonicApi.updateRating,
},
subsonic: {
@ -203,7 +205,16 @@ const getPlaylistList = async (args: PlaylistListArgs) => {
return (apiController('getPlaylistList') as ControllerEndpoint['getPlaylistList'])?.(args);
};
const createPlaylist = async (args: CreatePlaylistArgs) => {
return (apiController('createPlaylist') as ControllerEndpoint['createPlaylist'])?.(args);
};
const updatePlaylist = async (args: UpdatePlaylistArgs) => {
return (apiController('updatePlaylist') as ControllerEndpoint['updatePlaylist'])?.(args);
};
export const controller = {
createPlaylist,
getAlbumArtistList,
getAlbumDetail,
getAlbumList,
@ -212,4 +223,5 @@ export const controller = {
getMusicFolderList,
getPlaylistList,
getSongList,
updatePlaylist,
};

View file

@ -32,6 +32,8 @@ import type {
NDSongListResponse,
NDAlbumArtist,
NDPlaylist,
NDUpdatePlaylistParams,
NDUpdatePlaylistResponse,
} from '/@/renderer/api/navidrome.types';
import { NDPlaylistListSort, NDSongListSort, NDSortOrder } from '/@/renderer/api/navidrome.types';
import type {
@ -53,6 +55,8 @@ import type {
PlaylistSongListArgs,
AlbumArtist,
Playlist,
UpdatePlaylistResponse,
UpdatePlaylistArgs,
} from '/@/renderer/api/types';
import {
playlistListSortMap,
@ -286,7 +290,7 @@ const getSongDetail = async (args: SongDetailArgs): Promise<NDSongDetail> => {
};
const createPlaylist = async (args: CreatePlaylistArgs): Promise<CreatePlaylistResponse> => {
const { query, server, signal } = args;
const { query, server } = args;
const json: NDCreatePlaylistParams = {
comment: query.comment,
@ -299,7 +303,6 @@ const createPlaylist = async (args: CreatePlaylistArgs): Promise<CreatePlaylistR
headers: { 'x-nd-authorization': `Bearer ${server?.ndCredential}` },
json,
prefixUrl: server?.url,
signal,
})
.json<NDCreatePlaylistResponse>();
@ -309,6 +312,33 @@ const createPlaylist = async (args: CreatePlaylistArgs): Promise<CreatePlaylistR
};
};
const updatePlaylist = async (args: UpdatePlaylistArgs): Promise<UpdatePlaylistResponse> => {
const { query, server, signal } = args;
const previous = query.previous as NDPlaylist;
const json: NDUpdatePlaylistParams = {
...previous,
comment: query.comment || '',
name: query.name,
public: query.public || false,
};
const data = await api
.post(`api/playlist/${previous.id}`, {
headers: { 'x-nd-authorization': `Bearer ${server?.ndCredential}` },
json,
prefixUrl: server?.url,
signal,
})
.json<NDUpdatePlaylistResponse>();
return {
id: data.id,
name: query.name,
};
};
const deletePlaylist = async (args: DeletePlaylistArgs): Promise<NDDeletePlaylist> => {
const { query, server, signal } = args;
@ -552,6 +582,7 @@ export const navidromeApi = {
getPlaylistSongList,
getSongDetail,
getSongList,
updatePlaylist,
};
export const ndNormalize = {

View file

@ -259,7 +259,8 @@ export type NDAlbumArtistListParams = {
export type NDCreatePlaylistParams = {
comment?: string;
name: string;
public: boolean;
public?: boolean;
rules?: Record<string, any> | null;
};
export type NDCreatePlaylistResponse = {
@ -268,6 +269,10 @@ export type NDCreatePlaylistResponse = {
export type NDCreatePlaylist = NDCreatePlaylistResponse;
export type NDUpdatePlaylistParams = NDPlaylist;
export type NDUpdatePlaylistResponse = NDPlaylist;
export type NDDeletePlaylistParams = {
id: string;
};

View file

@ -120,16 +120,6 @@ export interface BasePaginatedResponse<T> {
totalRecordCount: number;
}
export type ApiError = {
error: {
message: string;
path: string;
trace: string[];
};
response: string;
statusCode: number;
};
export type AuthenticationResponse = {
credential: string;
ndCredential?: string;
@ -740,10 +730,30 @@ export type RawCreatePlaylistResponse = CreatePlaylistResponse | undefined;
export type CreatePlaylistResponse = { id: string; name: string };
export type CreatePlaylistQuery = { comment?: string; name: string; public?: boolean };
export type CreatePlaylistQuery = {
comment?: string;
name: string;
public?: boolean;
rules?: Record<string, any>;
};
export type CreatePlaylistArgs = { query: CreatePlaylistQuery } & BaseEndpointArgs;
// Update Playlist
export type RawUpdatePlaylistResponse = UpdatePlaylistResponse | undefined;
export type UpdatePlaylistResponse = { id: string; name: string };
export type UpdatePlaylistQuery = {
comment?: string;
name: string;
previous: RawPlaylistDetailResponse;
public?: boolean;
rules?: Record<string, any>;
};
export type UpdatePlaylistArgs = { query: UpdatePlaylistQuery } & BaseEndpointArgs;
// Delete Playlist
export type RawDeletePlaylistResponse = NDDeletePlaylist | undefined;