| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Http\Controllers;
- use App\Http\Requests\ClientPaymentMethodRequest;
- use App\Http\Resources\ClientPaymentMethodResource;
- use App\Services\ClientPaymentMethodService;
- use Illuminate\Http\JsonResponse;
- class ClientPaymentMethodController extends Controller
- {
- public function __construct(
- private readonly ClientPaymentMethodService $service
- ) {}
- public function index(int $clientId): JsonResponse
- {
- $paymentMethods = $this->service->getByClientId($clientId);
-
- return $this->successResponse(
- payload: ClientPaymentMethodResource::collection($paymentMethods)
- );
- }
- public function show(int $id): JsonResponse
- {
- $paymentMethod = $this->service->findById($id);
-
- return $this->successResponse(
- payload: new ClientPaymentMethodResource($paymentMethod)
- );
- }
- public function store(ClientPaymentMethodRequest $request): JsonResponse
- {
- $paymentMethod = $this->service->create($request->validated());
-
- return $this->successResponse(
- payload: new ClientPaymentMethodResource($paymentMethod),
- message: __("messages.created"),
- code: 201,
- );
- }
- public function update(ClientPaymentMethodRequest $request, int $id): JsonResponse
- {
- $paymentMethod = $this->service->findById($id);
-
- $paymentMethod = $this->service->update($paymentMethod, $request->validated());
-
- return $this->successResponse(
- payload: new ClientPaymentMethodResource($paymentMethod),
- message: __("messages.updated"),
- );
- }
- public function destroy(int $id): JsonResponse
- {
- $paymentMethod = $this->service->findById($id);
-
- $this->service->delete($paymentMethod);
-
- return $this->successResponse(
- message: __("messages.deleted"),
- code: 204,
- );
- }
- }
|