fix intervals not loading and other library issues

This commit is contained in:
Cipher Vance
2026-01-21 19:04:11 -06:00
parent 9c55db2128
commit 35e28590ff
10 changed files with 1558 additions and 666 deletions

View File

@@ -1,72 +1,113 @@
import api from './api'
export const workoutLibraryApi = {
// Browse & Search
async getWorkouts(params = {}) {
const { data } = await api.get('/api/protected/workout-library', { params })
// 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(`/api/protected/workout-library/${workoutId}`)
const { data } = await api.get(`/protected/library/${workoutId}`)
return data
},
async getWorkoutIntervals(workoutId) {
const { data } = await api.get(`/api/protected/workout-library/${workoutId}/intervals`)
return data
},
// User's Workouts
// Get current user's custom workouts
async getUserWorkouts() {
const { data } = await api.get('/api/protected/workouts')
const { data } = await api.get('/protected/library/mine')
return data
},
async createWorkout(workout) {
const { data } = await api.post('/api/protected/workouts', workout)
return data
},
async updateWorkout(workoutId, workout) {
const { data } = await api.put(`/api/protected/workouts/${workoutId}`, workout)
return data
},
async deleteWorkout(workoutId) {
const { data } = await api.delete(`/api/protected/workouts/${workoutId}`)
return data
},
async publishWorkout(workoutId) {
const { data } = await api.post(`/api/protected/workouts/${workoutId}/publish`)
return data
},
// Favorites
// Get user's favorited workouts
async getFavorites() {
const { data } = await api.get('/api/protected/workout-favorites')
const { data } = await api.get('/protected/library/favorites')
return data
},
async addFavorite(workoutId) {
const { data } = await api.post(`/api/protected/workout-favorites/${workoutId}`)
// Create custom workout
async createWorkout(workout) {
const { data } = await api.post('/protected/library', workout)
return data
},
async removeFavorite(workoutId) {
const { data } = await api.delete(`/api/protected/workout-favorites/${workoutId}`)
// Update user's workout
async updateWorkout(workoutId, workout) {
const { data } = await api.put(`/protected/library/${workoutId}`, workout)
return data
},
// Usage & Ratings
// 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(`/api/protected/workout-library/${workoutId}/use`)
const { data } = await api.post(`/protected/library/${workoutId}/use`)
return data
},
async rateWorkout(workoutId, rating) {
const { data } = await api.post(`/api/protected/workout-library/${workoutId}/rate`, { rating })
// 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
}
}