aboutsummaryrefslogtreecommitdiff
path: root/src/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/BotController.php18
-rw-r--r--src/controllers/CompetitionController.php36
-rw-r--r--src/controllers/CompetitionTypeController.php36
-rw-r--r--src/controllers/GameController.php36
-rw-r--r--src/controllers/ParticipantController.php36
-rw-r--r--src/controllers/UserController.php9
6 files changed, 161 insertions, 10 deletions
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 @@
+<?php
+namespace CamilStaps\BotleaguesApi;
+
+use Illuminate\Support\Facades\Input;
+
+class CompetitionController extends BaseController {
+
+ protected $competition;
+
+ public function __construct(Competition $competition) {
+ $this->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 @@
+<?php
+namespace CamilStaps\BotleaguesApi;
+
+use Illuminate\Support\Facades\Input;
+
+class CompetitionTypeController extends BaseController {
+
+ protected $competitionType;
+
+ public function __construct(CompetitionType $competitionType) {
+ $this->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 @@
+<?php
+namespace CamilStaps\BotleaguesApi;
+
+use Illuminate\Support\Facades\Input;
+
+class GameController extends BaseController {
+
+ protected $game;
+
+ public function __construct(Game $game) {
+ $this->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 @@
+<?php
+namespace CamilStaps\BotleaguesApi;
+
+use Illuminate\Support\Facades\Input;
+
+class ParticipantController extends BaseController {
+
+ protected $participant;
+
+ public function __construct(Participant $participant) {
+ $this->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();