Skip to content

Commit

Permalink
Riddle Controller WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jayar95 committed Mar 6, 2018
1 parent b0d5644 commit 4c2eecb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 46 deletions.
94 changes: 48 additions & 46 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
<?php

namespace App\Exceptions;
namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
class Handler extends ExceptionHandler {
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
*
* @return void
*/
public function report(Exception $exception) {
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
*
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception) {
if ($exception instanceof PermissionDeniedException)
return response()->json(['error' => 'Permission Denied.'], 403);

return parent::render($request, $exception);
}
}
5 changes: 5 additions & 0 deletions app/Exceptions/PermissionDeniedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
namespace App\Exceptions;

class PermissionDeniedException extends \Exception {
}
32 changes: 32 additions & 0 deletions app/Http/Controllers/RiddleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers;

use App\Exceptions\PermissionDeniedException;
use App\Riddle;
use App\User;
use Illuminate\Http\Request;

class RiddleController extends Controller {
/**
* @var User $user
*/
private $user;

public function __construct() {
$this->middleware('auth:api');
$this->user = auth()->user();
}

public function create(Request $request) {
$this->validate($request, [
'content' => 'required',
'title' => 'required',
]);

if (!$this->user->staff)
throw new PermissionDeniedException();

//TODO
$riddle = Riddle::create([]);
}
}

0 comments on commit 4c2eecb

Please sign in to comment.