diff options
author | Camil Staps | 2015-02-21 13:45:31 +0100 |
---|---|---|
committer | Camil Staps | 2015-02-21 13:45:31 +0100 |
commit | 1608adfa7bfbf027bddffe4051637bf65ce03622 (patch) | |
tree | 32bf7e57e2cb0b015a1a479e5bd2deb2664e8948 /src | |
parent | added migrations, created basic app relying on dingo (diff) |
Basic controllers and authentication
Diffstat (limited to 'src')
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Bot.php | 10 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php | 9 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/User.php | 10 | ||||
-rw-r--r-- | src/controllers/BaseController.php | 10 | ||||
-rw-r--r-- | src/controllers/BotController.php | 18 | ||||
-rw-r--r-- | src/controllers/UploadController.php | 10 | ||||
-rw-r--r-- | src/controllers/UserController.php | 18 | ||||
-rw-r--r-- | src/migrations/2015_02_20_210536_create_users.php (renamed from src/migrations/2015_02_20_210536_create_user.php) | 10 | ||||
-rw-r--r-- | src/migrations/2015_02_20_211306_create_games.php (renamed from src/migrations/2015_02_20_211306_create_game.php) | 6 | ||||
-rw-r--r-- | src/migrations/2015_02_20_211317_create_bots.php (renamed from src/migrations/2015_02_20_211317_create_bot.php) | 13 | ||||
-rw-r--r-- | src/routes.php | 5 |
11 files changed, 94 insertions, 25 deletions
diff --git a/src/CamilStaps/BotleaguesApi/Bot.php b/src/CamilStaps/BotleaguesApi/Bot.php new file mode 100644 index 0000000..f45ada7 --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Bot.php @@ -0,0 +1,10 @@ +<?php +namespace CamilStaps\BotleaguesApi; + +use Illuminate\Database\Eloquent\Model; + +class Bot extends Model { + + + +}
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php b/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php index b1af77f..76debfd 100644 --- a/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php +++ b/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php @@ -1,7 +1,10 @@ <?php namespace CamilStaps\BotleaguesApi; -use Illuminate\Support\ServiceProvider; +use \Illuminate\Support\ServiceProvider; +use \Illuminate\Database\Eloquent\ModelNotFoundException; +use \Dingo\Api\Facade\API; +use Response; class BotleaguesApiServiceProvider extends ServiceProvider { @@ -21,6 +24,10 @@ class BotleaguesApiServiceProvider extends ServiceProvider { { $this->package('camil-staps/botleagues-api'); + API::error(function(ModelNotFoundException $e) { + return Response::make(['error' => 'Resource not found'], 404); + }); + include __DIR__ . '/../../routes.php'; } diff --git a/src/CamilStaps/BotleaguesApi/User.php b/src/CamilStaps/BotleaguesApi/User.php new file mode 100644 index 0000000..50f37b8 --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/User.php @@ -0,0 +1,10 @@ +<?php +namespace CamilStaps\BotleaguesApi; + +use Illuminate\Database\Eloquent\Model; + +class User extends Model { + + + +}
\ No newline at end of file diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php new file mode 100644 index 0000000..2cc52c5 --- /dev/null +++ b/src/controllers/BaseController.php @@ -0,0 +1,10 @@ +<?php +namespace CamilStaps\BotleaguesApi; + +use \Dingo\Api\Routing\ControllerTrait; + +class BaseController extends \Illuminate\Routing\Controller { + + use ControllerTrait; + +}
\ No newline at end of file diff --git a/src/controllers/BotController.php b/src/controllers/BotController.php new file mode 100644 index 0000000..c304d1b --- /dev/null +++ b/src/controllers/BotController.php @@ -0,0 +1,18 @@ +<?php +namespace CamilStaps\BotleaguesApi; + +class BotController extends BaseController { + + public function index() { + return Bot::all(); + } + + public function show($id) { + return Bot::findOrFail($id); + } + + public function edit($id) { + return $this->response->noContent(); + } + +}
\ No newline at end of file diff --git a/src/controllers/UploadController.php b/src/controllers/UploadController.php deleted file mode 100644 index 7ea7f72..0000000 --- a/src/controllers/UploadController.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -namespace CamilStaps\BotleaguesApi; - -class UploadController extends \Illuminate\Routing\Controller { - - public function show($id) { - return 'Hello ' . $id; - } - -}
\ No newline at end of file diff --git a/src/controllers/UserController.php b/src/controllers/UserController.php new file mode 100644 index 0000000..39c2be6 --- /dev/null +++ b/src/controllers/UserController.php @@ -0,0 +1,18 @@ +<?php +namespace CamilStaps\BotleaguesApi; + +class UserController extends BaseController { + + public function index() { + return User::all(); + } + + public function show($id) { + return User::findOrFail($id); + } + + public function edit($id) { + return $this->response->noContent(); + } + +}
\ No newline at end of file diff --git a/src/migrations/2015_02_20_210536_create_user.php b/src/migrations/2015_02_20_210536_create_users.php index 39ff9e1..baf6c19 100644 --- a/src/migrations/2015_02_20_210536_create_user.php +++ b/src/migrations/2015_02_20_210536_create_users.php @@ -3,7 +3,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateUser extends Migration { +class CreateUsers extends Migration { /** * Run the migrations. @@ -12,11 +12,13 @@ class CreateUser extends Migration { */ public function up() { - Schema::create('user', function(Blueprint $table) + Schema::create('users', function(Blueprint $table) { $table->increments('id')->unsigned(); $table->string('email', 127)->unique(); - $table->string('password', 255); + $table->string('password', 60); + $table->rememberToken(); + $table->string('key', 255); $table->timestamps(); }); } @@ -28,7 +30,7 @@ class CreateUser extends Migration { */ public function down() { - Schema::drop('user'); + Schema::drop('users'); } } diff --git a/src/migrations/2015_02_20_211306_create_game.php b/src/migrations/2015_02_20_211306_create_games.php index 7fd5db5..5466404 100644 --- a/src/migrations/2015_02_20_211306_create_game.php +++ b/src/migrations/2015_02_20_211306_create_games.php @@ -3,7 +3,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateGame extends Migration { +class CreateGames extends Migration { /** * Run the migrations. @@ -12,7 +12,7 @@ class CreateGame extends Migration { */ public function up() { - Schema::create('game', function(Blueprint $table) + Schema::create('games', function(Blueprint $table) { $table->increments('id')->unsigned(); $table->string('title')->unique(); @@ -27,7 +27,7 @@ class CreateGame extends Migration { */ public function down() { - Schema::drop('game'); + Schema::drop('games'); } } diff --git a/src/migrations/2015_02_20_211317_create_bot.php b/src/migrations/2015_02_20_211317_create_bots.php index 86285a7..665ce0f 100644 --- a/src/migrations/2015_02_20_211317_create_bot.php +++ b/src/migrations/2015_02_20_211317_create_bots.php @@ -3,7 +3,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateBot extends Migration { +class CreateBots extends Migration { /** * Run the migrations. @@ -12,13 +12,16 @@ class CreateBot extends Migration { */ public function up() { - Schema::create('bot', function(Blueprint $table) + Schema::create('bots', function(Blueprint $table) { $table->increments('id')->unsigned(); $table->integer('userId')->unsigned(); - $table->foreign('userId')->references('id')->on('user'); + $table->foreign('userId')->references('id')->on('users'); $table->integer('gameId')->unsigned(); - $table->foreign('gameId')->references('id')->on('game'); + $table->foreign('gameId')->references('id')->on('games'); + $table->string('title', 45); + $table->string('version', 12); + $table->unique(array('gameId', 'title', 'version')); $table->timestamps(); }); } @@ -30,7 +33,7 @@ class CreateBot extends Migration { */ public function down() { - Schema::drop('bot'); + Schema::drop('bots'); } } diff --git a/src/routes.php b/src/routes.php index f40b16b..065d24a 100644 --- a/src/routes.php +++ b/src/routes.php @@ -3,6 +3,7 @@ Route::get('users', function(){ return 'hello world'; }); -Route::api('v1', function () { - Route::get('users/{id}', 'CamilStaps\BotleaguesApi\UploadController@show'); +Route::api(['version' => 'v1', 'protected' => true], function () { + Route::resource('bot', 'CamilStaps\BotleaguesApi\BotController'); + Route::resource('user', 'CamilStaps\BotleaguesApi\UserController'); });
\ No newline at end of file |