forked from jelic98/petplus_api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jelic98
committed
Aug 20, 2017
0 parents
commit dd5af67
Showing
64 changed files
with
6,069 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor | ||
.env |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Console; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Laravel\Lumen\Console\Kernel as ConsoleKernel; | ||
|
||
class Kernel extends ConsoleKernel | ||
{ | ||
/** | ||
* The Artisan commands provided by your application. | ||
* | ||
* @var array | ||
*/ | ||
protected $commands = [ | ||
// | ||
]; | ||
|
||
/** | ||
* Define the application's command schedule. | ||
* | ||
* @param \Illuminate\Console\Scheduling\Schedule $schedule | ||
* @return void | ||
*/ | ||
protected function schedule(Schedule $schedule) | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use Illuminate\Queue\SerializesModels; | ||
|
||
abstract class Event | ||
{ | ||
use SerializesModels; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
class ExampleEvent extends Event | ||
{ | ||
/** | ||
* Create a new event instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Validation\ValidationException; | ||
use Illuminate\Auth\Access\AuthorizationException; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; | ||
|
||
class Handler extends ExceptionHandler | ||
{ | ||
/** | ||
* Report or log an exception. | ||
* | ||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. | ||
* | ||
* @param \Exception $e | ||
* @return void | ||
*/ | ||
public function report(Exception $e) | ||
{ | ||
parent::report($e); | ||
} | ||
|
||
/** | ||
* Render an exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Exception $e | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function render($request, Exception $e) { | ||
if($request->wantsJson() && !($e instanceof ValidationException)) { | ||
if(is_object($e)) { | ||
$e = substr(strrchr(get_class($e), "\\"), 1); | ||
} | ||
|
||
return response()->json([ | ||
'code' => method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500, | ||
'message' => empty($e) ? 'Server error' : $e | ||
]); | ||
} | ||
|
||
return parent::render($request, $e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\School; | ||
use App\Subject; | ||
use App\Level; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
|
||
class ConstantsController extends Controller { | ||
|
||
public function schools() { | ||
return response()->json(School::with('level')->get()); | ||
} | ||
|
||
public function addSchool(Request $request) { | ||
$this->validate($request, [ | ||
'name' => 'required', | ||
'city' => 'required', | ||
'level' => 'required' | ||
]); | ||
|
||
if(School::where('name', $request['name']) | ||
->where('city', $request['city']) | ||
->where('level', $request['level']) | ||
->first()) { | ||
return MyResponse::show('School already exists', 400); | ||
} | ||
|
||
return response()->json(School::create($request->all())); | ||
} | ||
|
||
public function subjects() { | ||
return response()->json(Subject::all()); | ||
} | ||
|
||
public function addSubject(Request $request) { | ||
$this->validate($request, [ | ||
'name' => 'required' | ||
]); | ||
|
||
if(Subject::where('name', $request['name']) | ||
->first()) { | ||
return MyResponse::show('Subject already exists', 400); | ||
} | ||
|
||
return response()->json(Subject::create($request->all())); | ||
} | ||
|
||
public function levels() { | ||
return response()->json(Level::all()); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Laravel\Lumen\Routing\Controller as BaseController; | ||
|
||
class Controller extends BaseController | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Login; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
|
||
class LoginsController extends Controller { | ||
|
||
public function all() { | ||
return response()->json(Login::all()); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\JsonResponse; | ||
|
||
class MyResponse { | ||
|
||
public static function show($message = 'Error has occured', $code = 400) { | ||
if(is_object($message)) { | ||
$message = $message->toArray(); | ||
} | ||
|
||
$data = [ | ||
'code' => $code, | ||
'message' => $message | ||
]; | ||
|
||
return new JsonResponse($data, 200, [], 0); | ||
} | ||
} | ||
?> |
Oops, something went wrong.