Skip to content

Commit b4f74a3

Browse files
authored
Merge pull request #150 from Riyad-Murad/backend_structure_adjustment
backend_structure_adjustment: Grouped Services, created new trait for…
2 parents 3b5bfed + d7fe9d0 commit b4f74a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+616
-738
lines changed

amp-laravel/app/Http/Controllers/Admin/AdminFunctionsController.php renamed to amp-laravel/app/Http/Controllers/Admin/AdminController.php

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,53 @@
22

33
namespace App\Http\Controllers\Admin;
44

5-
use Illuminate\Http\Request;
65
use App\Http\Controllers\Controller;
6+
use App\Services\Admin\ProviderService;
7+
use App\Services\Admin\ContactFormService;
8+
use App\Services\Admin\EditProfileService;
79
use App\Http\Requests\Admin\EditProfileRequest;
810
use App\Http\Requests\Admin\EditProviderRequest;
9-
use App\Services\Admin\editProfileService;
10-
use App\Services\Admin\getAllProvidersService;
11-
use App\Services\Admin\DeleteContactMessageService;
12-
use App\Services\Admin\getAllContactMessagesService;
13-
use App\Services\Admin\AdminEditProviderProfileService;
1411
use Illuminate\Database\Eloquent\ModelNotFoundException;
1512

16-
class AdminFunctionsController extends Controller
13+
class AdminController extends Controller
1714
{
1815
public function getProviders()
1916
{
2017
try {
21-
$providers = getAllProvidersService::getAll();
18+
$providers = ProviderService::getAll();
2219

2320
return $this->messageResponse(true, "Providers retrieved successfully", 200, $providers);
2421
} catch (\Exception $e) {
2522
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve providers", 500);
2623
}
2724
}
2825

29-
public function getContactMessages()
30-
{
31-
try {
32-
$messages = getAllContactMessagesService::getAll();
33-
34-
return $this->messageResponse(true, "Messages retrieved successfully", 200, $messages);
35-
} catch (\Exception $e) {
36-
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve messages", 500);
37-
}
38-
}
39-
4026
public function editProvider(EditProviderRequest $request, $id)
4127
{
4228
try {
43-
AdminEditProviderProfileService::editProfile($id, $request->validated());
29+
ProviderService::editProfile($id, $request->validated());
4430

4531
return $this->messageResponse(true, "Profile updated successfully", 200);
4632
} catch (\Exception $e) {
4733
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to update profile", 500);
4834
}
4935
}
5036

51-
52-
public function editProfile(EditProfileRequest $request)
37+
public function getContactMessages()
5338
{
5439
try {
55-
editProfileService::editProfile($request->validated());
40+
$messages = ContactFormService::getAll();
5641

57-
return $this->messageResponse(true, "Profile updated successfully", 200);
42+
return $this->messageResponse(true, "Messages retrieved successfully", 200, $messages);
5843
} catch (\Exception $e) {
59-
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to update profile", 500);
44+
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve messages", 500);
6045
}
6146
}
6247

6348
public function deleteMessage($id)
6449
{
6550
try {
66-
DeleteContactMessageService::delete($id);
51+
ContactFormService::delete($id);
6752

6853
return $this->messageResponse(true, "Message deleted successfully", 200);
6954
} catch (ModelNotFoundException $e) {
@@ -72,4 +57,15 @@ public function deleteMessage($id)
7257
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to delete message", 500);
7358
}
7459
}
60+
61+
public function editProfile(EditProfileRequest $request)
62+
{
63+
try {
64+
EditProfileService::editProfile($request->validated());
65+
66+
return $this->messageResponse(true, "Profile updated successfully", 200);
67+
} catch (\Exception $e) {
68+
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to update profile", 500);
69+
}
70+
}
7571
}

amp-laravel/app/Http/Controllers/Clients/ClientFunctionsController.php renamed to amp-laravel/app/Http/Controllers/Client/ClientController.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<?php
22

3-
namespace App\Http\Controllers\Clients;
3+
namespace App\Http\Controllers\Client;
44

55
use App\Http\Controllers\Controller;
6-
use App\Services\Client\ClientDashboardService;
7-
use App\Services\Client\GeneratingReportService;
8-
use App\Services\Client\ClientEditProfileService;
6+
use App\Services\Client\ClientService;
97
use App\Http\Requests\Client\EditProfileRequest;
108

