112 lines
2.9 KiB
TypeScript
112 lines
2.9 KiB
TypeScript
import { apiClient } from '../client'
|
|
|
|
export interface Favorite {
|
|
id: number
|
|
user_id: number
|
|
sound_id?: number
|
|
playlist_id?: number
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
export interface FavoriteCountsResponse {
|
|
total: number
|
|
sounds: number
|
|
playlists: number
|
|
}
|
|
|
|
export interface FavoritesListResponse {
|
|
favorites: Favorite[]
|
|
}
|
|
|
|
export class FavoritesService {
|
|
/**
|
|
* Add a sound to favorites
|
|
*/
|
|
async addSoundFavorite(soundId: number): Promise<Favorite> {
|
|
const response = await apiClient.post<Favorite>(`/api/v1/favorites/sounds/${soundId}`)
|
|
return response
|
|
}
|
|
|
|
/**
|
|
* Remove a sound from favorites
|
|
*/
|
|
async removeSoundFavorite(soundId: number): Promise<void> {
|
|
await apiClient.delete(`/api/v1/favorites/sounds/${soundId}`)
|
|
}
|
|
|
|
/**
|
|
* Add a playlist to favorites
|
|
*/
|
|
async addPlaylistFavorite(playlistId: number): Promise<Favorite> {
|
|
const response = await apiClient.post<Favorite>(`/api/v1/favorites/playlists/${playlistId}`)
|
|
return response
|
|
}
|
|
|
|
/**
|
|
* Remove a playlist from favorites
|
|
*/
|
|
async removePlaylistFavorite(playlistId: number): Promise<void> {
|
|
await apiClient.delete(`/api/v1/favorites/playlists/${playlistId}`)
|
|
}
|
|
|
|
/**
|
|
* Get all favorites for the current user
|
|
*/
|
|
async getFavorites(limit = 50, offset = 0): Promise<Favorite[]> {
|
|
const response = await apiClient.get<FavoritesListResponse>(
|
|
`/api/v1/favorites/?limit=${limit}&offset=${offset}`
|
|
)
|
|
return response.favorites
|
|
}
|
|
|
|
/**
|
|
* Get sound favorites for the current user
|
|
*/
|
|
async getSoundFavorites(limit = 50, offset = 0): Promise<Favorite[]> {
|
|
const response = await apiClient.get<FavoritesListResponse>(
|
|
`/api/v1/favorites/sounds?limit=${limit}&offset=${offset}`
|
|
)
|
|
return response.favorites
|
|
}
|
|
|
|
/**
|
|
* Get playlist favorites for the current user
|
|
*/
|
|
async getPlaylistFavorites(limit = 50, offset = 0): Promise<Favorite[]> {
|
|
const response = await apiClient.get<FavoritesListResponse>(
|
|
`/api/v1/favorites/playlists?limit=${limit}&offset=${offset}`
|
|
)
|
|
return response.favorites
|
|
}
|
|
|
|
/**
|
|
* Get favorite counts for the current user
|
|
*/
|
|
async getFavoriteCounts(): Promise<FavoriteCountsResponse> {
|
|
const response = await apiClient.get<FavoriteCountsResponse>('/api/v1/favorites/counts')
|
|
return response
|
|
}
|
|
|
|
/**
|
|
* Check if a sound is favorited
|
|
*/
|
|
async isSoundFavorited(soundId: number): Promise<boolean> {
|
|
const response = await apiClient.get<{ is_favorited: boolean }>(
|
|
`/api/v1/favorites/sounds/${soundId}/check`
|
|
)
|
|
return response.is_favorited
|
|
}
|
|
|
|
/**
|
|
* Check if a playlist is favorited
|
|
*/
|
|
async isPlaylistFavorited(playlistId: number): Promise<boolean> {
|
|
const response = await apiClient.get<{ is_favorited: boolean }>(
|
|
`/api/v1/favorites/playlists/${playlistId}/check`
|
|
)
|
|
return response.is_favorited
|
|
}
|
|
}
|
|
|
|
export const favoritesService = new FavoritesService() |