Skip to content

Commit

Permalink
chore: refactor controllers, queries, relations
Browse files Browse the repository at this point in the history
  • Loading branch information
kamgrzeski committed Nov 26, 2024
1 parent 89af6ce commit b98e6dc
Show file tree
Hide file tree
Showing 68 changed files with 487 additions and 536 deletions.
28 changes: 13 additions & 15 deletions app/Http/Controllers/CRM/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use App\Jobs\Client\StoreClientJob;
use App\Jobs\Client\UpdateClientJob;
use App\Jobs\StoreSystemLogJob;
use App\Models\ClientsModel;
use App\Queries\ClientsQueries;
use App\Models\Client;
use App\Queries\ClientQueries;
use App\Services\ClientService;
use Illuminate\Foundation\Bus\DispatchesJobs;

Expand All @@ -30,8 +30,6 @@ class ClientController extends Controller
*/
public function __construct(ClientService $clientService)
{
$this->middleware(self::MIDDLEWARE_AUTH);

$this->clientService = $clientService;
}

Expand All @@ -49,10 +47,10 @@ public function processRenderCreateForm(): \Illuminate\View\View
/**
* Show the details of a specific client record.
*
* @param ClientsModel $client
* @param Client $client
* @return \Illuminate\View\View
*/
public function processShowClientDetails(ClientsModel $client): \Illuminate\View\View
public function processShowClientDetails(Client $client): \Illuminate\View\View
{
// Return the view with the client details.
return view('crm.clients.show')->with(['client' => $this->clientService->loadClientDetails($client)]);
Expand All @@ -61,10 +59,10 @@ public function processShowClientDetails(ClientsModel $client): \Illuminate\View
/**
* Render the form for updating an existing client record.
*
* @param ClientsModel $client
* @param Client $client
* @return \Illuminate\View\View
*/
public function processRenderUpdateForm(ClientsModel $client): \Illuminate\View\View
public function processRenderUpdateForm(Client $client): \Illuminate\View\View
{
// Return the view for updating the client record.
return view('crm.clients.update')->with(['client' => $this->clientService->loadClientDetails($client)]);
Expand All @@ -79,7 +77,7 @@ public function processListOfClients(): \Illuminate\View\View
{
// Return the view with the paginated list of clients.
return view('crm.clients.index')->with([
'clients' => ClientsQueries::getPaginate()
'clients' => ClientQueries::getPaginate()
]);
}

Expand All @@ -106,11 +104,11 @@ public function processStoreClient(ClientStoreRequest $request): \Illuminate\Htt
* Update an existing client record.
*
* @param ClientUpdateRequest $request
* @param ClientsModel $client
* @param Client $client
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processUpdateClient(ClientUpdateRequest $request, ClientsModel $client)
public function processUpdateClient(ClientUpdateRequest $request, Client $client)
{
// UpdateClientJob is a job that updates the client model.
$this->dispatchSync(new UpdateClientJob($request->validated(), $client));
Expand All @@ -122,11 +120,11 @@ public function processUpdateClient(ClientUpdateRequest $request, ClientsModel $
/**
* Delete a client record.
*
* @param ClientsModel $client
* @param Client $client
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processDeleteClient(ClientsModel $client): \Illuminate\Http\RedirectResponse
public function processDeleteClient(Client $client): \Illuminate\Http\RedirectResponse
{
// Delete the client model.
$client->delete();
Expand All @@ -138,11 +136,11 @@ public function processDeleteClient(ClientsModel $client): \Illuminate\Http\Redi
/**
* Set the active status of a client record.
*
* @param ClientsModel $client
* @param Client $client
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processClientSetIsActive(ClientsModel $client): \Illuminate\Http\RedirectResponse
public function processClientSetIsActive(Client $client): \Illuminate\Http\RedirectResponse
{
// UpdateClientJob is a job that updates the client model.
$this->dispatchSync(new UpdateClientJob(['is_active' => ! $client->is_active], $client));
Expand Down
50 changes: 16 additions & 34 deletions app/Http/Controllers/CRM/CompaniesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use App\Jobs\Company\StoreCompanyJob;
use App\Jobs\Company\UpdateCompanyJob;
use App\Jobs\StoreSystemLogJob;
use App\Models\CompaniesModel;
use App\Queries\ClientsQueries;
use App\Queries\CompaniesQueries;
use App\Services\CompaniesService;
use App\Services\DealsService;
use App\Models\Company;
use App\Queries\ClientQueries;
use App\Queries\CompanyQueries;
use Illuminate\Foundation\Bus\DispatchesJobs;

/**
Expand All @@ -23,22 +21,6 @@
class CompaniesController extends Controller
{
use DispatchesJobs;
private CompaniesService $companiesService;
private DealsService $dealsService;

/**
* CompaniesController constructor.
*
* @param CompaniesService $companiesService
* @param DealsService $dealsService
*/
public function __construct(CompaniesService $companiesService, DealsService $dealsService)
{
$this->middleware(self::MIDDLEWARE_AUTH);

$this->companiesService = $companiesService;
$this->dealsService = $dealsService;
}

/**
* Render the form for creating a new company record.
Expand All @@ -48,16 +30,16 @@ public function __construct(CompaniesService $companiesService, DealsService $de
public function processRenderCreateForm(): \Illuminate\View\View
{
// Return view with clients.
return view('crm.companies.create')->with(['clients' => ClientsQueries::getAll()]);
return view('crm.companies.create')->with(['clients' => ClientQueries::getAll()]);
}

/**
* Show the details of a specific company record.
*
* @param CompaniesModel $company
* @param Company $company
* @return \Illuminate\View\View
*/
public function processViewCompanyDetails(CompaniesModel $company): \Illuminate\View\View
public function processViewCompanyDetails(Company $company): \Illuminate\View\View
{
// Return view with company details.
return view('crm.companies.show')->with(['company' => $company]);
Expand All @@ -72,22 +54,22 @@ public function processListOfCompanies(): \Illuminate\View\View
{
// Return view with companies pagination.
return view('crm.companies.index')->with([
'companies' => CompaniesQueries::getPaginate()
'companies' => CompanyQueries::getPaginate()
]);
}

/**
* Render the form for updating an existing company record.
*
* @param CompaniesModel $company
* @param Company $company
* @return \Illuminate\View\View
*/
public function processRenderUpdateForm(CompaniesModel $company): \Illuminate\View\View
public function processRenderUpdateForm(Company $company): \Illuminate\View\View
{
// Return view with company and clients
return view('crm.companies.update')->with([
'company' => $company,
'clients' => ClientsQueries::getAll()
'clients' => ClientQueries::getAll()
]);
}

Expand All @@ -114,11 +96,11 @@ public function processStoreCompany(CompanyStoreRequest $request): \Illuminate\H
* Update an existing company record.
*
* @param CompanyUpdateRequest $request
* @param CompaniesModel $company
* @param Company $company
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processUpdateCompany(CompanyUpdateRequest $request, CompaniesModel $company): \Illuminate\Http\RedirectResponse
public function processUpdateCompany(CompanyUpdateRequest $request, Company $company): \Illuminate\Http\RedirectResponse
{
// Update company.
$this->dispatchSync(new UpdateCompanyJob($request->validated(), $company));
Expand All @@ -130,11 +112,11 @@ public function processUpdateCompany(CompanyUpdateRequest $request, CompaniesMod
/**
* Delete a company record.
*
* @param CompaniesModel $company
* @param Company $company
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processDeleteCompany(CompaniesModel $company): \Illuminate\Http\RedirectResponse
public function processDeleteCompany(Company $company): \Illuminate\Http\RedirectResponse
{
// Check if company has deals.
if ($company->deals()->count() > 0) {
Expand All @@ -154,11 +136,11 @@ public function processDeleteCompany(CompaniesModel $company): \Illuminate\Http\
/**
* Set the active status of a company record.
*
* @param CompaniesModel $company
* @param Company $company
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processCompanySetIsActive(CompaniesModel $company): \Illuminate\Http\RedirectResponse
public function processCompanySetIsActive(Company $company): \Illuminate\Http\RedirectResponse
{
// Update company status.
$this->dispatchSync(new UpdateCompanyJob(['is_active' => ! $company->is_active], $company));
Expand Down
54 changes: 26 additions & 28 deletions app/Http/Controllers/CRM/DealsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
use App\Jobs\Deal\StoreDealTermJob;
use App\Jobs\Deal\UpdateDealJob;
use App\Jobs\StoreSystemLogJob;
use App\Models\DealsModel;
use App\Models\DealsTermsModel;
use App\Queries\CompaniesQueries;
use App\Queries\DealsQueries;
use App\Models\Deal;
use App\Models\DealTerm;
use App\Queries\CompanyQueries;
use App\Queries\DealQueries;
use App\Services\DealsService;
use Illuminate\Foundation\Bus\DispatchesJobs;

Expand All @@ -34,8 +34,6 @@ class DealsController extends Controller
*/
public function __construct(DealsService $dealsService)
{
$this->middleware(self::MIDDLEWARE_AUTH);

$this->dealsService = $dealsService;
}

Expand All @@ -47,21 +45,21 @@ public function __construct(DealsService $dealsService)
public function processRenderCreateForm(): \Illuminate\View\View
{
// Load the companies for the dropdown.
return view('crm.deals.create')->with(['companies' => CompaniesQueries::getAll()]);
return view('crm.deals.create')->with(['companies' => CompanyQueries::getAll()]);
}

/**
* Show the details of a specific deal record.
*
* @param DealsModel $deal
* @param Deal $deal
* @return \Illuminate\View\View
*/
public function processShowDealsDetails(DealsModel $deal): \Illuminate\View\View
public function processShowDealsDetails(Deal $deal): \Illuminate\View\View
{
// Load the deal record details.
return view('crm.deals.show')->with([
'deal' => $deal,
'companies' => CompaniesQueries::getAll()
'companies' => CompanyQueries::getAll()
]);
}

Expand All @@ -74,22 +72,22 @@ public function processListOfDeals(): \Illuminate\View\View
{
// Load the deal records with pagination.
return view('crm.deals.index')->with([
'deals' => DealsQueries::getPaginate()
'deals' => DealQueries::getPaginate()
]);
}

/**
* Render the form for updating an existing deal record.
*
* @param DealsModel $deal
* @param Deal $deal
* @return \Illuminate\View\View
*/
public function processRenderUpdateForm(DealsModel $deal): \Illuminate\View\View
public function processRenderUpdateForm(Deal $deal): \Illuminate\View\View
{
// Load the deal record for editing.
return view('crm.deals.update')->with([
'deal' => $deal,
'companies' => CompaniesQueries::getAll(),
'companies' => CompanyQueries::getAll(),
]);
}

Expand All @@ -116,11 +114,11 @@ public function processStoreDeal(DealStoreRequest $request): \Illuminate\Http\Re
* Update an existing deal record.
*
* @param DealUpdateRequest $request
* @param DealsModel $deal
* @param Deal $deal
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processUpdateDeal(DealUpdateRequest $request, DealsModel $deal)
public function processUpdateDeal(DealUpdateRequest $request, Deal $deal)
{
// Update the deal record.
$this->dispatchSync(new UpdateDealJob($request->validated(), $deal));
Expand All @@ -132,11 +130,11 @@ public function processUpdateDeal(DealUpdateRequest $request, DealsModel $deal)
/**
* Delete a deal record.
*
* @param DealsModel $deal
* @param Deal $deal
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processDeleteDeal(DealsModel $deal): \Illuminate\Http\RedirectResponse
public function processDeleteDeal(Deal $deal): \Illuminate\Http\RedirectResponse
{
// Check if the deal has any deal terms.
if ($deal->dealTerms()->count() > 0) {
Expand All @@ -156,11 +154,11 @@ public function processDeleteDeal(DealsModel $deal): \Illuminate\Http\RedirectRe
/**
* Set the active status of a deal record.
*
* @param DealsModel $deal
* @param Deal $deal
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processSetIsActive(DealsModel $deal): \Illuminate\Http\RedirectResponse
public function processSetIsActive(Deal $deal): \Illuminate\Http\RedirectResponse
{
// Update the deal status.
$this->dispatchSync(new UpdateDealJob(['is_active' => ! $deal->is_active], $deal));
Expand All @@ -176,11 +174,11 @@ public function processSetIsActive(DealsModel $deal): \Illuminate\Http\RedirectR
* Store new deal terms.
*
* @param StoreDealTermRequest $request
* @param DealsModel $deal
* @param Deal $deal
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processStoreDealTerms(StoreDealTermRequest $request, DealsModel $deal): \Illuminate\Http\RedirectResponse
public function processStoreDealTerms(StoreDealTermRequest $request, Deal $deal): \Illuminate\Http\RedirectResponse
{
// Store the deal terms.
$this->dispatchSync(new StoreDealTermJob($request->validated(), $deal));
Expand All @@ -195,11 +193,11 @@ public function processStoreDealTerms(StoreDealTermRequest $request, DealsModel
/**
* Generate deal terms in PDF format.
*
* @param DealsTermsModel $dealTerm
* @param DealsModel $deal
* @param DealTerm $dealTerm
* @param Deal $deal
* @return mixed
*/
public function processGenerateDealTermsInPDF(DealsTermsModel $dealTerm, DealsModel $deal): mixed
public function processGenerateDealTermsInPDF(DealTerm $dealTerm, Deal $deal): mixed
{
// Load the deal terms in PDF format.
return $this->dealsService->loadGenerateDealTermsInPDF($dealTerm, $deal);
Expand All @@ -208,11 +206,11 @@ public function processGenerateDealTermsInPDF(DealsTermsModel $dealTerm, DealsMo
/**
* Delete a deal term record.
*
* @param DealsTermsModel $dealTerm
* @param DealTerm $dealTerm
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processDeleteDealTerm(DealsTermsModel $dealTerm): \Illuminate\Http\RedirectResponse
public function processDeleteDealTerm(DealTerm $dealTerm): \Illuminate\Http\RedirectResponse
{
// Check if the deal term has been used in any deal
$dealTerm->delete();
Expand All @@ -224,7 +222,7 @@ public function processDeleteDealTerm(DealsTermsModel $dealTerm): \Illuminate\Ht
return redirect()->back()->with('message_success', $this->getMessage('messages.deal_term_delete'));
}

public function processRenderTermCreateForm(DealsModel $deal)
public function processRenderTermCreateForm(Deal $deal)
{
return view('crm.deals.terms.create')->with(['deal' => $deal]);
}
Expand Down
Loading

0 comments on commit b98e6dc

Please sign in to comment.