diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php new file mode 100644 index 00000000..197b5273 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php @@ -0,0 +1,91 @@ + 'Created Company Wallet', + 'message' => 'You have successfully created a company wallet' + ]; + } + + private $createsWallet; + + + public function __construct( + CreatesWallet $createsWallet + ) + { + $this->createsWallet= $createsWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + echo $request->input('amount'); + echo $request->input('company_id'); + $amount = doubleval($request->input('amount')); + $wallet_object = new WalletObject( + $request->input('code'), + $request->input('currency'), + $request->input('amount'), + $request->input('company_id') + ); + + $wallet_query = $this->createsWallet->execute($wallet_object); + + DB::commit(); + + return $this->resourceResponse(new WalletResource($wallet_query)); + + } catch (\Exception $exception) { + dd($exception); + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php new file mode 100644 index 00000000..116117ce --- /dev/null +++ b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php @@ -0,0 +1,68 @@ +code = $code; + $this->currency = $currency; + $this->amount = $amount; + $this->company_id = $company_id; + } + + /** + * @return string + */ + public function getCode(): ?string + { + return $this->code; + } + + /** + * @return string + */ + public function getCurrency(): ?string + { + return $this->currency; + } + + /** + * @return string + */ + public function getAmount(): ?float + { + return floatval($this->amount); + } + + /** + * @return int|null + */ + public function getCompanyId(): ?int + { + return $this->company_id; + } + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/CreatesWallet.php b/app/Classes/Modules/Wallets/Services/CreatesWallet.php new file mode 100644 index 00000000..9e7c0c5d --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/CreatesWallet.php @@ -0,0 +1,27 @@ +code = $object->getCode(); + $model->currency = $object->getCurrency(); + $model->company_id = $object->getCompanyId(); + $model->amount = $object->getAmount(); + + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Wallets/CreateWalletController.php b/app/Http/Controllers/Wallets/CreateWalletController.php new file mode 100644 index 00000000..1aa71179 --- /dev/null +++ b/app/Http/Controllers/Wallets/CreateWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Resources/WalletResource.php b/app/Http/Resources/WalletResource.php new file mode 100644 index 00000000..567e5db0 --- /dev/null +++ b/app/Http/Resources/WalletResource.php @@ -0,0 +1,25 @@ + $this->id, + 'code' => $this->code, + 'currency' => $this->currency, + 'amount' => (double) $this->amount, + 'company_id' => (int) $this->company_id + ]; + } +} diff --git a/app/Models/Wallets.php b/app/Models/Wallets.php new file mode 100644 index 00000000..ca947fd4 --- /dev/null +++ b/app/Models/Wallets.php @@ -0,0 +1,17 @@ +hasOne(Company::class, 'company_id', 'id'); + } + +} diff --git a/database/migrations/2020_11_29_212614_create_companies_wallet_table.php b/database/migrations/2020_11_29_212614_create_companies_wallet_table.php new file mode 100644 index 00000000..475a4c26 --- /dev/null +++ b/database/migrations/2020_11_29_212614_create_companies_wallet_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('code'); + $table->string('currency'); + $table->decimal('amount', 8, 2); + $table->bigInteger('company_id')->unsigned(); + $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('wallets'); + } +} diff --git a/routes/wallet.php b/routes/wallet.php new file mode 100644 index 00000000..2774ea40 --- /dev/null +++ b/routes/wallet.php @@ -0,0 +1,14 @@ + 'wallet', 'namespace' => 'Wallets', 'as' => 'wallet.'], function () { + + Route::group(['prefix' => 'authentication', 'as' => 'authentication.'], function () { + + }); + + + Route::post('/create', 'CreateWalletController@create')->name('create'); + +}); \ No newline at end of file