Skip to content

Commit

Permalink
fix new targer page endpoint #124
Browse files Browse the repository at this point in the history
  • Loading branch information
beesaferoot committed Dec 30, 2024
1 parent 686192b commit 7c398e0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/backend/app/Http/Controllers/MeterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,8 @@ public function update(UpdateMeterRequest $request, Meter $meter): ApiResource {

return ApiResource::make($updatedMeter);
}

public function showConnectionTypes(): ApiResource {
return ApiResource::make($this->meterService->getNumberOfConnectionTypes());
}
}
8 changes: 8 additions & 0 deletions src/backend/app/Services/MeterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Services\Interfaces\IBaseService;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;

/**
* @implements IBaseService<Meter>
Expand Down Expand Up @@ -107,4 +108,11 @@ public function update($meter, array $meterData): Meter {

return $meter;
}

public function getNumberOfConnectionTypes(): Collection|array {
return $this->meter->newQuery()->join('connection_types', 'meters.connection_type_id', '=', 'connection_types.id')
->select('connection_type_id', DB::raw('count(*) as total'))
->groupBy('connection_type_id')
->get();
}
}
1 change: 1 addition & 0 deletions src/backend/routes/resources/Meters.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Route::group(['prefix' => 'meters'], function () {
Route::get('/', 'MeterController@index');
Route::post('/', 'MeterController@store');
Route::get('/connection-types', 'MeterController@showConnectionTypes');
Route::put('/{meter}', 'MeterController@update');
Route::get('/search', 'MeterController@search');
Route::get('/{serialNumber}', 'MeterController@show');
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export let resources = {
connections: {
list: "/api/connection-groups",
sublist: "/api/sub-connection-types",
number_of_customers: "/api/meters/parameters/connection-types",
number_of_customers: "/api/meters/connection-types",
store: "/api/connection-types",
},
clusters: {
Expand Down

0 comments on commit 7c398e0

Please sign in to comment.