11-
class ClientFunctionsController extends Controller
9+
class ClientController extends Controller
1210
{
1311
public function generateReport($id)
1412
{
@@ -18,7 +16,7 @@ public function generateReport($id)
1816
return $this->messageResponse(false, "Route ID not provided", 400, null);
1917
}
2018

21-
$report = GeneratingReportService::generateReport($id);
19+
$report = ClientService::generateReport($id);
2220
return $this->messageResponse(true, "Report Generated", 200, $report);
2321
} catch (\Exception $e) {
2422
return $this->errorMessageResponse(false, "Failed to generate report ", $e->getMessage(), 500);
@@ -28,7 +26,7 @@ public function generateReport($id)
2826
public function editProfile(EditProfileRequest $request)
2927
{
3028
try {
31-
ClientEditProfileService::editProfile($request->validated());
29+
ClientService::editProfile($request->validated());
3230

3331
return $this->messageResponse(true, "Profile updated successfully", 200);
3432
} catch (\Exception $e) {
@@ -39,7 +37,7 @@ public function editProfile(EditProfileRequest $request)
3937
public function getDashboardData($id)
4038
{
4139
try {
42-
$dashboardData = ClientDashboardService::getDashboardData($id);
40+
$dashboardData = ClientService::getDashboardData($id);
4341
return $this->messageResponse(true, "Dashboard data fetched successfully", 200, $dashboardData);
4442
} catch (\Exception $e) {
4543
return $this->errorMessageResponse(false, "Failed to fetch dashboard data", $e->getMessage(), 500);

amp-laravel/app/Http/Controllers/Common/ClientCheckinController.php

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Common;
4+
5+
use App\Http\Controllers\Controller;
6+
7+
use Throwable;
8+
use InvalidArgumentException;
9+
use App\Services\IotService;
10+
use App\Http\Requests\Client\ClientRequestMetric;
11+
use App\Http\Requests\Client\ClientRequestCheckin;
12+
use App\Http\Requests\Provider\ProviderRequestLine;
13+
use App\Http\Requests\Provider\ProviderRequestCheckin;
14+
15+
class IotController extends Controller
16+
{
17+
// Master Check In
18+
public function masterCheckin(ProviderRequestCheckin $request)
19+
{
20+
try {
21+
$data = IotService::masterCheckin($request->validated());
22+
return $this->messageResponse(true, "Master checked in successfully", 200, $data);
23+
} catch (Throwable $e) {
24+
return $this->errorMessageResponse(false, "Master checkin failed", $e->getMessage(), 500);
25+
}
26+
}
27+
28+
// Slave Check In
29+
public function slaveCheckin(ClientRequestCheckin $request)
30+
{
31+
try {
32+
$slave = IotService::slaveCheckin($request->validated());
33+
34+
return $this->messageResponse(true, "Slave Checkin Successful", 200, $slave);
35+
} catch (InvalidArgumentException $e) {
36+
return $this->errorMessageResponse(false, 'Invalid Input', $e->getMessage(), 422);
37+
} catch (Throwable $e) {
38+
return $this->errorMessageResponse(false, "Slave checkin failed", $e->getMessage(), 500);
39+
} catch (\Exception $e) {
40+
return $this->errorMessageResponse(false, 'Unexpected error', $e->getMessage(), 500);
41+
}
42+
}
43+
44+
// Slave Metrics
45+
public function slaveMetrics(ClientRequestMetric $request)
46+
{
47+
try {
48+
$metric = IotService::addMetrics($request->validated());
49+
return $this->messageResponse(true, "Slave metric stored", 200, $metric);
50+
} catch (InvalidArgumentException $e) {
51+
return $this->errorMessageResponse(false, 'Invalid Input', $e->getMessage(), 422);
52+
} catch (Throwable $e) {
53+
return $this->errorMessageResponse(false, "Metric save failed", $e->getMessage(), 500);
54+
}
55+
}
56+
57+
// Master Lines
58+
public function masterLines(ProviderRequestLine $request)
59+
{
60+
try {
61+
$line = IotService::addLines($request->validated());
62+
return $this->messageResponse(true, "Master lines data saved", 200, $line);
63+
} catch (Throwable $e) {
64+
return $this->errorMessageResponse(false, "Failed to save master lines", $e->getMessage(), 500);
65+
}
66+
}
67+
}

amp-laravel/app/Http/Controllers/Common/LinesController.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

amp-laravel/app/Http/Controllers/Common/MetricsController.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

amp-laravel/app/Http/Controllers/Common/ProviderCheckinController.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)