Implemented Event Budget
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Budget\Controllers;
|
||||
|
||||
use App\Domains\Budget\Actions\CreateEstimate\CreateEstimateAction;
|
||||
use App\Domains\Budget\Actions\CreateEstimate\CreateEstimateRequest;
|
||||
use App\Domains\Budget\Actions\DeleteEstimate\DeleteEstimateAction;
|
||||
use App\Domains\Budget\Actions\DeleteEstimate\DeleteEstimateRequest;
|
||||
use App\Domains\CostUnit\Actions\CreateCostUnit\CreateCostUnitRequest;
|
||||
use App\Scopes\CommonController;
|
||||
use App\ValueObjects\Amount;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteController extends CommonController
|
||||
{
|
||||
public function __invoke(int $costUnitId, int $estimateId, Request $request) : JsonResponse {
|
||||
$estimate = $this->estimates->getById($estimateId);
|
||||
|
||||
if ($estimate === null) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Estimate not found'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$deleteEstimateResponse =
|
||||
new DeleteEstimateAction(request: new DeleteEstimateRequest($estimate)
|
||||
)->execute();
|
||||
|
||||
if ($deleteEstimateResponse->success) {
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Der Eintrag wurde erfolgreich gelöscht.'
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Beim Löschen des Eintrags ist ein Fehler aufgetreten.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,9 @@ class ListController extends CommonController
|
||||
'status' => 'success',
|
||||
'costUnitId' => $costUnitId,
|
||||
'title' => InvoiceType::where('slug', $estimateType)->first()->name,
|
||||
'estimateType' => $estimateType,
|
||||
'estimates' => $estimates,
|
||||
'totalAmountString' => $this->estimates->getTotalAmount($costUnit, $estimateType)->toString(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Budget\Controllers;
|
||||
|
||||
use App\Domains\Budget\Actions\CreateEstimate\CreateEstimateAction;
|
||||
use App\Domains\Budget\Actions\CreateEstimate\CreateEstimateRequest;
|
||||
use App\Domains\CostUnit\Actions\CreateCostUnit\CreateCostUnitRequest;
|
||||
use App\Scopes\CommonController;
|
||||
use App\ValueObjects\Amount;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SaveController extends CommonController
|
||||
{
|
||||
public function __invoke(int $costUnitId, Request $request) : JsonResponse {
|
||||
$costUnit = $this->costUnits->getById($costUnitId);
|
||||
|
||||
if ($costUnit === null) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Cost unit not found'
|
||||
], 404);
|
||||
}
|
||||
|
||||
$createCostUniResponse =
|
||||
new CreateEstimateAction(request: new CreateEstimateRequest(
|
||||
description: $request->input('description'),
|
||||
amount: Amount::fromString($request->input('amount')),
|
||||
amountType: $request->input('amount_type'),
|
||||
estimateType: $request->input('estimateType'),
|
||||
costUnit: $costUnit,
|
||||
estimateId: $request->input('estimateId'),
|
||||
))->execute();
|
||||
|
||||
if ($createCostUniResponse->success) {
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Der Eintrag wurde erfolgreich angelegt.'
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Beim Anlegen des Eintrags ist ein Fehler aufgetreten.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user