|
@@ -0,0 +1,65 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Http\Controllers;
|
|
|
|
|
+
|
|
|
|
|
+use App\Http\Requests\ProviderPaymentMethodRequest;
|
|
|
|
|
+use App\Http\Resources\ProviderPaymentMethodResource;
|
|
|
|
|
+use App\Services\ProviderPaymentMethodService;
|
|
|
|
|
+use Illuminate\Http\JsonResponse;
|
|
|
|
|
+use Illuminate\Http\Request;
|
|
|
|
|
+use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
|
|
|
+
|
|
|
|
|
+class ProviderPaymentMethodController extends Controller
|
|
|
|
|
+{
|
|
|
|
|
+ public function __construct(
|
|
|
|
|
+ private readonly ProviderPaymentMethodService $service
|
|
|
|
|
+ ) {}
|
|
|
|
|
+
|
|
|
|
|
+ public function index($id): JsonResponse
|
|
|
|
|
+ {
|
|
|
|
|
+ // $providerId = $request->query('provider_id');
|
|
|
|
|
+ $paymentMethods = $this->service->getByProvider($id);
|
|
|
|
|
+ // return ProviderPaymentMethodResource::collection($paymentMethods);
|
|
|
|
|
+ return $this->successResponse(
|
|
|
|
|
+ payload: ProviderPaymentMethodResource::collection($paymentMethods)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function show(int $id): ProviderPaymentMethodResource
|
|
|
|
|
+ {
|
|
|
|
|
+ $paymentMethod = $this->service->findById($id);
|
|
|
|
|
+ abort_if(!$paymentMethod, 404);
|
|
|
|
|
+ return new ProviderPaymentMethodResource($paymentMethod);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function store(ProviderPaymentMethodRequest $request): JsonResponse
|
|
|
|
|
+ {
|
|
|
|
|
+ $paymentMethod = $this->service->create($request->validated());
|
|
|
|
|
+ return $this->successResponse(
|
|
|
|
|
+ payload: new ProviderPaymentMethodResource($paymentMethod)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function update(ProviderPaymentMethodRequest $request, int $id): JsonResponse
|
|
|
|
|
+ {
|
|
|
|
|
+ $paymentMethod = $this->service->findById($id);
|
|
|
|
|
+ abort_if(!$paymentMethod, 404);
|
|
|
|
|
+
|
|
|
|
|
+ $paymentMethod = $this->service->update($paymentMethod, $request->validated());
|
|
|
|
|
+ return $this->successResponse(
|
|
|
|
|
+ payload: new ProviderPaymentMethodResource($paymentMethod)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function destroy(int $id): JsonResponse
|
|
|
|
|
+ {
|
|
|
|
|
+ $paymentMethod = $this->service->findById($id);
|
|
|
|
|
+ abort_if(!$paymentMethod, 404);
|
|
|
|
|
+
|
|
|
|
|
+ $this->service->delete($paymentMethod);
|
|
|
|
|
+ return $this->successResponse(
|
|
|
|
|
+ message: __("messages.deleted"),
|
|
|
|
|
+ code: 204,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+}
|