-
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.
Creating the models, migrations, repositories and controllers
- Loading branch information
0 parents
commit 970fbaa
Showing
79 changed files
with
9,716 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,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 |
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,19 @@ | ||
APP_NAME=Lumen | ||
APP_ENV=local | ||
APP_KEY= | ||
APP_DEBUG=true | ||
APP_URL=http://localhost | ||
APP_TIMEZONE=UTC | ||
|
||
LOG_CHANNEL=stack | ||
LOG_SLACK_WEBHOOK_URL= | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=homestead | ||
DB_USERNAME=homestead | ||
DB_PASSWORD=secret | ||
|
||
CACHE_DRIVER=file | ||
QUEUE_CONNECTION=sync |
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,6 @@ | ||
/vendor | ||
/.idea | ||
Homestead.json | ||
Homestead.yaml | ||
.env | ||
.phpunit.result.cache |
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,6 @@ | ||
php: | ||
preset: laravel | ||
disabled: | ||
- unused_use | ||
js: true | ||
css: true |
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,26 @@ | ||
# Lumen PHP Framework | ||
|
||
[](https://travis-ci.org/laravel/lumen-framework) | ||
[](https://packagist.org/packages/laravel/lumen-framework) | ||
[](https://packagist.org/packages/laravel/lumen-framework) | ||
[](https://packagist.org/packages/laravel/lumen-framework) | ||
|
||
Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching. | ||
|
||
> **Note:** In the years since releasing Lumen, PHP has made a variety of wonderful performance improvements. For this reason, along with the availability of [Laravel Octane](https://laravel.com/docs/octane), we no longer recommend that you begin new projects with Lumen. Instead, we recommend always beginning new projects with [Laravel](https://laravel.com). | ||
## Official Documentation | ||
|
||
Documentation for the framework can be found on the [Lumen website](https://lumen.laravel.com/docs). | ||
|
||
## Contributing | ||
|
||
Thank you for considering contributing to Lumen! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). | ||
|
||
## Security Vulnerabilities | ||
|
||
If you discover a security vulnerability within Lumen, please send an e-mail to Taylor Otwell at [email protected]. All security vulnerabilities will be promptly addressed. | ||
|
||
## License | ||
|
||
The Lumen framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
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 = [ | ||
\Illuminate\Console\KeyGenerateCommand::class, | ||
]; | ||
|
||
/** | ||
* 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,54 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Illuminate\Auth\Access\AuthorizationException; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Illuminate\Validation\ValidationException; | ||
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Throwable; | ||
|
||
class Handler extends ExceptionHandler | ||
{ | ||
/** | ||
* A list of the exception types that should not be reported. | ||
* | ||
* @var array | ||
*/ | ||
protected $dontReport = [ | ||
AuthorizationException::class, | ||
HttpException::class, | ||
ModelNotFoundException::class, | ||
ValidationException::class, | ||
]; | ||
|
||
/** | ||
* Report or log an exception. | ||
* | ||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. | ||
* | ||
* @param \Throwable $exception | ||
* @return void | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function report(Throwable $exception) | ||
{ | ||
parent::report($exception); | ||
} | ||
|
||
/** | ||
* Render an exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Throwable $exception | ||
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse | ||
* | ||
* @throws \Throwable | ||
*/ | ||
public function render($request, Throwable $exception) | ||
{ | ||
return parent::render($request, $exception); | ||
} | ||
} |
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,118 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Exception; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use Laravel\Lumen\Routing\Controller as BaseController; | ||
use App\Services\ServiceInterface; | ||
|
||
abstract class Controller extends BaseController implements ControllerInterface | ||
{ | ||
protected ServiceInterface $service; | ||
protected array $searchFields = []; | ||
|
||
public function __construct(ServiceInterface $service) | ||
{ | ||
$this->service = $service; | ||
} | ||
|
||
public function findAll(Request $request): JsonResponse | ||
{ | ||
try { | ||
$limit = (int) $request->get('limit', 10); | ||
$orderBy = $request->get('order_by', []); | ||
$searchString = $request->get('q', ''); | ||
|
||
if (!empty($searchString)) { | ||
$result = $this->service->searchBy( | ||
$searchString, | ||
$this->searchFields, | ||
$limit, | ||
$orderBy, | ||
); | ||
} else { | ||
$result = $this->service->findAll($limit, $orderBy); | ||
} | ||
|
||
$response = $this->successResponse($result, Response::HTTP_PARTIAL_CONTENT); | ||
} catch (Exception $e) { | ||
$response = $this->errorResponse($e); | ||
} | ||
|
||
return response()->json($response, $response['status_code']); | ||
} | ||
|
||
public function findOne(Request $request, int|string $id): JsonResponse | ||
{ | ||
try { | ||
$result = $this->service->findOne($id); | ||
$response = $this->successResponse($result, Response::HTTP_CREATED); | ||
} catch (Exception $e) { | ||
$response = $this->errorResponse($e); | ||
} | ||
|
||
return response()->json($response, $response['status_code']); | ||
} | ||
|
||
public function create(Request $request): JsonResponse | ||
{ | ||
try { | ||
$data = $request->all(); | ||
$result = $this->service->create($data); | ||
$response = $this->successResponse($result, Response::HTTP_CREATED); | ||
} catch (Exception $e) { | ||
$response = $this->errorResponse($e); | ||
} | ||
|
||
return response()->json($response, $response['status_code']); | ||
} | ||
|
||
public function update(Request $request, int|string $id): JsonResponse | ||
{ | ||
try { | ||
$data = $request->all(); | ||
$result = $this->service->update($id, $data); | ||
$response = $this->successResponse([ | ||
'updated' => $result, | ||
]); | ||
} catch (Exception $e) { | ||
$response = $this->errorResponse($e); | ||
} | ||
|
||
return response()->json($response, $response['status_code']); | ||
} | ||
|
||
public function delete(int|string $id): JsonResponse | ||
{ | ||
try { | ||
$result = $this->service->delete($id); | ||
$response = $this->successResponse([ | ||
'deleted' => $result, | ||
]); | ||
} catch (Exception $e) { | ||
$response = $this->errorResponse($e); | ||
} | ||
|
||
return response()->json($response, $response['status_code']); | ||
} | ||
|
||
protected function successResponse(array $data, int $statusCode = Response::HTTP_OK): array | ||
{ | ||
return [ | ||
'status_code' => $statusCode, | ||
'data' => $data, | ||
]; | ||
} | ||
|
||
protected function errorResponse(Exception $e, int $statusCode = Response::HTTP_BAD_REQUEST): array | ||
{ | ||
return [ | ||
'status_code' => $statusCode, | ||
'error' => true, | ||
'error_description' => $e->getMessage(), | ||
]; | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
|
||
interface ControllerInterface | ||
{ | ||
public function findAll(Request $request): JsonResponse; | ||
public function findOne(Request $request, int|string $param): JsonResponse; | ||
public function create(Request $request): JsonResponse; | ||
public function update(Request $request, int|string $param): JsonResponse; | ||
public function delete(int|string $param): JsonResponse; | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Services\AuthorService; | ||
|
||
class AuthorController extends Controller | ||
{ | ||
protected array $searchFields = [ | ||
'first_name', | ||
'last_name', | ||
]; | ||
|
||
protected function __construct(AuthorService $service) | ||
{ | ||
parent::__construct($service); | ||
} | ||
} |
Oops, something went wrong.