Skip to content

Commit

Permalink
Added actions uniform naming with convention [SLE-192]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed Oct 18, 2023
1 parent 26038b8 commit deba0d5
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 60 deletions.
36 changes: 18 additions & 18 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
return $response;
})->setName('test-post-request');

$app->put('/dashboard-toggle-panel', \App\Application\Actions\Dashboard\DashboardTogglePanelAction::class)
$app->put('/dashboard-toggle-panel', \App\Application\Actions\Dashboard\DashboardTogglePanelProcessAction::class)
->setName('dashboard-toggle-panel');

$app->get('/login', \App\Application\Actions\Authentication\Page\LoginPageAction::class)->setName('login-page');
$app->post('/login', \App\Application\Actions\Authentication\Submit\LoginSubmitAction::class)->setName(
$app->post('/login', \App\Application\Actions\Authentication\Ajax\LoginSubmitAction::class)->setName(
'login-submit'
);
$app->get('/logout', \App\Application\Actions\Authentication\Page\LogoutPageAction::class)->setName('logout')->add(
Expand All @@ -44,32 +44,32 @@
// Authentication - email verification - token
$app->get(
'/register-verification',
\App\Application\Actions\Authentication\Submit\RegisterVerifySubmitAction::class
\App\Application\Actions\Authentication\Ajax\RegisterVerifyProcessAction::class
)->setName(
'register-verification'
);

$app->get('/unlock-account', \App\Application\Actions\Authentication\Submit\AccountUnlockAction::class)->setName(
$app->get('/unlock-account', \App\Application\Actions\Authentication\Ajax\AccountUnlockProcessAction::class)->setName(
'account-unlock-verification'
);

$app->post(// Url password-forgotten hardcoded in login-main.js
'/password-forgotten',
\App\Application\Actions\Authentication\Submit\PasswordForgottenEmailSubmitAction::class
\App\Application\Actions\Authentication\Ajax\PasswordForgottenEmailSubmitAction::class
)->setName('password-forgotten-email-submit');
// Set new password page after clicking on email link with token
$app->get('/reset-password', \App\Application\Actions\Authentication\Page\PasswordResetPageAction::class)
->setName('password-reset-page');
// Submit new password (reset-password hardcoded in login-main.js)
$app->post(
'/reset-password',
\App\Application\Actions\Authentication\Submit\PasswordResetSubmitAction::class
\App\Application\Actions\Authentication\Ajax\NewPasswordResetSubmitAction::class
)->setName('password-reset-submit');

// Submit new password when authenticated (post and not put as form submit)
$app->put(
'/change-password/{user_id:[0-9]+}',
\App\Application\Actions\User\Ajax\ChangePasswordSubmitAction::class
\App\Application\Actions\User\Ajax\PasswordChangeSubmitAction::class
)->setName('change-password-submit')->add(UserAuthenticationMiddleware::class);

// Without UserAuthenticationMiddleware as translations are also needed for non-protected pages such as password reset
Expand All @@ -80,24 +80,24 @@
// $group->options('', PreflightAction::class); // Allow preflight requests
$group->get('/list', \App\Application\Actions\User\Page\UserListPageAction::class)
->setName('user-list-page');
$group->get('', \App\Application\Actions\User\Ajax\UserListAction::class)
$group->get('', \App\Application\Actions\User\Ajax\UserFetchListAction::class)
->setName('user-list');

$group // User dropdown options
->get('/dropdown-options', \App\Application\Actions\User\Ajax\UserFetchDropdownOptionsAction::class)
->get('/dropdown-options', \App\Application\Actions\User\Ajax\FetchDropdownOptionsForUserCreateAction::class)
->setName('user-dropdown-options');

$group->get('/activity', \App\Application\Actions\User\Ajax\ListUserActivityAction::class)
$group->get('/activity', \App\Application\Actions\User\Ajax\UserActivityFetchListAction::class)
->setName('user-get-activity');

$group->post('', \App\Application\Actions\User\Ajax\UserSubmitCreateAction::class)
$group->post('', \App\Application\Actions\User\Ajax\UserCreateAction::class)
->setName('user-create-submit');
// Route name has to be in the format: "[table_name]-read-page" and argument "[table-name]-id" to link from user activity
$group->get('/{user_id:[0-9]+}', \App\Application\Actions\User\Page\UserReadPageAction::class)
->setName('user-read-page');
$group->put('/{user_id:[0-9]+}', \App\Application\Actions\User\Ajax\UserSubmitUpdateAction::class)
$group->put('/{user_id:[0-9]+}', \App\Application\Actions\User\Ajax\UserUpdateAction::class)
->setName('user-update-submit');
$group->delete('/{user_id:[0-9]+}', \App\Application\Actions\User\Ajax\UserSubmitDeleteAction::class)
$group->delete('/{user_id:[0-9]+}', \App\Application\Actions\User\Ajax\UserDeleteAction::class)
->setName('user-delete-submit');
})->add(UserAuthenticationMiddleware::class);

Expand All @@ -114,7 +114,7 @@
// Client create form is rendered by the client and needs to have the available dropdown options
$group->get(
'/dropdown-options',
\App\Application\Actions\Client\Ajax\ClientCreateDropdownOptionsAction::class
\App\Application\Actions\Client\Ajax\FetchDropdownOptionsForClientCreateAction::class
)->setName('client-create-dropdown');
/* For api response action:
json_encode transforms object with public attributes to camelCase which matches Google recommendation
Expand All @@ -135,16 +135,16 @@

// Note routes
$app->group('/notes', function (RouteCollectorProxy $group) {
$group->get('', \App\Application\Actions\Note\Ajax\NoteListFetchAction::class)->setName('note-list');
$group->get('', \App\Application\Actions\Note\Ajax\NoteFetchListAction::class)->setName('note-list');
$group->get('/{note_id:[0-9]+}', \App\Application\Actions\Note\Page\NoteReadPageAction::class)->setName(
'note-read-page'
);
$group->post('', \App\Application\Actions\Note\Ajax\NoteCreateSubmitAction::class)->setName(
$group->post('', \App\Application\Actions\Note\Ajax\NoteCreateAction::class)->setName(
'note-submit-creation'
);
$group->put('/{note_id:[0-9]+}', \App\Application\Actions\Note\Ajax\NoteUpdateSubmitAction::class)
$group->put('/{note_id:[0-9]+}', \App\Application\Actions\Note\Ajax\NoteUpdateAction::class)
->setName('note-submit-modification');
$group->delete('/{note_id:[0-9]+}', \App\Application\Actions\Note\Ajax\NoteDeleteSubmitAction::class)
$group->delete('/{note_id:[0-9]+}', \App\Application\Actions\Note\Ajax\NoteDeleteAction::class)
->setName('note-submit-delete');
})->add(UserAuthenticationMiddleware::class);

Expand Down
28 changes: 28 additions & 0 deletions docs/naming-convention.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ There are three kinds of DTOs:
* Collection of Data objects with optional additional attributes. MUST end with ResultDataCollection:
`ClientResultDataCollection`.

## Actions
1. **Use Case Specific**: The action name should clearly indicate the use case it handles.
The name of the resource should be the first word and in singular form (first word to be able to
find it better on a project wide search).
For example, if an action handles updating a client, it could be named `ClientUpdateAction.php`.
2. **Request Type Specific**: The action name should also indicate the type of request it handles.
For example, for fetch requests, `Fetch` could be used in the action name like `ClientFetchAction.php`.
For actions that display a page, the word `Page` should be in the action name like `LoginPageAction.php`.
Alternatively the word "Show" can also be used as it makes clear that a page is rendered `ShowUserProfileAction.php`.
4. **Suffix with "Action"**: `Action` at the end of the action names indicates that
the class is an action.
5. **Prefix with "Api"**: Only for Api requests add `Api` at the beginning of the action name
to indicate that the request is made from another application via said interface.
5. **Folder Structure**: Actions are organized into "Page" and "Ajax" folders based on whether they
handle page requests or Ajax requests.

Based on these guidelines, here are some examples for different types of requests:

- Show page actions: `LoginPageAction.php`, `UserProfilePageAction.php`, `ShowUserProfileAction.php`
- Fetch collection of data: `ClientFetchListAction.php`, `NoteFetchListAction.php`
- Read, get specific set of data: `ClientReadAction.php`, `UserReadAction.php`
- Submit/Process requests: `LoginSubmitAction.php`, `PasswordForgottenSubmitEmailAction.php`,
`NewPasswordResetSubmitAction.php`, `AccountUnlockProcessAction.php`
- Create requests: `ClientCreateAction.php`, `UserCreateAction.php`
- Update requests: `ClientUpdateAction.php`, `NoteUpdateAction.php`
- Delete requests: `ClientDeleteAction.php`, `NoteDeleteAction.php`
- Api requests: `ApiClientCreateAction.php`,

## Templates
* Follow [general files and folders](#General-files-and-folders) rules
* View templates that are displayed to the user are in the module sub folder and must end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Application\Actions\Authentication\Submit;
namespace App\Application\Actions\Authentication\Ajax;

use App\Application\Responder\Responder;
use App\Domain\Authentication\Exception\InvalidTokenException;
Expand All @@ -13,7 +13,7 @@
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpBadRequestException;

final class AccountUnlockAction
final class AccountUnlockProcessAction
{
protected LoggerInterface $logger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Application\Actions\Authentication\Submit;
namespace App\Application\Actions\Authentication\Ajax;

use App\Application\Responder\Responder;
use App\Application\Validation\MalformedRequestBodyChecker;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Application\Actions\Authentication\Submit;
namespace App\Application\Actions\Authentication\Ajax;

use App\Application\Responder\Responder;
use App\Application\Validation\MalformedRequestBodyChecker;
Expand All @@ -14,7 +14,7 @@
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpBadRequestException;

class PasswordResetSubmitAction
class NewPasswordResetSubmitAction
{
private LoggerInterface $logger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Application\Actions\Authentication\Submit;
namespace App\Application\Actions\Authentication\Ajax;

use App\Application\Responder\Responder;
use App\Application\Validation\MalformedRequestBodyChecker;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Application\Actions\Authentication\Submit;
namespace App\Application\Actions\Authentication\Ajax;

use App\Application\Responder\Responder;
use App\Domain\Authentication\Exception\InvalidTokenException;
Expand All @@ -13,7 +13,7 @@
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpBadRequestException;

final class RegisterVerifySubmitAction
final class RegisterVerifyProcessAction
{
protected LoggerInterface $logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* Post list all and own action.
*/
final class ClientFetchListAction
{
/**
Expand All @@ -28,7 +25,7 @@ public function __construct(
}

/**
* Client list all and own Action.
* Client fetch list Action.
*
* @param ServerRequestInterface $request The request
* @param ResponseInterface $response The response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class ClientCreateDropdownOptionsAction
class FetchDropdownOptionsForClientCreateAction
{
/**
* The constructor.
Expand All @@ -24,7 +24,7 @@ public function __construct(
}

/**
* Client list all and own Action.
* Fetch dropdown options for client create form (lazy load).
*
* @param ServerRequestInterface $request The request
* @param ResponseInterface $response The response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Action.
*/
final class DashboardTogglePanelAction
final class DashboardTogglePanelProcessAction
{
/**
* The constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Action.
*/
final class NoteCreateSubmitAction
final class NoteCreateAction
{
/**
* The constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Action.
*/
final class NoteDeleteSubmitAction
final class NoteDeleteAction
{
protected LoggerInterface $logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* List notes linked to user action.
*/
final class NoteListFetchAction
final class NoteFetchListAction
{
/**
* The constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Action.
*/
final class NoteUpdateSubmitAction
final class NoteUpdateAction
{
/**
* The constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class UserFetchDropdownOptionsAction
class FetchDropdownOptionsForUserCreateAction
{
/**
* The constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* When user wants to change password being authenticated.
*/
class ChangePasswordSubmitAction
class PasswordChangeSubmitAction
{
private LoggerInterface $logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
use App\Domain\FilterSetting\FilterModule;
use App\Domain\FilterSetting\FilterSettingSaver;
use App\Domain\User\Service\UserActivityFinder;
use Odan\Session\SessionInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class ListUserActivityAction
class UserActivityFetchListAction
{
/**
* The constructor.
*
* @param Responder $responder The responder
* @param UserActivityFinder $userActivityFinder
* @param SessionInterface $session
* @param FilterSettingSaver $filterSettingSaver
*/
public function __construct(
Expand All @@ -28,7 +26,7 @@ public function __construct(
}

/**
* Client list all and own Action.
* Fetch list of user activity.
*
* @param ServerRequestInterface $request The request
* @param ResponseInterface $response The response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Slim\Exception\HttpBadRequestException;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;

final class UserSubmitCreateAction
final class UserCreateAction
{
protected LoggerInterface $logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class UserSubmitDeleteAction
final class UserDeleteAction
{
/**
* The constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* Post list all and own action.
*/
final class UserListAction
final class UserFetchListAction
{
/**
* The constructor.
Expand All @@ -26,7 +23,7 @@ public function __construct(
}

/**
* Client list all and own Action.
* User fetch list action.
*
* @param ServerRequestInterface $request The request
* @param ResponseInterface $response The response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpBadRequestException;

final class UserSubmitUpdateAction
final class UserUpdateAction
{
private LoggerInterface $logger;

Expand Down
Loading

0 comments on commit deba0d5

Please sign in to comment.