mirror of
https://github.com/kevin-DL/exercise_tracker_api.git
synced 2026-01-11 19:14:27 +00:00
Created exercises
- Added endpoint to retrieve the list of exercises
This commit is contained in:
39
app/Exercise.php
Normal file
39
app/Exercise.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Exercise extends Model
|
||||
{
|
||||
/**
|
||||
* The name of the exercise
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
18
app/Http/Controllers/ExerciseController.php
Normal file
18
app/Http/Controllers/ExerciseController.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Exercise;
|
||||
|
||||
class ExerciseController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get the list of exercises
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index() {
|
||||
return response()->json(Exercise::all());
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,10 @@ class CreateUsersTable extends Migration
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->string('username')->unique()->nullable(false);
|
||||
$table->string('email')->unique()->nullable(false);
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->string('password')->nullable(false);
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateExercisesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('exercises', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->nullable(false)->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('exercises');
|
||||
}
|
||||
}
|
||||
27
database/seeds/ExerciseSeeder.php
Normal file
27
database/seeds/ExerciseSeeder.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use App\Exercise;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ExerciseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$exercises = [
|
||||
'BENT OVER HIGH ROWS', 'LOW PULL APARTS', 'BENT OVER LOW ROWS', 'ARCHER PULLS',
|
||||
'PUSH-UP w/ BAND', 'REVERSE GRIP FLYE', 'WRAPAROUND MOST MUSCULAR', 'WRAPAROUND PRESS', 'REVERSE CRUNCHES',
|
||||
'STANDING BICEPS CURLS', 'SINGLE-ARM CONCENTRATION CURLS', 'SINGLE-ARM OVERHEAD EXTENSIONS', 'SINGLE-ARM KICKBACKS',
|
||||
'STANDING SINGLE-ARM PRESS', 'SINGLE-ARM LATERAL RAISE', 'HIGH PULL APARTS', 'FRONT RAISES',
|
||||
'OVERHEAD SQUAT', 'SINGLE LEG SQUAT', 'STIFF LEG DEADLIFT', 'SINGLE LEG CALF RAISE'
|
||||
];
|
||||
|
||||
foreach ($exercises as $exercise) {
|
||||
Exercise::create(['name' => $exercise]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,3 +17,7 @@ use Illuminate\Support\Facades\Route;
|
||||
Route::middleware('auth:api')->get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
|
||||
Route::prefix('exercises')->group(function () {
|
||||
Route::get('', 'ExerciseController@index');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user