ProviderPaymentMethodController.php 1.7 KB

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