ClientPaymentMethodController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Requests\ClientPaymentMethodRequest;
  4. use App\Http\Resources\ClientPaymentMethodResource;
  5. use App\Services\ClientPaymentMethodService;
  6. use Illuminate\Http\JsonResponse;
  7. class ClientPaymentMethodController extends Controller
  8. {
  9. public function __construct(
  10. private readonly ClientPaymentMethodService $service
  11. ) {}
  12. public function index(int $clientId): JsonResponse
  13. {
  14. $paymentMethods = $this->service->getByClientId($clientId);
  15. return $this->successResponse(
  16. payload: ClientPaymentMethodResource::collection($paymentMethods)
  17. );
  18. }
  19. public function show(int $id): JsonResponse
  20. {
  21. $paymentMethod = $this->service->findById($id);
  22. return $this->successResponse(
  23. payload: new ClientPaymentMethodResource($paymentMethod)
  24. );
  25. }
  26. public function store(ClientPaymentMethodRequest $request): JsonResponse
  27. {
  28. $paymentMethod = $this->service->create($request->validated());
  29. return $this->successResponse(
  30. payload: new ClientPaymentMethodResource($paymentMethod),
  31. message: __("messages.created"),
  32. code: 201,
  33. );
  34. }
  35. public function update(ClientPaymentMethodRequest $request, int $id): JsonResponse
  36. {
  37. $paymentMethod = $this->service->findById($id);
  38. $paymentMethod = $this->service->update($paymentMethod, $request->validated());
  39. return $this->successResponse(
  40. payload: new ClientPaymentMethodResource($paymentMethod),
  41. message: __("messages.updated"),
  42. );
  43. }
  44. public function destroy(int $id): JsonResponse
  45. {
  46. $paymentMethod = $this->service->findById($id);
  47. $this->service->delete($paymentMethod);
  48. return $this->successResponse(
  49. message: __("messages.deleted"),
  50. code: 204,
  51. );
  52. }
  53. }