mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-16 01:34:08 +00:00
Consolidate single-action controllers into resource controllers
Merge 11 single-action controllers into their parent resource controllers: - Invoice: send, sendPreview, clone, changeStatus -> InvoicesController - Estimate: send, sendPreview, clone, convertToInvoice, changeStatus -> EstimatesController - Payment: send, sendPreview -> PaymentsController Extract clone and convert business logic from controllers into services: - InvoiceService: add clone(), changeStatus() - EstimateService: add clone(), convertToInvoice(), changeStatus() Previously this logic was inlined in controllers (~80-90 lines each).
This commit is contained in:
@@ -5,11 +5,15 @@ namespace App\Http\Controllers\V1\Admin\Estimate;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\DeleteEstimatesRequest;
|
||||
use App\Http\Requests\EstimatesRequest;
|
||||
use App\Http\Requests\SendEstimatesRequest;
|
||||
use App\Http\Resources\EstimateResource;
|
||||
use App\Http\Resources\InvoiceResource;
|
||||
use App\Jobs\GenerateEstimatePdfJob;
|
||||
use App\Models\Estimate;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\EstimateService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Markdown;
|
||||
|
||||
class EstimatesController extends Controller
|
||||
{
|
||||
@@ -83,4 +87,55 @@ class EstimatesController extends Controller
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function send(SendEstimatesRequest $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('send estimate', $estimate);
|
||||
|
||||
$response = $this->estimateService->send($estimate, $request->all());
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function sendPreview(SendEstimatesRequest $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('send estimate', $estimate);
|
||||
|
||||
$markdown = new Markdown(view(), config('mail.markdown'));
|
||||
|
||||
$data = $this->estimateService->sendEstimateData($estimate, $request->all());
|
||||
$data['url'] = $estimate->estimatePdfUrl;
|
||||
|
||||
return $markdown->render('emails.send.estimate', ['data' => $data]);
|
||||
}
|
||||
|
||||
public function clone(Request $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('view', $estimate);
|
||||
$this->authorize('create', Estimate::class);
|
||||
|
||||
$newEstimate = $this->estimateService->clone($estimate);
|
||||
|
||||
return new EstimateResource($newEstimate);
|
||||
}
|
||||
|
||||
public function convertToInvoice(Request $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('create', Invoice::class);
|
||||
|
||||
$invoice = $this->estimateService->convertToInvoice($estimate);
|
||||
|
||||
return new InvoiceResource($invoice);
|
||||
}
|
||||
|
||||
public function changeStatus(Request $request, Estimate $estimate)
|
||||
{
|
||||
$this->authorize('send estimate', $estimate);
|
||||
|
||||
$this->estimateService->changeStatus($estimate, $request->status);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user