From 8dbdb24ad6e7beda0fe943f1caf00b03d62dbe61 Mon Sep 17 00:00:00 2001 From: Kevin ANATOLE Date: Sun, 26 Apr 2020 20:33:09 +0100 Subject: [PATCH] Created exercises - Added endpoint to retrieve the list of exercises --- app/Exercise.php | 39 +++++++++++++++++++ app/Http/Controllers/ExerciseController.php | 18 +++++++++ .../2014_10_12_000000_create_users_table.php | 6 +-- ...20_04_26_162929_create_exercises_table.php | 32 +++++++++++++++ database/seeds/ExerciseSeeder.php | 27 +++++++++++++ routes/api.php | 4 ++ 6 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 app/Exercise.php create mode 100644 app/Http/Controllers/ExerciseController.php create mode 100644 database/migrations/2020_04_26_162929_create_exercises_table.php create mode 100644 database/seeds/ExerciseSeeder.php diff --git a/app/Exercise.php b/app/Exercise.php new file mode 100644 index 0000000..a350562 --- /dev/null +++ b/app/Exercise.php @@ -0,0 +1,39 @@ +name; + } + + /** + * @param string $name + */ + public function setName(string $name): void + { + $this->name = $name; + } +} diff --git a/app/Http/Controllers/ExerciseController.php b/app/Http/Controllers/ExerciseController.php new file mode 100644 index 0000000..a91de73 --- /dev/null +++ b/app/Http/Controllers/ExerciseController.php @@ -0,0 +1,18 @@ +json(Exercise::all()); + } +} diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 621a24e..4e766e7 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -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(); }); diff --git a/database/migrations/2020_04_26_162929_create_exercises_table.php b/database/migrations/2020_04_26_162929_create_exercises_table.php new file mode 100644 index 0000000..e08c0a0 --- /dev/null +++ b/database/migrations/2020_04_26_162929_create_exercises_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name')->nullable(false)->unique(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('exercises'); + } +} diff --git a/database/seeds/ExerciseSeeder.php b/database/seeds/ExerciseSeeder.php new file mode 100644 index 0000000..bc2af8f --- /dev/null +++ b/database/seeds/ExerciseSeeder.php @@ -0,0 +1,27 @@ + $exercise]); + } + } +} diff --git a/routes/api.php b/routes/api.php index bcb8b18..9af0251 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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'); +});