116 lines
3.0 KiB
JavaScript
116 lines
3.0 KiB
JavaScript
import api from './api'
|
|
|
|
export const workoutLibraryApi = {
|
|
// Get workout types, categories, and difficulties
|
|
async getTypes() {
|
|
const { data } = await api.get('/protected/library/types')
|
|
return data
|
|
},
|
|
|
|
// Get system-provided workouts
|
|
async getSystemWorkouts() {
|
|
const { data } = await api.get('/protected/library/system')
|
|
return data
|
|
},
|
|
|
|
// Browse public workouts (paginated)
|
|
async browseWorkouts(page = 1, pageSize = 20) {
|
|
const { data } = await api.get('/protected/library/browse', {
|
|
params: { page, page_size: pageSize }
|
|
})
|
|
return data
|
|
},
|
|
|
|
// Search/filter workouts
|
|
async searchWorkouts(params = {}) {
|
|
const { data } = await api.get('/protected/library/search', {
|
|
params: {
|
|
q: params.search || undefined,
|
|
type: params.type || undefined,
|
|
category: params.category || undefined,
|
|
difficulty: params.difficulty || undefined,
|
|
page: params.page || 1,
|
|
page_size: params.pageSize || 20
|
|
}
|
|
})
|
|
return data
|
|
},
|
|
|
|
// Get workouts by type
|
|
async getWorkoutsByType(type) {
|
|
const { data } = await api.get(`/protected/library/type/${type}`)
|
|
return data
|
|
},
|
|
|
|
// Get workouts by category
|
|
async getWorkoutsByCategory(category) {
|
|
const { data } = await api.get(`/protected/library/category/${category}`)
|
|
return data
|
|
},
|
|
|
|
// Get single workout details
|
|
async getWorkout(workoutId) {
|
|
const { data } = await api.get(`/protected/library/${workoutId}`)
|
|
return data
|
|
},
|
|
|
|
// Get current user's custom workouts
|
|
async getUserWorkouts() {
|
|
const { data } = await api.get('/protected/library/mine')
|
|
return data
|
|
},
|
|
|
|
// Get user's favorited workouts
|
|
async getFavorites() {
|
|
const { data } = await api.get('/protected/library/favorites')
|
|
return data
|
|
},
|
|
|
|
// Create custom workout
|
|
async createWorkout(workout) {
|
|
const { data } = await api.post('/protected/library', workout)
|
|
return data
|
|
},
|
|
|
|
// Update user's workout
|
|
async updateWorkout(workoutId, workout) {
|
|
const { data } = await api.put(`/protected/library/${workoutId}`, workout)
|
|
return data
|
|
},
|
|
|
|
// Delete user's workout
|
|
async deleteWorkout(workoutId) {
|
|
const { data } = await api.delete(`/protected/library/${workoutId}`)
|
|
return data
|
|
},
|
|
|
|
// Mark workout as used
|
|
async recordUsage(workoutId) {
|
|
const { data } = await api.post(`/protected/library/${workoutId}/use`)
|
|
return data
|
|
},
|
|
|
|
// Add to favorites
|
|
async addFavorite(workoutId) {
|
|
const { data } = await api.post(`/protected/library/${workoutId}/favorite`)
|
|
return data
|
|
},
|
|
|
|
// Remove from favorites
|
|
async removeFavorite(workoutId) {
|
|
const { data } = await api.delete(`/protected/library/${workoutId}/favorite`)
|
|
return data
|
|
},
|
|
|
|
// Rate workout (1-5 stars + optional comment)
|
|
async rateWorkout(workoutId, rating, comment = null) {
|
|
const { data } = await api.post(`/protected/library/${workoutId}/rate`, {
|
|
rating,
|
|
comment: comment || undefined
|
|
})
|
|
return data
|
|
}
|
|
}
|
|
|
|
export default workoutLibraryApi
|