Skip to content

Commit

Permalink
Cleaned up client actions [SLE-194]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed Oct 26, 2023
1 parent a5bb7a0 commit 65e8d0f
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 217 deletions.
9 changes: 0 additions & 9 deletions src/Application/Actions/Client/Ajax/ApiClientCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Application\Actions\Client\Ajax;

use App\Application\Responder\Responder;
use App\Application\Validation\MalformedRequestBodyChecker;
use App\Domain\Client\Service\ClientCreatorFromClientSubmit;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -13,17 +12,9 @@
*/
final class ApiClientCreateAction
{
/**
* The constructor.
*
* @param Responder $responder The responder
* @param ClientCreatorFromClientSubmit $clientCreatorFromClientSubmit
* @param MalformedRequestBodyChecker $malformedRequestBodyChecker
*/
public function __construct(
private readonly Responder $responder,
private readonly ClientCreatorFromClientSubmit $clientCreatorFromClientSubmit,
private readonly MalformedRequestBodyChecker $malformedRequestBodyChecker,
) {
}

Expand Down
9 changes: 0 additions & 9 deletions src/Application/Actions/Client/Ajax/ClientCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,8 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* Action.
*/
final class ClientCreateAction
{
/**
* The constructor.
*
* @param Responder $responder The responder
* @param ClientCreator $clientCreator
*/
public function __construct(
private readonly Responder $responder,
private readonly ClientCreator $clientCreator,
Expand Down
13 changes: 0 additions & 13 deletions src/Application/Actions/Client/Ajax/ClientDeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,10 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;

/**
* Action.
*/
final class ClientDeleteAction
{
protected LoggerInterface $logger;

/**
* The constructor.
*
* @param Responder $responder The responder
* @param ClientDeleter $clientDeleter
* @param SessionInterface $session
* @param LoggerFactory $logger
*/
public function __construct(
private readonly Responder $responder,
private readonly ClientDeleter $clientDeleter,
Expand All @@ -43,8 +32,6 @@ public function __construct(
* @param ResponseInterface $response The response
* @param array $args
*
* @throws \JsonException
*
* @return ResponseInterface The response
*/
public function __invoke(
Expand Down
26 changes: 2 additions & 24 deletions src/Application/Actions/Client/Ajax/ClientFetchListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
namespace App\Application\Actions\Client\Ajax;

use App\Application\Responder\Responder;
use App\Domain\Authorization\UnauthorizedException;
use App\Domain\Client\Exception\InvalidClientFilterException;
use App\Domain\Client\Service\ClientFinderWithFilter;
use App\Test\Integration\Client\ClientListActionTest;
use Fig\Http\Message\StatusCodeInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class ClientFetchListAction
{
/**
* The constructor.
*
* @param Responder $responder The responder
* @param ClientFinderWithFilter $clientFilterFinder
*/
public function __construct(
private readonly Responder $responder,
private readonly ClientFinderWithFilter $clientFilterFinder,
Expand All @@ -31,8 +25,6 @@ public function __construct(
* @param ResponseInterface $response The response
* @param array $args
*
* @throws \JsonException
*
* @return ResponseInterface The response
*/
public function __invoke(
Expand All @@ -48,27 +40,13 @@ public function __invoke(
} catch (InvalidClientFilterException $invalidClientFilterException) {
return $this->responder->respondWithJson(
$response,
// Response format tested in PostFilterProvider.php
/** @see ClientListActionTest::testClientListActionInvalidFilters() */
[
'status' => 'error',
'message' => $invalidClientFilterException->getMessage(),
],
StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY
);
} // If user requests its own posts he has to be logged in
catch (UnauthorizedException $unauthorizedException) {
// Respond with status code 401 Unauthorized which is caught in the Ajax call
return $this->responder->respondWithJson(
$response,
[
'loginUrl' => $this->responder->urlFor(
'login-page',
[],
['redirect' => $this->responder->urlFor('client-list-assigned-to-me-page')]
),
],
401
);
}
}
}
52 changes: 0 additions & 52 deletions src/Application/Actions/Client/Ajax/ClientReadAction.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Application/Actions/Client/Ajax/ClientUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@

use App\Application\Responder\Responder;
use App\Domain\Client\Service\ClientUpdater;
use App\Domain\Factory\LoggerFactory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;

/**
* Action.
*/
final class ClientUpdateAction
{
protected LoggerInterface $logger;

public function __construct(
protected readonly Responder $responder,
private readonly ClientUpdater $clientUpdater,
LoggerFactory $logger,
) {
$this->logger = $logger->addFileHandler('error.log')->createLogger('client-update');
}

/**
Expand All @@ -32,7 +23,6 @@ public function __construct(
* @param array $args
*
* @return ResponseInterface The response
*
*/
public function __invoke(
ServerRequestInterface $request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@

class FetchDropdownOptionsForClientCreateAction
{
/**
* The constructor.
*
* @param Responder $responder The responder
* @param ClientUtilFinder $clientUtilFinder
*/
public function __construct(
private readonly Responder $responder,
private readonly ClientUtilFinder $clientUtilFinder,
Expand All @@ -30,8 +24,6 @@ public function __construct(
* @param ResponseInterface $response The response
* @param array $args
*
* @throws \JsonException
*
* @return ResponseInterface The response
*/
public function __invoke(
Expand Down
11 changes: 0 additions & 11 deletions src/Application/Actions/Client/Page/ClientListPageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,8 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* Action.
*/
final class ClientListPageAction
{
/**
* The constructor.
*
* @param Responder $responder The responder
* @param ClientListFilterChipProvider $clientListFilterChipGetter
* @param ClientAuthorizationChecker $clientAuthorizationChecker
*/
public function __construct(
private readonly Responder $responder,
private readonly ClientListFilterChipProvider $clientListFilterChipGetter,
Expand All @@ -35,7 +25,6 @@ public function __construct(
* @param ResponseInterface $response The response
* @param array $args
*
* @throws \JsonException
* @throws \Throwable
*
* @return ResponseInterface The response
Expand Down
10 changes: 0 additions & 10 deletions src/Application/Actions/Client/Page/ClientReadPageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* Action.
*/
final class ClientReadPageAction
{
/**
* The constructor.
*
* @param Responder $responder The responder
* @param ClientFinder $clientFinder
* @param ClientUtilFinder $clientUtilFinder
*/
public function __construct(
private readonly Responder $responder,
private readonly ClientFinder $clientFinder,
Expand Down
1 change: 0 additions & 1 deletion src/Application/Actions/Note/Ajax/NoteCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

final class NoteCreateAction
{

public function __construct(
private readonly Responder $responder,
private readonly NoteCreator $noteCreator,
Expand Down
13 changes: 1 addition & 12 deletions src/Application/Actions/Note/Ajax/NoteFetchListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,21 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* List notes linked to user action.
*/
final class NoteFetchListAction
{
/**
* The constructor.
*
* @param Responder $responder The responder
* @param NoteFilterFinder $noteFilterFinder
*/
public function __construct(
private readonly Responder $responder,
private readonly NoteFilterFinder $noteFilterFinder,
) {
}

/**
* Note list all and own Action.
* Fetch note list with given params action.
*
* @param ServerRequestInterface $request The request
* @param ResponseInterface $response The response
* @param array $args
*
* @throws \JsonException
*
* @return ResponseInterface The response
*/
public function __invoke(
Expand Down
4 changes: 0 additions & 4 deletions src/Application/Actions/Note/Ajax/NoteUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
namespace App\Application\Actions\Note\Ajax;

use App\Application\Responder\Responder;
use App\Domain\Factory\LoggerFactory;
use App\Domain\Note\Service\NoteUpdater;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class NoteUpdateAction
{

public function __construct(
private readonly Responder $responder,
private readonly NoteUpdater $noteUpdater,
LoggerFactory $logger,
) {
$this->logger = $logger->addFileHandler('error.log')->createLogger('note-update');
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/Application/Actions/Note/Page/NoteReadPageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* Action.
*/
final class NoteReadPageAction
{
/**
* The constructor.
*
* @param Responder $responder The responder
* @param NoteFinder $noteFinder
* @param SessionInterface $session
*/
public function __construct(
private readonly Responder $responder,
private readonly NoteFinder $noteFinder,
Expand Down
3 changes: 1 addition & 2 deletions src/Application/Middleware/ForbiddenExceptionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

class ForbiddenExceptionMiddleware implements MiddlewareInterface
{

public function __construct(
private readonly Responder $responder,
) {
Expand All @@ -36,4 +35,4 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
);
}
}
}
}
Loading

0 comments on commit 65e8d0f

Please sign in to comment.