129 lines
3.5 KiB
JavaScript
129 lines
3.5 KiB
JavaScript
import api from './api'
|
|
|
|
export const workoutLibraryApi = {
|
|
// Get workout types, categories, and difficulties
|
|
async getTypes() {
|
|
const { data } = await api.get('/api/protected/library/types')
|
|
return data
|
|
},
|
|
|
|
// Get system-provided workouts
|
|
async getSystemWorkouts() {
|
|
const { data } = await api.get('/api/protected/library/system')
|
|
return data
|
|
},
|
|
|
|
// Browse public workouts (paginated)
|
|
async browseWorkouts(page = 1, pageSize = 20) {
|
|
const { data } = await api.get('/api/protected/library/browse', {
|
|
params: { page, page_size: pageSize }
|
|
})
|
|
return data
|
|
},
|
|
|
|
// Search/filter workouts
|
|
async searchWorkouts(params = {}) {
|
|
const { data } = await api.get('/api/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(`/api/protected/library/type/${type}`)
|
|
return data
|
|
},
|
|
|
|
// Get workouts by category
|
|
async getWorkoutsByCategory(category) {
|
|
const { data } = await api.get(`/api/protected/library/category/${category}`)
|
|
return data
|
|
},
|
|
|
|
// Get single workout details
|
|
async getWorkout(workoutId) {
|
|
const { data } = await api.get(`/api/protected/library/${workoutId}`)
|
|
return data
|
|
},
|
|
|
|
// Get current user's custom workouts
|
|
async getUserWorkouts() {
|
|
const { data } = await api.get('/api/protected/library/mine')
|
|
return data
|
|
},
|
|
|
|
// Get user's favorited workouts
|
|
async getFavorites() {
|
|
const { data } = await api.get('/api/protected/library/favorites')
|
|
return data
|
|
},
|
|
|
|
// Create custom workout
|
|
async createWorkout(workout) {
|
|
const { data } = await api.post('/api/protected/library', workout)
|
|
return data
|
|
},
|
|
|
|
// Update user's workout
|
|
async updateWorkout(workoutId, workout) {
|
|
const { data } = await api.put(`/api/protected/library/${workoutId}`, workout)
|
|
return data
|
|
},
|
|
|
|
// Delete user's workout
|
|
async deleteWorkout(workoutId) {
|
|
const { data } = await api.delete(`/api/protected/library/${workoutId}`)
|
|
return data
|
|
},
|
|
|
|
// Mark workout as used
|
|
async recordUsage(workoutId) {
|
|
const { data } = await api.post(`/api/protected/library/${workoutId}/use`)
|
|
return data
|
|
},
|
|
|
|
// Add to favorites
|
|
async addFavorite(workoutId) {
|
|
const { data } = await api.post(`/api/protected/library/${workoutId}/favorite`)
|
|
return data
|
|
},
|
|
|
|
// Remove from favorites
|
|
async removeFavorite(workoutId) {
|
|
const { data } = await api.delete(`/api/protected/library/${workoutId}/favorite`)
|
|
return data
|
|
},
|
|
|
|
// Rate workout (1-5 stars + optional comment)
|
|
async rateWorkout(workoutId, rating, comment = null) {
|
|
const { data } = await api.post(`/api/protected/library/${workoutId}/rate`, {
|
|
rating,
|
|
comment: comment || undefined
|
|
})
|
|
return data
|
|
},
|
|
|
|
// Schedule a library workout to a specific date
|
|
async scheduleToCalendar(workout, scheduledDate) {
|
|
const { data } = await api.post('/api/protected/workouts/schedule-template', {
|
|
template_id: workout.id,
|
|
template_name: workout.name,
|
|
template_type: workout.type,
|
|
duration: workout.duration,
|
|
scheduled_date: scheduledDate,
|
|
workout_data: workout.structure || null
|
|
})
|
|
return data
|
|
}
|
|
}
|
|
|
|
export default workoutLibraryApi
|