From 11a20c5be971d97f4a4f575f91b706791c1893a9 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sun, 26 Apr 2015 23:29:17 +0200 Subject: Competitions; CompetitionTypes; Participants; better routing; administrators; ... --- src/controllers/BotController.php | 18 +++++++++++--- src/controllers/CompetitionController.php | 36 +++++++++++++++++++++++++++ src/controllers/CompetitionTypeController.php | 36 +++++++++++++++++++++++++++ src/controllers/GameController.php | 36 +++++++++++++++++++++++++++ src/controllers/ParticipantController.php | 36 +++++++++++++++++++++++++++ src/controllers/UserController.php | 9 +++---- 6 files changed, 161 insertions(+), 10 deletions(-) create mode 100644 src/controllers/CompetitionController.php create mode 100644 src/controllers/CompetitionTypeController.php create mode 100644 src/controllers/GameController.php create mode 100644 src/controllers/ParticipantController.php (limited to 'src/controllers') diff --git a/src/controllers/BotController.php b/src/controllers/BotController.php index c304d1b..9349ea8 100644 --- a/src/controllers/BotController.php +++ b/src/controllers/BotController.php @@ -3,16 +3,26 @@ namespace CamilStaps\BotleaguesApi; class BotController extends BaseController { + protected $bot; + + public function __construct(Bot $bot) { + $this->bot = $bot; + } + public function index() { - return Bot::all(); + return $this->bot->all(); } public function show($id) { - return Bot::findOrFail($id); + return $this->bot->findOrFail($id); + } + + public function update($id) { + throw new \Exception("Not implemented yet."); } - public function edit($id) { - return $this->response->noContent(); + public function store() { + throw new \Exception("Not implemented yet."); } } \ No newline at end of file diff --git a/src/controllers/CompetitionController.php b/src/controllers/CompetitionController.php new file mode 100644 index 0000000..6529433 --- /dev/null +++ b/src/controllers/CompetitionController.php @@ -0,0 +1,36 @@ +competition = $competition; + } + + public function index() { + return $this->competition->all(); + } + + public function show($id) { + return $this->competition->findOrFail($id); + } + + public function update($id) { + throw new \Exception("Not implemented yet."); + } + + public function store() { + $this->competition->fill(Input::all()); + + if ($this->competition->save()) { + return $this->response->created(); + } else { + throw new Dingo\Api\Exception\StoreResourceFailedException; + } + } + +} \ No newline at end of file diff --git a/src/controllers/CompetitionTypeController.php b/src/controllers/CompetitionTypeController.php new file mode 100644 index 0000000..430f7b5 --- /dev/null +++ b/src/controllers/CompetitionTypeController.php @@ -0,0 +1,36 @@ +competitionType = $competitionType; + } + + public function index() { + return $this->competitionType->all(); + } + + public function show($id) { + return $this->competitionType->findOrFail($id); + } + + public function update($id) { + throw new \Exception("Not implemented yet."); + } + + public function store() { + $this->competitionType->fill(Input::all()); + + if ($this->competitionType->save()) { + return $this->response->created(); + } else { + throw new Dingo\Api\Exception\StoreResourceFailedException; + } + } + +} \ No newline at end of file diff --git a/src/controllers/GameController.php b/src/controllers/GameController.php new file mode 100644 index 0000000..3ef9c37 --- /dev/null +++ b/src/controllers/GameController.php @@ -0,0 +1,36 @@ +game = $game; + } + + public function index() { + return $this->game->all(); + } + + public function show($id) { + return $this->game->findOrFail($id); + } + + public function update($id) { + throw new \Exception("Not implemented yet."); + } + + public function store() { + $this->game->fill(Input::all()); + + if ($this->game->save()) { + return $this->response->created(); + } else { + throw new Dingo\Api\Exception\StoreResourceFailedException; + } + } + +} \ No newline at end of file diff --git a/src/controllers/ParticipantController.php b/src/controllers/ParticipantController.php new file mode 100644 index 0000000..2ca28fb --- /dev/null +++ b/src/controllers/ParticipantController.php @@ -0,0 +1,36 @@ +participant = $participant; + } + + public function index() { + return $this->participant->all(); + } + + public function show($id) { + return $this->participant->findOrFail($id); + } + + public function update($id) { + throw new \Exception("Not implemented yet."); + } + + public function store() { + $this->participant->fill(Input::all()); + + if ($this->participant->save()) { + return $this->response->created(); + } else { + throw new Dingo\Api\Exception\StoreResourceFailedException; + } + } + +} \ No newline at end of file diff --git a/src/controllers/UserController.php b/src/controllers/UserController.php index 02400e9..03bebbc 100644 --- a/src/controllers/UserController.php +++ b/src/controllers/UserController.php @@ -4,7 +4,6 @@ namespace CamilStaps\BotleaguesApi; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Input; -use Illuminate\Support\Facades\Redirect; class UserController extends BaseController { @@ -12,6 +11,8 @@ class UserController extends BaseController { public function __construct(User $user) { $this->user = $user; + + $this->beforeFilter('current_user', array('only' => ['update', 'destroy'])); } public function index() { @@ -23,10 +24,6 @@ class UserController extends BaseController { } public function update($id) { - if ($id != Auth::user()->id) { - throw new \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException(); - } - $s = $this->user->find($id); if (!empty(Input::get('password'))) @@ -41,7 +38,7 @@ class UserController extends BaseController { public function store() { $this->user->email = Input::get('email'); - $this->user->password = Hash::make(Input::get('password')); + $this->user->password = empty(Input::get('password')) ? null : Hash::make(Input::get('password')); if ($this->user->save()) { return $this->response->created(); -- cgit v1.2.3