-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
96 changed files
with
2,538 additions
and
191 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
Website/htdocs/mpmanager/app/Console/Commands/AddEBikesItemToNavbar.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Services\MenuItemsService; | ||
use Illuminate\Console\Command; | ||
|
||
class AddEBikesItemToNavbar extends AbstractSharedCommand | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'navbar:add-ebikes-item'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Add ebikes item to navbar'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(private MenuItemsService $menuItemsService,) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
$this->addSolarHomeSystemsToNavBar(); | ||
return 0; | ||
} | ||
|
||
private function addSolarHomeSystemsToNavBar() | ||
{ | ||
$eBikesMenuItem = 'E-Bikes'; | ||
$menuItem = $this->menuItemsService->getByName($eBikesMenuItem); | ||
|
||
if (!$menuItem) { | ||
$this->menuItemsService->create([ | ||
'name' => $eBikesMenuItem, | ||
'url_slug' => '/e-bikes/page/1', | ||
'md_icon' => 'electric_bike', | ||
'menu_order' => 0, | ||
]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
Website/htdocs/mpmanager/app/Http/Controllers/EBikeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Requests\StoreEBikeRequest; | ||
use App\Http\Resources\ApiResource; | ||
use App\Services\AppliancePersonService; | ||
use App\Services\ManufacturerService; | ||
use MPM\Device\DeviceService; | ||
use MPM\EBike\EBikeDeviceService; | ||
use MPM\EBike\EBikeService; | ||
use Illuminate\Http\Request; | ||
|
||
class EBikeController extends Controller | ||
{ | ||
public function __construct( | ||
private DeviceService $deviceService, | ||
private EBikeService $eBikeService, | ||
private EBikeDeviceService $eBikeDeviceService, | ||
private ManufacturerService $manufacturerService, | ||
private AppliancePersonService $appliancePersonService | ||
) { | ||
} | ||
|
||
public function index(Request $request): ApiResource | ||
{ | ||
$limit = $request->input('per_page'); | ||
return ApiResource::make($this->eBikeService->getAll($limit)); | ||
} | ||
|
||
public function store(StoreEBikeRequest $request) | ||
{ | ||
$eBikeData = $request->all(); | ||
$deviceData = [ | ||
'device_serial' => $eBikeData['serial_number'], | ||
'person_id' => null | ||
]; | ||
|
||
$device = $this->deviceService->make($deviceData); | ||
$eBike = $this->eBikeService->create($eBikeData); | ||
$this->eBikeDeviceService->setAssigned($device); | ||
$this->eBikeDeviceService->setAssignee($eBike); | ||
$this->eBikeDeviceService->assign(); | ||
$this->deviceService->save($device); | ||
|
||
return ApiResource::make($eBike->load(['manufacturer', 'appliance', 'device.person'])); | ||
} | ||
|
||
public function search(Request $request): ApiResource | ||
{ | ||
$term = $request->input('term'); | ||
$paginate = $request->input('paginate') ?? 1; | ||
|
||
return ApiResource::make($this->eBikeService->search($term, $paginate)); | ||
} | ||
|
||
public function show(string $serialNumber): ApiResource | ||
{ | ||
return ApiResource::make($this->eBikeService->getBySerialNumber($serialNumber)); | ||
} | ||
|
||
public function switch(Request $request): ApiResource | ||
{ | ||
$serialNumber = $request->input('serial_number'); | ||
$manufacturerName = $request->input('manufacturer_name'); | ||
$status = $request->input('status'); | ||
$manufacturer = $this->manufacturerService->getByName($manufacturerName); | ||
$manufacturerApi = resolve($manufacturer->api_name); | ||
$manufacturerApi->switchDevice($serialNumber, $status); | ||
$creatorId = auth('api')->user()->id; | ||
$appliancePerson = $this->appliancePersonService->getBySerialNumber($serialNumber); | ||
event( | ||
'new.log', | ||
[ | ||
'logData' => [ | ||
'user_id' => $creatorId, | ||
'affected' => $appliancePerson, | ||
'action' => 'Bike (' . $serialNumber . ') is set as ' . $status . ' manually.' | ||
] | ||
] | ||
); | ||
return ApiResource::make($this->eBikeService->getBySerialNumber($serialNumber)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Website/htdocs/mpmanager/app/Http/Requests/StoreEBikeRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class StoreEBikeRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'serial_number' => 'required|min:8|max:15|unique:shard.devices,device_serial', | ||
'manufacturer_id' => 'required|exists:shard.manufacturers,id', | ||
'asset_id' => 'required|exists:shard.assets,id', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.