Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPM-8] New API to get usage types & Create Company API & Update MainSettings API #40

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function store(CompanyRegistrationRequest $request): JsonResponse

$adminData = $request->input('user');
$plugins = $request->input('plugins');
$usageType = $request->input('usage_type');

$companyDatabaseData = [
'company_id' => $company->getId(),
Expand All @@ -51,7 +52,7 @@ public function store(CompanyRegistrationRequest $request): JsonResponse

return $this->databaseProxyManagerService->runForCompany(
$company->getId(),
function () use ($adminData, $company, $plugins) {
function () use ($adminData, $company, $plugins, $usageType) {
$this->companyDatabaseService->doMigrations();
$this->companyDatabaseService->runSeeders();
$this->userService->create([
Expand Down Expand Up @@ -89,7 +90,7 @@ function () use ($adminData, $company, $plugins) {

$this->registrationTailService->create(['tail' => json_encode($registrationTail)]);
$mainSettings = $this->mainSettingsService->getAll()->first();
$this->mainSettingsService->update($mainSettings, ['company_name' => $company->name]);
$this->mainSettingsService->update($mainSettings, ['company_name' => $company->name, 'usage_type' => $usageType]);

return response()->json([
'message' => 'Congratulations! you have registered to MicroPowerManager successfully. You will be redirected to dashboard in seconds..',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function update(MainSettings $mainSettings, Request $request): ApiResourc
'country',
'language',
'vat_energy',
'vat_appliance'
'vat_appliance',
'usage_type'
]);

return ApiResource::make($this->mainSettingsService->update($mainSettings, $mainSettingsData));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers;

use App\Http\Resources\ApiResource;
use App\Models\UsageType;
use App\Services\UsageTypeService;
use Illuminate\Http\Request;

class UsageTypeController extends Controller
{
public function __construct(private UsageTypeService $usageTypeService)
{
}

public function index(Request $request): ApiResource
{
return ApiResource::make($this->usageTypeService->getAll());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ private function handleApiRequest(Request $request, Closure $next)
return $next($request);
}

//getting usage types should not be proxied. It should use the base database to create the record
if ($request->path() === 'api/usage-types' && $request->isMethod('get')) {
return $next($request);
}

//webclient login
if ($request->path() === 'api/auth/login' || $request->path() === 'api/app/login') {
$databaseProxy = $this->databaseProxyManager->findByEmail($request->input('email'));
Expand Down
37 changes: 37 additions & 0 deletions Website/htdocs/mpmanager/app/Services/UsageTypeService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Services;

use App\Models\UsageType;

class UsageTypeService implements IBaseService
{
public function __construct(private UsageType $usageType)
{
}

public function getAll($limit = null)
{
return $this->usageType->newQuery()->get();
}

public function getById($id)
{
// TODO: Implement getById() method.
}

public function create($data)
{
// TODO: Implement create() method.
}

public function update($model, $data)
{
// TODO: Implement update() method.
}

public function delete($model)
{
// TODO: Implement delete() method.
}
}
51 changes: 34 additions & 17 deletions Website/htdocs/mpmanager/database/seeders/MpmPluginsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,119 +20,136 @@ public function run()
'description' => 'This plugin uses KoiosAPI for the main authentication. After it got authenticated it uses the ThunderCloud API for basic CRUD operations. You need to enter the ThunderCloud Token on the site',
'tail_tag' => 'Spark Meter',
'installation_command' => 'spark-meter:install',
'root_class' => 'SparkMeter'
'root_class' => 'SparkMeter',
'usage_type' => 'mini-grid'
],
[
'name' => 'SteamaMeter',
'description' => 'This plugin integrates Steamaco meters to Micropowermanager. It uses the same credentials as ui.steama.co for authentication. After it got authenticated, the plugin synchronizes Site, Customer ..',
'tail_tag' => 'Steamaco Meter',
'installation_command' => 'steama-meter:install',
'root_class' => 'SteamaMeter'
'root_class' => 'SteamaMeter',
'usage_type' => 'mini-grid'
],
[
'name' => 'CalinMeter',
'description' => 'This plugin integrates Calin meters to Micropowermanager. It uses user_id & api_key for creating tokens for energy.',
'tail_tag' => 'Calin Meter',
'installation_command' => 'calin-meter:install',
'root_class' => 'CalinMeter'
'root_class' => 'CalinMeter',
'usage_type' => 'mini-grid'
],
[
'name' => 'CalinSmartMeter',
'description' => 'This plugin integrates Calin meters to Micropowermanager. It uses company_name, user_name, password and password_vend for creating tokens for energy.',
'tail_tag' => 'CalinSmart Meter',
'installation_command' => 'calin-smart-meter:install',
'root_class' => 'CalinSmartMeter'
'root_class' => 'CalinSmartMeter',
'usage_type' => 'mini-grid'
],
[
'name' => 'KelinMeter',
'description' => 'This plugin integrates Kelim meters to Micropowermanager. It uses username & password for creating tokens for energy.',
'tail_tag' => 'Kelin Meter',
'installation_command' => 'kelin-meter:install',
'root_class' => 'KelinMeter'
'root_class' => 'KelinMeter',
'usage_type' => 'mini-grid'
],
[
'name' => 'StronMeter',
'description' => 'This plugin integrates Stron meters to Micropowermanager. It uses the api login credentials for authentication.',
'tail_tag' => 'Stron Meter',
'installation_command' => 'stron-meter:installl',
'root_class' => 'StronMeter'
'root_class' => 'StronMeter',
'usage_type' => 'mini-grid'
],
[
'name' => 'SwiftaPayment',
'description' => 'This plugin developed for getting Swifta payments into MicroPowerManager.',
'tail_tag' => null,
'installation_command' => 'swifta-payment-provider:install',
'root_class' => 'SwiftaPaymentProvider'
'root_class' => 'SwiftaPaymentProvider',
'usage_type' => 'general'
],
[
'name' => 'MesombPayment',
'description' => 'This plugin developed for getting MeSomb payments into MicroPowerManager.',
'tail_tag' => null,
'installation_command' => 'mesomb-payment-provider:install',
'root_class' => 'MesombPaymentProvider'
'root_class' => 'MesombPaymentProvider',
'usage_type' => 'general'
],
[
'name' => 'BulkRegistration',
'description' => 'This plugin provides bulk registration of the company\'s existing records. NOTE: Please do not use this plugin to register your Spark & Stemaco meter records. These records will be synchronized automatically once you configure your credential settings for these plugins.',
'tail_tag' => null,
'installation_command' => 'bulk-registration:install',
'root_class' => 'BulkRegistration'
'root_class' => 'BulkRegistration',
'usage_type' => 'general'
],
[
'name' => 'ViberMessaging',
'description' => 'This plugin developed for the communication with customers throughout Viber messages.',
'tail_tag' => 'Viber Messaging',
'installation_command' => 'viber-messaging:install',
'root_class' => 'ViberMessaging'
'root_class' => 'ViberMessaging',
'usage_type' => 'general'
],
[
'name' => 'WaveMoneyPayment',
'description' => 'This plugin developed for getting WaveMoney payments into MicroPowerManager.',
'tail_tag' => 'WaveMoney',
'installation_command' => 'wave-money-payment-provider:install',
'root_class' => 'WaveMoneyPaymentProvider'
'root_class' => 'WaveMoneyPaymentProvider',
'usage_type' => 'general'
],
[
'name' => 'MicroStarMeter',
'description' => 'This plugin integrates MicroStar meters to Micropowermanager. It uses user_id & api_key for creating tokens for energy.',
'tail_tag' => 'MicroStar Meter',
'installation_command' => 'micro-star-meter:install',
'root_class' => 'MicroStarMeter'
'root_class' => 'MicroStarMeter',
'usage_type' => 'mini-grid'
],
[
'name' => 'SunKingSHS',
'description' => 'This plugin integrates SunKing solar home systems to Micropowermanager. It uses client_id & client_secret for creating tokens for energy.',
'tail_tag' => 'SunKing SHS',
'installation_command' => 'sun-king-shs:install',
'root_class' => 'SunKingSHS'
'root_class' => 'SunKingSHS',
'usage_type' => 'shs'
],
[
'name' => 'GomeLongMeter',
'description' => 'This plugin integrates GomeLong meters to Micropowermanager. It uses. user_id & user_password for creating tokens for energy.',
'tail_tag' => 'GomeLong Meter',
'installation_command' => 'gome-long-meter:install',
'root_class' => 'GomeLongMeter'
'root_class' => 'GomeLongMeter',
'usage_type' => 'mini-grid'
],
[
'name' => 'WavecomPayment',
'description' => 'This plugin developed for getting Wavecom(Senegal) payments into MicroPowerManager.',
'tail_tag' => null,
'installation_command' => 'wavecom-payment-provider:install',
'root_class' => 'WavecomPaymentProvider'
'root_class' => 'WavecomPaymentProvider',
'usage_type' => 'general'
],
[
'name' => 'DalyBms',
'description' => 'This plugin developed for managing e-bikes with daly bms.',
'tail_tag' => "Daly Bms",
'installation_command' => 'daly-bms:install',
'root_class' => 'DalyBms'
'root_class' => 'DalyBms',
'usage_type' => 'e-bike'
],
[
'name' => 'AngazaSHS',
'description' => 'This plugin integrates Angaza solar home systems to Micropowermanager. It uses client_id & client_secret for creating tokens for energy.',
'tail_tag' => 'Angaza SHS',
'installation_command' => 'angaza-shs:install',
'root_class' => 'AngazaSHS'
'root_class' => 'AngazaSHS',
'usage_type' => 'shs'
]
)
);
Expand Down
3 changes: 3 additions & 0 deletions Website/htdocs/mpmanager/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,6 @@ static function () {
Route::get('/transactions/{slug}', 'TransactionExportController@download');
Route::get('/debts/{slug}', 'OutstandingDebtsExportController@download');
});
Route::group(['prefix' => 'usage-types'], static function () {
Route::get('/', 'UsageTypeController@index');
});
Loading