Skip to content

Commit

Permalink
feat: CR - fix php docs, fix store client redirect to valid state
Browse files Browse the repository at this point in the history
  • Loading branch information
kamgrzeski committed Sep 10, 2024
1 parent 4b7ef1b commit 6e4b6a6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/CRM/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function processStoreClient(ClientStoreRequest $request): \Illuminate\Htt
$this->dispatchSync(new StoreSystemLogJob('ClientsModel has been added.', 201, auth()->user()));

// Redirect to the clients page with a success message.
return redirect()->back()->with('message_success', $this->getMessage('messages.client_store'));
return redirect()->to('clients')->with('message_success', $this->getMessage('messages.client_store'));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/CRM/DealsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public function processShowDealsDetails(DealsModel $deal): \Illuminate\View\View
*
* @return \Illuminate\View\View
*/
public function processListOfDeals()
public function processListOfDeals(): \Illuminate\View\View
{
// Load the deal records with pagination.
return view('crm.deals.index')->with([
'dealsPaginate' => $this->dealsService->loadPaginate()
]);
Expand Down
32 changes: 24 additions & 8 deletions app/Http/Controllers/CRM/EmployeesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public function __construct(EmployeesService $employeesService, ClientService $c
*
* @return \Illuminate\View\View
*/
public function processRenderCreateForm()
public function processRenderCreateForm(): \Illuminate\View\View
{
// Load the clients data to be used in the form.
return view('crm.employees.create')->with(['clients' => ClientsQueries::getAll()]);
}

Expand All @@ -55,8 +56,9 @@ public function processRenderCreateForm()
* @param EmployeesModel $employee
* @return \Illuminate\View\View
*/
public function processShowEmployeeDetails(EmployeesModel $employee)
public function processShowEmployeeDetails(EmployeesModel $employee): \Illuminate\View\View
{
// Load the employee record details.
return view('crm.employees.show')->with(['employee' => $employee]);
}

Expand All @@ -65,8 +67,9 @@ public function processShowEmployeeDetails(EmployeesModel $employee)
*
* @return \Illuminate\View\View
*/
public function processListOfEmployees()
public function processListOfEmployees(): \Illuminate\View\View
{
// Load the employee records and render the list page.
return view('crm.employees.index')->with([
'employeesPaginate' => $this->employeesService->loadPaginate()
]);
Expand All @@ -78,8 +81,9 @@ public function processListOfEmployees()
* @param EmployeesModel $employee
* @return \Illuminate\View\View
*/
public function processRenderUpdateForm(EmployeesModel $employee)
public function processRenderUpdateForm(EmployeesModel $employee): \Illuminate\View\View
{
// Load the employee record details and the clients data to be used in the form.
return view('crm.employees.edit')->with([
'employee' => $employee,
'clients' => ClientsQueries::getAll()
Expand All @@ -93,12 +97,15 @@ public function processRenderUpdateForm(EmployeesModel $employee)
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processStoreEmployee(EmployeeStoreRequest $request)
public function processStoreEmployee(EmployeeStoreRequest $request): \Illuminate\Http\RedirectResponse
{
// Dispatch the job to store the employee record.
$this->dispatchSync(new StoreEmployeeJob($request->validated(), auth()->user()));

// Dispatch the job to store the system log.
$this->dispatchSync(new StoreSystemLogJob('Employees has been added.', 201, auth()->user()));

// Redirect to the employees page with a success message.
return redirect()->to('employees')->with('message_success', $this->getMessage('messages.employee_store'));
}

Expand All @@ -110,10 +117,12 @@ public function processStoreEmployee(EmployeeStoreRequest $request)
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processUpdateEmployee(EmployeeUpdateRequest $request, EmployeesModel $employee)
public function processUpdateEmployee(EmployeeUpdateRequest $request, EmployeesModel $employee): \Illuminate\Http\RedirectResponse
{
// Dispatch the job to update the employee record.
$this->dispatchSync(new UpdateEmployeeJob($request->validated(), $employee));

// Dispatch the job to store the system log.
return redirect()->to('employees')->with('message_success', $this->getMessage('messages.employee_update'));
}

Expand All @@ -124,16 +133,20 @@ public function processUpdateEmployee(EmployeeUpdateRequest $request, EmployeesM
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processDeleteEmployee(EmployeesModel $employee)
public function processDeleteEmployee(EmployeesModel $employee): \Illuminate\Http\RedirectResponse
{
// Check if the employee has any tasks assigned.
if ($employee->tasks()->count() > 0) {
return redirect()->back()->with('message_danger', $this->getMessage('messages.task_delete_tasks'));
}

// Dispatch the job to delete the employee record.
$employee->delete();

// Dispatch the job to store the system log.
$this->dispatchSync(new StoreSystemLogJob('Employees has been deleted with id: ' . $employee->id, 201, auth()->user()));

// Redirect to the employees page with a success message.
return redirect()->to('employees')->with('message_success', $this->getMessage('messages.employee_delete'));
}

Expand All @@ -145,12 +158,15 @@ public function processDeleteEmployee(EmployeesModel $employee)
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processEmployeeSetIsActive(EmployeesModel $employee, $value)
public function processEmployeeSetIsActive(EmployeesModel $employee, bool $value): \Illuminate\Http\RedirectResponse
{
// Dispatch the job to update the employee record.
$this->dispatchSync(new UpdateEmployeeJob(['is_active' => $value], $employee));

// Dispatch the job to store the system log.
$this->dispatchSync(new StoreSystemLogJob('Employees has been enabled with id: ' . $employee->id, 201, auth()->user()));

// Redirect to the employees page with a success message.
return redirect()->to('employees')->with('message_success', $this->getMessage('messages.employee_update'));
}
}
15 changes: 15 additions & 0 deletions app/Http/Controllers/CRM/SalesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct(SalesService $salesService, ProductsService $product
*/
public function processRenderCreateForm(): \Illuminate\View\View
{
// Load the products data to be used in the form.
return view('crm.sales.create')->with(['dataOfProducts' => $this->productsService->loadProducts()]);
}

Expand All @@ -56,6 +57,7 @@ public function processRenderCreateForm(): \Illuminate\View\View
*/
public function processShowSalesDetails(SalesModel $sale): \Illuminate\View\View
{
// Load the sale record details.
return view('crm.sales.show')->with(['sale' => $sale]);
}

Expand All @@ -67,6 +69,7 @@ public function processShowSalesDetails(SalesModel $sale): \Illuminate\View\View
*/
public function processRenderUpdateForm(SalesModel $sale): \Illuminate\View\View
{
// Load the sale record details and the products data to be used in the form.
return view('crm.sales.edit')->with([
'sale' => $sale,
'dataWithPluckOfProducts' => $this->productsService->loadProducts()
Expand All @@ -80,6 +83,7 @@ public function processRenderUpdateForm(SalesModel $sale): \Illuminate\View\View
*/
public function processListOfSales(): \Illuminate\View\View
{
// Load the sale records with pagination.
return view('crm.sales.index')->with([
'sales' => $this->salesService->loadSales(),
'salesPaginate' => $this->salesService->loadPaginate()
Expand All @@ -95,10 +99,13 @@ public function processListOfSales(): \Illuminate\View\View
*/
public function processStoreSale(SaleStoreRequest $request): \Illuminate\Http\RedirectResponse
{
// Dispatch the job to store the sale record.
$this->dispatchSync(new StoreSaleJob($request->validated(), auth()->user()));

// Dispatch the job to store the system log.
$this->dispatchSync(new StoreSystemLogJob('SalesModel has been added.', 201, auth()->user()));

// Redirect to the sales list page with a success message.
return redirect()->to('sales')->with('message_success', $this->getMessage('messages.sale_store'));
}

Expand All @@ -112,8 +119,10 @@ public function processStoreSale(SaleStoreRequest $request): \Illuminate\Http\Re
*/
public function processUpdateSale(SaleUpdateRequest $request, SalesModel $sale): \Illuminate\Http\RedirectResponse
{
// Dispatch the job to update the sale record.
$this->dispatchSync(new UpdateSaleJob($request->validated(), $sale));

// Dispatch the job to store the system log.
return redirect()->to('sales')->with('message_success', $this->getMessage('messages.sale_store'));
}

Expand All @@ -126,10 +135,13 @@ public function processUpdateSale(SaleUpdateRequest $request, SalesModel $sale):
*/
public function processDeleteSale(SalesModel $sale): \Illuminate\Http\RedirectResponse
{
// Delete the sale record.
$sale->delete();

// Dispatch the job to store the system log.
$this->dispatchSync(new StoreSystemLogJob('SalesModel has been deleted with id: ' . $sale->id, 201, auth()->user()));

// Redirect to the sales list page with a success message.
return redirect()->to('sales')->with('message_success', $this->getMessage('messages.sale_delete'));
}

Expand All @@ -143,10 +155,13 @@ public function processDeleteSale(SalesModel $sale): \Illuminate\Http\RedirectRe
*/
public function processSaleSetIsActive(SalesModel $sale, bool $value): \Illuminate\Http\RedirectResponse
{
// Dispatch the job to update the sale record.
$this->dispatchSync(new UpdateSaleJob(['is_active' => $value], $sale));

// Dispatch the job to store the system log.
$this->dispatchSync(new StoreSystemLogJob('SalesModel has been enabled with id: ' . $sale->id, 201, auth()->user()));

// Redirect to the sales list page with a success message.
return redirect()->to('sales')->with('message_success', $this->getMessage('messages.sale_update'));
}
}
22 changes: 19 additions & 3 deletions app/Http/Controllers/CRM/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct(TasksService $tasksService, EmployeesService $employ
*/
public function processRenderCreateForm(): \Illuminate\View\View
{
// Load the employees for the task.
return view('crm.tasks.create')->with(['dataOfEmployees' => $this->employeesService->loadEmployees(true)]);
}

Expand All @@ -53,9 +54,8 @@ public function processRenderCreateForm(): \Illuminate\View\View
*/
public function processListOfTasks(): \Illuminate\View\View
{
return view('crm.tasks.index')->with([
'tasksPaginate' => $this->tasksService->loadPaginate()
]);
// Load the tasks with pagination.
return view('crm.tasks.index')->with(['tasksPaginate' => $this->tasksService->loadPaginate()]);
}

/**
Expand All @@ -66,6 +66,7 @@ public function processListOfTasks(): \Illuminate\View\View
*/
public function processShowTasksDetails(TasksModel $task): \Illuminate\View\View
{
// Load the task record.
return view('crm.tasks.show')->with(['task' => $task]);
}

Expand All @@ -77,6 +78,7 @@ public function processShowTasksDetails(TasksModel $task): \Illuminate\View\View
*/
public function processRenderUpdateForm(TasksModel $task): \Illuminate\View\View
{
// Load the task record for editing.
return view('crm.tasks.edit')->with([
'task' => $task,
'employees' => $this->employeesService->loadEmployees()
Expand All @@ -92,10 +94,13 @@ public function processRenderUpdateForm(TasksModel $task): \Illuminate\View\View
*/
public function processStoreTask(TaskStoreRequest $request): \Illuminate\Http\RedirectResponse
{
// Store task.
$this->dispatchSync(new StoreTaskJob($request->validated(), auth()->user()));

// Log the task creation.
$this->dispatchSync(new StoreSystemLogJob('Task has been added.', 201, auth()->user()));

// Redirect to the tasks page with a success message.
return redirect()->to('tasks')->with('message_success', $this->getMessage('messages.task_store'));
}

Expand All @@ -109,8 +114,10 @@ public function processStoreTask(TaskStoreRequest $request): \Illuminate\Http\Re
*/
public function processUpdateTask(TaskUpdateRequest $request, TasksModel $task): \Illuminate\Http\RedirectResponse
{
// Update task.
$this->dispatchSync(new UpdateTaskJob($request->validated(), $task));

// Log the task update.
return redirect()->to('tasks')->with('message_success', $this->getMessage('messages.task_update'));
}

Expand All @@ -123,15 +130,18 @@ public function processUpdateTask(TaskUpdateRequest $request, TasksModel $task):
*/
public function processDeleteTask(TasksModel $task): \Illuminate\Http\RedirectResponse
{
// Check if the task is completed.
if (! $task->completed) {
return redirect()->back()->with('message_danger', $this->getMessage('messages.task_uncompleted'));
}

// Delete task.
$task->delete();

// Log the task deletion.
$this->dispatchSync(new StoreSystemLogJob('Tasks has been deleted with id: ' . $task->id, 201, auth()->user()));

// Redirect to the tasks page with a success message.
return redirect()->to('tasks')->with('message_success', $this->getMessage('messages.task_delete'));
}

Expand All @@ -145,10 +155,13 @@ public function processDeleteTask(TasksModel $task): \Illuminate\Http\RedirectRe
*/
public function processTaskSetIsActive(TasksModel $task, bool $value): \Illuminate\Http\RedirectResponse
{
// Update the task status.
$this->dispatchSync(new UpdateTaskJob(['is_active' => $value], $task));

// Log the task status change.
$this->dispatchSync(new StoreSystemLogJob('Tasks has been enabled with id: ' . $task->id, 201, auth()->user()));

// Redirect to the tasks page with a success message.
return redirect()->to('tasks')->with('message_success', $this->getMessage('messages.task_update'));
}

Expand All @@ -161,10 +174,13 @@ public function processTaskSetIsActive(TasksModel $task, bool $value): \Illumina
*/
public function processSetTaskToCompleted(TasksModel $task): \Illuminate\Http\RedirectResponse
{
// Update the task to complete.
$this->dispatchSync(new UpdateTaskJob(['completed' => true], $task));

// Log the task completion.
$this->dispatchSync(new StoreSystemLogJob('Tasks has been completed with id: ' . $task->id, 201, auth()->user()));

// Redirect to the tasks page with a success message.
return redirect()->back()->with('message_success', $this->getMessage('messages.task_completed'));
}
}
11 changes: 6 additions & 5 deletions app/Jobs/StoreSystemLogJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\AdminModel;
use App\Models\SystemLogsModel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
Expand All @@ -16,18 +17,18 @@ class StoreSystemLogJob implements ShouldQueue

private string $actions;
private int $statusCode;
private AdminModel $admin;
private Authenticatable $authUser;

/**
* Create a new job instance.
*
* @return void
*/
public function __construct(string $actions, int $statusCode, AdminModel $admin)
public function __construct(string $actions, int $statusCode, Authenticatable $authUser)
{
$this->actions = $actions;
$this->statusCode = $statusCode;
$this->admin = $admin;
$this->authUser = $authUser;
}

/**
Expand All @@ -37,11 +38,11 @@ public function __construct(string $actions, int $statusCode, AdminModel $admin)
*/
public function handle(): void
{
$userInformation = $this->admin->getUserInformation();
$userInformation = $this->authUser->getUserInformation();

$model = new SystemLogsModel();

$model->admin_id = $this->admin->id;
$model->admin_id = $this->authUser->id;
$model->actions = $this->actions;
$model->status_code = $this->statusCode;
$model->date = now();
Expand Down

0 comments on commit 6e4b6a6

Please sign in to comment.