-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProviderFunctionsController.php
More file actions
147 lines (128 loc) · 5.59 KB
/
ProviderFunctionsController.php
File metadata and controls
147 lines (128 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace App\Http\Controllers\Provider;
use App\Http\Controllers\Controller;
use App\Services\Provider\GetAllLinesService;
use App\Http\Requests\Provider\EditUserRequest;
use App\Services\Provider\EditClientUserService;
use App\Services\Provider\GetOverviewDataService;
use App\Services\Provider\GetMetricSummaryService;
use App\Services\Provider\GeneratingReportService;
use App\Http\Requests\Provider\EditProfileRequest;
use App\Services\Provider\GetAllClientUsersService;
use App\Services\Provider\GetAverageVoltageService;
use App\Services\Provider\GetTotalPowerUsageService;
use App\Services\Provider\ProviderEditProfileService;
use App\Services\Provider\GetAllClientMetricsService;
use App\Services\Provider\GetPowerUsageByClientService;
use App\Services\Provider\GetVoltageDistributionService;
class ProviderFunctionsController extends Controller
{
public function generateReport()
{
try {
$report = GeneratingReportService::generateReport();
return $this->messageResponse(true, "Report Generated", 200, $report);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, "Failed to generate report ", $e->getMessage(), 500);
}
}
public function editProfile(EditProfileRequest $request)
{
try {
ProviderEditProfileService::editProfile($request->validated());
return $this->messageResponse(true, "Profile updated successfully", 200);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to update profile", 500);
}
}
public function editUser(EditUserRequest $request, $id)
{
try {
EditClientUserService::editUser($id, $request->validated());
return $this->messageResponse(true, "Profile updated successfully", 200);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to update profile", 500);
}
}
public function getUsers($id)
{
try {
$users = GetAllClientUsersService::getAll($id);
return $this->messageResponse(true, "Users retrieved successfully", 200, $users);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve users", 500);
}
}
public function getMetrics($id)
{
try {
$metrics = GetAllClientMetricsService::getAll($id);
return $this->messageResponse(true, "Metrics retrieved successfully", 200, $metrics);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve metrics", 500);
}
}
public function getLines($id)
{
try {
$lines = GetAllLinesService::getAll($id);
return $this->messageResponse(true, "Lines retrieved successfully", 200, $lines);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve lines", 500);
}
}
public function getOverviewData($id)
{
try {
$overviewData = GetOverviewDataService::getOverviewData($id);
return $this->messageResponse(true, "Overview data retrieved successfully", 200, $overviewData);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve overview data", 500);
}
}
public function getTotalPowerUsage($id)
{
try {
$totalPower = GetTotalPowerUsageService::getTotalPowerUsage($id);
return $this->messageResponse(true, "Total power usage retrieved successfully", 200, $totalPower);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve total power usage", 500);
}
}
public function getAverageVoltage($id)
{
try {
$averageVoltage = GetAverageVoltageService::getAverageVoltage($id);
return $this->messageResponse(true, "Average voltage retrieved successfully", 200, $averageVoltage);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve average voltage", 500);
}
}
public function getPowerUsageByClient($id)
{
try {
$powerUsageByClient = GetPowerUsageByClientService::getPowerUsageByClient($id);
return $this->messageResponse(true, "Power usage by client retrieved successfully", 200, $powerUsageByClient);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve power usage by client", 500);
}
}
public function getVoltageDistribution($id)
{
try {
$voltageDistribution = GetVoltageDistributionService::getVoltageDistribution($id);
return $this->messageResponse(true, "Voltage distribution retrieved successfully", 200, $voltageDistribution);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve voltage distribution", 500);
}
}
public function getMetricsSummary($id)
{
try {
$metricsSummary = GetMetricSummaryService::getMetricSummary($id);
return $this->messageResponse(true, "Metrics summary retrieved successfully", 200, $metricsSummary);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve metrics summary", 500);
}
}
}