Project started 🥂
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { api } from '../index';
|
||||
import type { Playlist, PlaylistTrack, PaginatedResponse } from '../types';
|
||||
|
||||
export const playlistsApi = api.injectEndpoints({
|
||||
endpoints: (build) => ({
|
||||
getPlaylists: build.query<PaginatedResponse<Playlist>, void>({
|
||||
query: () => '/playlists',
|
||||
providesTags: ['Playlist'],
|
||||
}),
|
||||
getPlaylist: build.query<Playlist, string>({
|
||||
query: (id) => `/playlists/${id}`,
|
||||
providesTags: (_r, _e, id) => [{ type: 'Playlist', id }],
|
||||
}),
|
||||
getPlaylistTracks: build.query<PlaylistTrack[], string>({
|
||||
query: (id) => `/playlists/${id}/tracks`,
|
||||
providesTags: (_r, _e, id) => [{ type: 'Playlist', id }, 'Track'],
|
||||
}),
|
||||
createPlaylist: build.mutation<Playlist, { name: string; description?: string; isPublic?: boolean }>({
|
||||
query: (body) => ({ url: '/playlists', method: 'POST', body }),
|
||||
invalidatesTags: ['Playlist'],
|
||||
}),
|
||||
updatePlaylist: build.mutation<Playlist, { id: string; name?: string; description?: string; isPublic?: boolean }>({
|
||||
query: ({ id, ...body }) => ({ url: `/playlists/${id}`, method: 'PATCH', body }),
|
||||
invalidatesTags: (_r, _e, { id }) => [{ type: 'Playlist', id }],
|
||||
}),
|
||||
deletePlaylist: build.mutation<void, string>({
|
||||
query: (id) => ({ url: `/playlists/${id}`, method: 'DELETE' }),
|
||||
invalidatesTags: ['Playlist'],
|
||||
}),
|
||||
addTrackToPlaylist: build.mutation<void, { playlistId: string; trackId: string }>({
|
||||
query: ({ playlistId, trackId }) => ({ url: `/playlists/${playlistId}/tracks`, method: 'POST', body: { trackId } }),
|
||||
invalidatesTags: (_r, _e, { playlistId }) => [{ type: 'Playlist', id: playlistId }],
|
||||
}),
|
||||
removeTrackFromPlaylist: build.mutation<void, { playlistId: string; trackId: string; position: number }>({
|
||||
query: ({ playlistId, position }) => ({ url: `/playlists/${playlistId}/tracks/${position}`, method: 'DELETE' }),
|
||||
invalidatesTags: (_r, _e, { playlistId }) => [{ type: 'Playlist', id: playlistId }],
|
||||
}),
|
||||
}),
|
||||
overrideExisting: false,
|
||||
});
|
||||
|
||||
export const {
|
||||
useGetPlaylistsQuery,
|
||||
useGetPlaylistQuery,
|
||||
useGetPlaylistTracksQuery,
|
||||
useCreatePlaylistMutation,
|
||||
useUpdatePlaylistMutation,
|
||||
useDeletePlaylistMutation,
|
||||
useAddTrackToPlaylistMutation,
|
||||
useRemoveTrackFromPlaylistMutation,
|
||||
} = playlistsApi;
|
||||
Reference in New Issue
Block a user