progress
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ExerciseResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->display_name,
|
||||
'original_name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'gif_url' => $this->gif_url,
|
||||
'poster_url' => $this->poster_url,
|
||||
'instructions' => $this->instructions,
|
||||
'body_parts' => $this->whenLoaded('bodyParts', fn () => $this->bodyParts->map(fn ($m) => [
|
||||
'id' => $m->id, 'name' => $m->name, 'slug' => $m->slug,
|
||||
])),
|
||||
'target_muscles' => $this->whenLoaded('targetMuscles', fn () => $this->targetMuscles->map(fn ($m) => [
|
||||
'id' => $m->id, 'name' => $m->name, 'slug' => $m->slug,
|
||||
])),
|
||||
'secondary_muscles' => $this->whenLoaded('secondaryMuscles', fn () => $this->secondaryMuscles->map(fn ($m) => [
|
||||
'id' => $m->id, 'name' => $m->name, 'slug' => $m->slug,
|
||||
])),
|
||||
'equipments' => $this->whenLoaded('equipments', fn () => $this->equipments->map(fn ($m) => [
|
||||
'id' => $m->id, 'name' => $m->name, 'slug' => $m->slug,
|
||||
])),
|
||||
'is_favorited' => $request->user()
|
||||
? $request->user()->favoriteExercises()->where('exercise_id', $this->id)->exists()
|
||||
: false,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProgramResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user_id' => $this->user_id,
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'weeks' => $this->weeks,
|
||||
'workouts_count' => $this->whenCounted('workouts'),
|
||||
'workouts' => WorkoutResource::collection($this->whenLoaded('workouts')),
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'is_trainer' => (bool) $this->is_trainer,
|
||||
'is_admin' => (bool) $this->is_admin,
|
||||
'age' => $this->age,
|
||||
'weight_kg' => $this->weight_kg !== null ? (float) $this->weight_kg : null,
|
||||
'height_cm' => $this->height_cm !== null ? (float) $this->height_cm : null,
|
||||
'fitness_level' => $this->fitness_level,
|
||||
'goal' => $this->goal,
|
||||
'health_notes' => $this->health_notes,
|
||||
'available_equipment' => $this->available_equipment,
|
||||
'days_per_week' => $this->days_per_week,
|
||||
'minutes_per_session' => $this->minutes_per_session,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WeightLogResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'weight_kg' => (float) $this->weight_kg,
|
||||
'logged_at' => $this->logged_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WorkoutExerciseResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'workout_id' => $this->workout_id,
|
||||
'position' => $this->position,
|
||||
'sets' => $this->sets,
|
||||
'reps' => $this->reps,
|
||||
'weight' => $this->weight !== null ? (float) $this->weight : null,
|
||||
'rest_seconds' => $this->rest_seconds,
|
||||
'notes' => $this->notes,
|
||||
'exercise' => new ExerciseResource($this->whenLoaded('exercise')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WorkoutResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user_id' => $this->user_id,
|
||||
'owner' => new UserResource($this->whenLoaded('user')),
|
||||
'title' => $this->title,
|
||||
'notes' => $this->notes,
|
||||
'estimated_minutes' => $this->estimated_minutes,
|
||||
'is_public' => (bool) $this->is_public,
|
||||
'program_id' => $this->program_id,
|
||||
'week_number' => $this->week_number,
|
||||
'day_number' => $this->day_number,
|
||||
'assigned_by_trainer_id' => $this->assigned_by_trainer_id,
|
||||
'assigned_by_trainer' => new UserResource($this->whenLoaded('assignedByTrainer')),
|
||||
'items' => WorkoutExerciseResource::collection($this->whenLoaded('items')),
|
||||
'is_favorited' => $request->user()
|
||||
? $request->user()->favoriteWorkouts()->where('workout_id', $this->id)->exists()
|
||||
: false,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WorkoutSessionItemResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'session_id' => $this->session_id,
|
||||
'workout_exercise_id' => $this->workout_exercise_id,
|
||||
'done' => (bool) $this->done,
|
||||
'actual_weight' => $this->actual_weight !== null ? (float) $this->actual_weight : null,
|
||||
'actual_reps' => $this->actual_reps,
|
||||
'exercise_ms' => $this->exercise_ms,
|
||||
'rest_ms' => $this->rest_ms,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WorkoutSessionResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user_id' => $this->user_id,
|
||||
'workout_id' => $this->workout_id,
|
||||
'workout' => new WorkoutResource($this->whenLoaded('workout')),
|
||||
'started_at' => $this->started_at,
|
||||
'completed_at' => $this->completed_at,
|
||||
'items' => WorkoutSessionItemResource::collection($this->whenLoaded('items')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class YogaPoseResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'slug' => $this->slug,
|
||||
'english_name' => $this->english_name,
|
||||
'sanskrit_name' => $this->sanskrit_name,
|
||||
'sanskrit_name_adapted' => $this->sanskrit_name_adapted,
|
||||
'translation_name' => $this->translation_name,
|
||||
'description' => $this->description,
|
||||
'benefits' => $this->benefits,
|
||||
'url_svg' => $this->url_svg,
|
||||
'url_png' => $this->url_png,
|
||||
'url_svg_alt' => $this->url_svg_alt,
|
||||
'category' => $this->whenLoaded('category', fn () => [
|
||||
'id' => $this->category->id,
|
||||
'name' => $this->category->name,
|
||||
]),
|
||||
'is_favorited' => $request->user()
|
||||
? $request->user()->favoriteYogaPoses()->where('yoga_pose_id', $this->id)->exists()
|
||||
: false,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user