Skip to content

Commit

Permalink
Make controllers structure more flat (#27)
Browse files Browse the repository at this point in the history
Make controllers structure more flat
  • Loading branch information
antonkomarev authored Jul 12, 2019
1 parent d244a1a commit 8fd7703
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 33 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `laravel-paket` will be documented in this file.

## [Unreleased]

### Changed

- ([#27](https://github.com/cybercog/laravel-paket/pull/27)) `Http\Controllers` namespace structure became more flat

## 1.0.0 - 2019-06-30

- Initial release
10 changes: 5 additions & 5 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@

Route::prefix('api')->namespace('Api')->name('paket.api.')->group(function () {
Route::get('requirements')
->uses('Requirements\Collect\Action')
->uses('Requirements\CollectAction')
->name('requirements.collect');

Route::get('jobs')
->uses('Jobs\Collect\Action')
->uses('Jobs\CollectAction')
->name('jobs.collect');

Route::post('jobs')
->uses('Jobs\Post\Action')
->uses('Jobs\PostAction')
->name('jobs.post');

Route::get('jobs/{job}')
->uses('Jobs\Get\Action')
->uses('Jobs\GetAction')
->name('jobs.get');
});

Route::get('{view?}', 'App\Action')
Route::get('{view?}', 'AppAction')
->where('view', '(.*)')
->name('paket');
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs\Collect;
namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs;

use Cog\Contracts\Paket\Job\Repositories\Job as JobRepositoryContract;
use Illuminate\Contracts\Support\Responsable as ResponsableContract;

final class Action
final class CollectAction
{
public function __invoke(JobRepositoryContract $jobs): ResponsableContract
{
return new Response($jobs->all());
return new CollectResponse($jobs->all());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs\Collect;
namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs;

use Illuminate\Contracts\Support\Responsable as ResponsableContract;
use Illuminate\Http\JsonResponse;

final class Response implements ResponsableContract
final class CollectResponse implements ResponsableContract
{
private $jobs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs\Get;
namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs;

use Cog\Contracts\Paket\Job\Repositories\Job as JobRepositoryContract;
use Illuminate\Contracts\Support\Responsable as ResponsableContract;

final class Action
final class GetAction
{
public function __invoke(string $id, JobRepositoryContract $jobs): ResponsableContract
{
return new Response($jobs->getById($id));
return new GetResponse($jobs->getById($id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs\Get;
namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs;

use Cog\Contracts\Paket\Job\Entities\Job as JobContract;
use Illuminate\Contracts\Support\Responsable as ResponsableContract;
use Illuminate\Http\JsonResponse;

final class Response implements ResponsableContract
final class GetResponse implements ResponsableContract
{
private $job;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs\Post;
namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs;

use Cog\Contracts\Paket\Job\Repositories\Job as JobRepositoryContract;
use Cog\Contracts\Paket\Requirement\Entities\Requirement as RequirementContract;
Expand All @@ -27,7 +27,7 @@
use Ramsey\Uuid\Uuid;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

final class Action
final class PostAction
{
private $jobs;

Expand All @@ -36,7 +36,7 @@ public function __construct(JobRepositoryContract $jobs)
$this->jobs = $jobs;
}

public function __invoke(Request $request): ResponsableContract
public function __invoke(PostRequest $request): ResponsableContract
{
$type = $request->input('type');
$requirement = Requirement::fromArray($request->input('requirement'));
Expand Down Expand Up @@ -66,7 +66,7 @@ public function __invoke(Request $request): ResponsableContract

event(new JobHasBeenCreated($job));

return new Response($job);
return new PostResponse($job);
}

private function getInstalledRequirements(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs\Post;
namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs;

use Illuminate\Foundation\Http\FormRequest;

final class Request extends FormRequest
final class PostRequest extends FormRequest
{
public function rules(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs\Post;
namespace Cog\Laravel\Paket\Http\Controllers\Api\Jobs;

use Cog\Contracts\Paket\Job\Entities\Job as JobContract;
use Illuminate\Contracts\Support\Responsable as ResponsableContract;
use Illuminate\Http\JsonResponse;

final class Response implements ResponsableContract
final class PostResponse implements ResponsableContract
{
private $job;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\Api\Requirements\Collect;
namespace Cog\Laravel\Paket\Http\Controllers\Api\Requirements;

use Illuminate\Contracts\Support\Responsable as ResponsableContract;
use MCStreetguy\ComposerParser\Factory as ComposerParser;

final class Action
final class CollectAction
{
public function __invoke(): ResponsableContract
{
$requirements = $this->getInstalledRequirements();

return new Response($requirements);
return new CollectResponse($requirements);
}

private function getInstalledRequirements(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\Api\Requirements\Collect;
namespace Cog\Laravel\Paket\Http\Controllers\Api\Requirements;

use Illuminate\Contracts\Support\Responsable as ResponsableContract;
use Illuminate\Http\JsonResponse;

final class Response implements ResponsableContract
final class CollectResponse implements ResponsableContract
{
private $requirements;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\App;
namespace Cog\Laravel\Paket\Http\Controllers;

use Illuminate\Contracts\Support\Responsable as ResponsableContract;

final class Action
final class AppAction
{
public function __invoke(): ResponsableContract
{
return new Response();
return new AppResponse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

declare(strict_types=1);

namespace Cog\Laravel\Paket\Http\Controllers\App;
namespace Cog\Laravel\Paket\Http\Controllers;

use Illuminate\Contracts\Support\Responsable as ResponsableContract;
use Illuminate\Http\Response as IlluminateResponse;
use Illuminate\Support\Facades\Config;

final class Response implements ResponsableContract
final class AppResponse implements ResponsableContract
{
/**
* Create an HTTP response that represents the object.
Expand Down

0 comments on commit 8fd7703

Please sign in to comment.